-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* added base64 functionality and basic testing * Change log * fix conftest to allow json * Change method name from camel to snake case * change type hinting to be py3.9 compatible --------- Co-authored-by: Robele Baker <>
- Loading branch information
Showing
5 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Add support for base 64 encoded json keyfile credentials | ||
time: 2024-05-16T12:57:35.383416-07:00 | ||
custom: | ||
Author: robeleb1 | ||
Issue: "923" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import json | ||
import pytest | ||
from dbt.adapters.bigquery.utility import string_to_base64, is_base64 | ||
|
||
|
||
@pytest.fixture | ||
def example_json_keyfile(): | ||
keyfile = json.dumps( | ||
{ | ||
"type": "service_account", | ||
"project_id": "", | ||
"private_key_id": "", | ||
"private_key": "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----\n", | ||
"client_email": "", | ||
"client_id": "", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "", | ||
} | ||
) | ||
|
||
return keyfile | ||
|
||
|
||
@pytest.fixture | ||
def example_json_keyfile_b64(): | ||
keyfile = json.dumps( | ||
{ | ||
"type": "service_account", | ||
"project_id": "", | ||
"private_key_id": "", | ||
"private_key": "-----BEGIN PRIVATE KEY----------END PRIVATE KEY-----\n", | ||
"client_email": "", | ||
"client_id": "", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "", | ||
} | ||
) | ||
|
||
return string_to_base64(keyfile) | ||
|
||
|
||
def test_valid_base64_strings(example_json_keyfile_b64): | ||
valid_strings = [ | ||
"SGVsbG8gV29ybGQh", # "Hello World!" | ||
"Zm9vYmFy", # "foobar" | ||
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2Nzg5", # A long string | ||
"", # Empty string | ||
example_json_keyfile_b64.decode("utf-8"), | ||
] | ||
|
||
for s in valid_strings: | ||
assert is_base64(s) is True | ||
|
||
|
||
def test_valid_base64_bytes(example_json_keyfile_b64): | ||
valid_bytes = [ | ||
b"SGVsbG8gV29ybGQh", # "Hello World!" | ||
b"Zm9vYmFy", # "foobar" | ||
b"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVowMTIzNDU2Nzg5", # A long string | ||
b"", # Empty bytes | ||
example_json_keyfile_b64, | ||
] | ||
for s in valid_bytes: | ||
assert is_base64(s) is True | ||
|
||
|
||
def test_invalid_base64(example_json_keyfile): | ||
invalid_inputs = [ | ||
"This is not Base64", | ||
"SGVsbG8gV29ybGQ", # Incorrect padding | ||
"Invalid#Base64", | ||
12345, # Not a string or bytes | ||
b"Invalid#Base64", | ||
"H\xffGVsbG8gV29ybGQh", # Contains invalid character \xff | ||
example_json_keyfile, | ||
] | ||
for s in invalid_inputs: | ||
assert is_base64(s) is False |