From 5f8f03b383aa1f5ed2fb9fc75f632457fb416f66 Mon Sep 17 00:00:00 2001 From: Skynet Date: Thu, 14 Sep 2023 21:49:04 +0200 Subject: [PATCH] Feat: Add test case for base64 encoded private key --- .../secrets/encrypted-private-key-base64 | 1 + .../snowflake/test_snowflake_configuration.py | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/common/cases/secrets/encrypted-private-key-base64 diff --git a/tests/common/cases/secrets/encrypted-private-key-base64 b/tests/common/cases/secrets/encrypted-private-key-base64 new file mode 100644 index 0000000000..40f3703390 --- /dev/null +++ b/tests/common/cases/secrets/encrypted-private-key-base64 @@ -0,0 +1 @@ +LS0tLS1CRUdJTiBFTkNSWVBURUQgUFJJVkFURSBLRVktLS0tLQpNSUlGTFRCWEJna3Foa2lHOXcwQkJRMHdTakFwQmdrcWhraUc5dzBCQlF3d0hBUUlsL0ErZlkrSVFMVUNBZ2dBCk1Bd0dDQ3FHU0liM0RRSUpCUUF3SFFZSllJWklBV1VEQkFFcUJCQ2krUnBJVmpEN1hBYURHLzNoa3F5dEJJSUUKMEtnODJvbnhqZnp5VFpFVVFtU3ZsVkw4cncwY0hTWk92RS96TkFmTFhwRjcva213OVVWWkxMLy9jbHcybWlpNgo2ZnNSRlVLd1RTNVJYYWtRcDh2ZWllTHpDT3g2bzFLd0lrMGFvOUE3c0ptd1BMejBsTXZoWEsvdHlGanM5dUhVCm4yWWNTSEo0WGdzUGRnL2xKc1RjbjRwNFFMNTJLREFFSUUvY2pSVktiZEljbGFYN3pQZHBWSzhXQ2NQVWNSK2cKOWxJbTNIQnl4ZDd3NklDRXh0WXFabGFCbE56S3NTeVdZNmNOR0J5bG91WHR2YktidHFpNEhnaThpaDdlc2ZFTgpqZU0zYmhudVpQSmViQVBHYWFxQ2cyMHlKNDQyOGpEWlpVSUlKbEx1cnZhZ2JwME11S0tTRy83YURlQzVNaUlMCktMRHY2UjJZKzNoK3ZhQy8xOWlwVHFtZXlUZ3ND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K2NBcXBoV240SHI0eGhVVjVBYXEKQTBIZEJCcTczVDlHNVAyaU5XdUJib0hTTzNLUncxT3BiRHRDc1ZvN1h3V2NBdU9oOTg2ck0zelhPcDdsd29ERQphMHNMay9Kd1pndEVPTndqeGlXWk4zWHZOYWl4aVJ2MEt3NnNsUFBDYytkWlRSN0VIdHVZZXlGTXBtK2VZQkoxClhXbTBGMFo4RERRSkExYkZqbTUyeDNhR3hnVWFHYkVyZHNFb0ZpcHFoVURaWXhjeVhucythRFhuMURkZFJnbDMKZjFzQ09FSkFyNlpQVStlNkszMDE1NEFLcHZQMlJYTTZFNjVjR2lxUU1NKzdSV3czOGdrRlZPL1NqdEZmcGtuVQp0dmZjZFBYcTltVkQ4SXFNU0lkQVNka3Y5bmN1L25pTXNZS1crMG40djF0ZzJQeC9WaUVEOVhkSEtTUDNEbjExCkpvWnR0bkhUenFKQWl5emtUd0pNYjhVTHlIb2JsN2pEZFBmaTJkam1ZcnVnTEZDaDBOemRaTnBXNFdoeE5LejAKellqTTVuTnAzWXFOajVpQnAxTDVCUnBiSHdwbGhvenFTZGo5Y2Z1MWJRdWFBRnZya3NCMDhXa2puSkdSWFdSbApPUHMrRStyNGU0SFY3ZUxET2Y3MTFxRWhOVTJzNVVCODVpY3Fzc3AxWU52TgotLS0tLUVORCBFTkNSWVBURUQgUFJJVkFURSBLRVktLS0tLQo= \ No newline at end of file diff --git a/tests/load/snowflake/test_snowflake_configuration.py b/tests/load/snowflake/test_snowflake_configuration.py index 7214574f2d..628da2dd0f 100644 --- a/tests/load/snowflake/test_snowflake_configuration.py +++ b/tests/load/snowflake/test_snowflake_configuration.py @@ -15,7 +15,7 @@ def test_connection_string_with_all_params() -> None: - url = "snowflake://user1:pass1@host1/db1?warehouse=warehouse1&role=role1&private_key=pk&private_key_passphrase=paphr" + url = "snowflake://user1:pass1@host1/db1?warehouse=warehouse1&role=role1&private_key=cGsK&private_key_passphrase=paphr" creds = SnowflakeCredentials() creds.parse_native_representation(url) @@ -60,6 +60,31 @@ def test_to_connector_params() -> None: warehouse='warehouse1', role='role1', ) + + pkey_str = Path('./tests/common/cases/secrets/encrypted-private-key-base64').read_text('utf8') + + creds = SnowflakeCredentials() + creds.private_key = pkey_str # type: ignore[assignment] + creds.private_key_passphrase = '12345' # type: ignore[assignment] + creds.username = 'user1' + creds.database = 'db1' + creds.host = 'host1' + creds.warehouse = 'warehouse1' + creds.role = 'role1' + + params = creds.to_connector_params() + + assert isinstance(params['private_key'], bytes) + params.pop('private_key') + + assert params == dict( + user='user1', + database='db1', + account='host1', + password=None, + warehouse='warehouse1', + role='role1', + ) def test_snowflake_credentials_native_value(environment) -> None: