11#!/usr/bin/env python
22
3- # Copyright (c) 2021, 2023 Oracle and/or its affiliates.
3+ # Copyright (c) 2021, 2024 Oracle and/or its affiliates.
44# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
66from ads .secrets import ADBSecretKeeper
@@ -36,6 +36,24 @@ def key_encoding():
3636 )
3737
3838
39+ @pytest .fixture
40+ def key_encoding_dsn ():
41+ user_name = "myuser"
42+ password = "this-is-not-the-secret"
43+ dsn = "my long dsn string....................."
44+ secret_dict = {
45+ "user_name" : user_name ,
46+ "password" : password ,
47+ "dsn" : dsn ,
48+ }
49+ encoded = b64encode (json .dumps (secret_dict ).encode ("utf-8" )).decode ("utf-8" )
50+ return (
51+ (user_name , password , dsn ),
52+ secret_dict ,
53+ encoded ,
54+ )
55+
56+
3957def generate_wallet_data (wallet_zip_path , wallet_dir_path ):
4058 files = 4
4159 file_content = {}
@@ -133,9 +151,9 @@ def test_encode(mock_client, mock_signer, key_encoding):
133151
134152@patch ("ads.common.auth.default_signer" )
135153@patch ("ads.common.oci_client.OCIClientFactory" )
136- def test_adw_save (mock_client , mock_signer , key_encoding , tmpdir ):
154+ def test_adw_tls_save (mock_client , mock_signer , key_encoding_dsn , tmpdir ):
137155 adwsecretkeeper = ADBSecretKeeper (
138- * key_encoding [ 0 ],
156+ ** key_encoding_dsn [ 1 ],
139157 vault_id = "ocid.vault" ,
140158 key_id = "ocid.key" ,
141159 compartment_id = "dummy" ,
@@ -211,6 +229,7 @@ def test_adw_context(mock_client, mock_signer, key_encoding):
211229 assert adwsecretkeeper == {
212230 ** key_encoding [1 ],
213231 "wallet_location" : "/this/is/mywallet.zip" ,
232+ "dsn" : None ,
214233 }
215234 assert os .environ .get ("user_name" ) == key_encoding [0 ][0 ]
216235 assert os .environ .get ("password" ) == key_encoding [0 ][1 ]
@@ -221,6 +240,7 @@ def test_adw_context(mock_client, mock_signer, key_encoding):
221240 "password" : None ,
222241 "service_name" : None ,
223242 "wallet_location" : None ,
243+ "dsn" : None ,
224244 }
225245 assert os .environ .get ("user_name" ) is None
226246 assert os .environ .get ("password" ) is None
@@ -240,13 +260,14 @@ def test_adw_keeper_no_wallet(mock_client, mock_signer, key_encoding):
240260 assert adwsecretkeeper == {
241261 ** key_encoding [1 ],
242262 "wallet_location" : None ,
263+ "dsn" : None ,
243264 }
244265
245266
246267@patch ("ads.common.auth.default_signer" )
247268@patch ("ads.common.oci_client.OCIClientFactory" )
248269def test_adw_keeper_with_repository (mock_client , mock_signer , key_encoding , tmpdir ):
249- expected = {** key_encoding [1 ], "wallet_location" : key_encoding [3 ]}
270+ expected = {** key_encoding [1 ], "wallet_location" : key_encoding [3 ], "dsn" : None }
250271 os .makedirs (os .path .join (tmpdir , "testdb" ))
251272 with open (os .path .join (tmpdir , "testdb" , "config.json" ), "w" ) as conffile :
252273 json .dump (expected , conffile )
@@ -270,6 +291,7 @@ def test_adw_context_namespace(mock_client, mock_signer, key_encoding):
270291 assert adwsecretkeeper == {
271292 ** key_encoding [1 ],
272293 "wallet_location" : "/this/is/mywallet.zip" ,
294+ "dsn" : None ,
273295 }
274296 assert os .environ .get ("myapp.user_name" ) == key_encoding [0 ][0 ]
275297 assert os .environ .get ("myapp.password" ) == key_encoding [0 ][1 ]
@@ -280,6 +302,7 @@ def test_adw_context_namespace(mock_client, mock_signer, key_encoding):
280302 "password" : None ,
281303 "service_name" : None ,
282304 "wallet_location" : None ,
305+ "dsn" : None ,
283306 }
284307 assert os .environ .get ("myapp.user_name" ) is None
285308 assert os .environ .get ("myapp.password" ) is None
@@ -300,6 +323,7 @@ def test_adw_context_noexport(mock_client, mock_signer, key_encoding):
300323 assert adwsecretkeeper == {
301324 ** key_encoding [1 ],
302325 "wallet_location" : "/this/is/mywallet.zip" ,
326+ "dsn" : None ,
303327 }
304328
305329 assert os .environ .get ("user_name" ) is None
@@ -312,6 +336,7 @@ def test_adw_context_noexport(mock_client, mock_signer, key_encoding):
312336 "password" : None ,
313337 "service_name" : None ,
314338 "wallet_location" : None ,
339+ "dsn" : None ,
315340 }
316341
317342
@@ -413,6 +438,7 @@ def mock_get_secret_id(
413438 "password" : key_encoding_with_wallet .credentials .password ,
414439 "service_name" : key_encoding_with_wallet .credentials .service_name ,
415440 "wallet_location" : f"{ os .path .join (wallet_dir ,'wallet.zip' )} " ,
441+ "dsn" : None ,
416442 }
417443
418444 # with open(key_encoding_with_wallet[3], "rb") as orgfile:
@@ -449,6 +475,7 @@ def mock_get_secret_id(
449475 "password" : key_encoding_with_wallet .credentials .password ,
450476 "service_name" : key_encoding_with_wallet .credentials .service_name ,
451477 "wallet_location" : f"{ os .path .join (wallet_dir ,'wallet.zip' )} " ,
478+ "dsn" : None ,
452479 }
453480 assert (
454481 os .environ .get ("user_name" )
@@ -472,6 +499,7 @@ def mock_get_secret_id(
472499 "password" : None ,
473500 "service_name" : None ,
474501 "wallet_location" : None ,
502+ "dsn" : None ,
475503 }
476504 assert os .environ .get ("user_name" ) is None
477505 assert os .environ .get ("password" ) is None
@@ -508,6 +536,7 @@ def mock_get_secret_id(
508536 "password" : key_encoding_with_wallet .credentials .password ,
509537 "service_name" : key_encoding_with_wallet .credentials .service_name ,
510538 "wallet_location" : f"{ os .path .join (wallet_dir ,'wallet.zip' )} " ,
539+ "dsn" : None ,
511540 }
512541 assert (
513542 os .environ .get ("myapp.user_name" )
@@ -531,6 +560,7 @@ def mock_get_secret_id(
531560 "password" : None ,
532561 "service_name" : None ,
533562 "wallet_location" : None ,
563+ "dsn" : None ,
534564 }
535565 assert os .environ .get ("myapp.user_name" ) is None
536566 assert os .environ .get ("myapp.password" ) is None
@@ -565,6 +595,7 @@ def mock_get_secret_id(
565595 "password" : key_encoding_with_wallet .credentials .password ,
566596 "service_name" : key_encoding_with_wallet .credentials .service_name ,
567597 "wallet_location" : f"{ os .path .join (wallet_dir ,'wallet.zip' )} " ,
598+ "dsn" : None ,
568599 }
569600 assert os .environ .get ("user_name" ) is None
570601 assert os .environ .get ("password" ) is None
@@ -576,6 +607,7 @@ def mock_get_secret_id(
576607 "password" : None ,
577608 "service_name" : None ,
578609 "wallet_location" : None ,
610+ "dsn" : None ,
579611 }
580612
581613
@@ -730,6 +762,7 @@ def mock_get_secret_id(
730762 "password" : key_encoding_with_wallet .credentials .password ,
731763 "service_name" : key_encoding_with_wallet .credentials .service_name ,
732764 "wallet_location" : f"{ os .path .join (wallet_dir ,'wallet.zip' )} " ,
765+ "dsn" : None ,
733766 }
734767 assert (
735768 os .environ .get ("user_name" )
@@ -753,6 +786,7 @@ def mock_get_secret_id(
753786 "password" : None ,
754787 "service_name" : None ,
755788 "wallet_location" : None ,
789+ "dsn" : None ,
756790 }
757791 assert os .environ .get ("user_name" ) is None
758792 assert os .environ .get ("password" ) is None
@@ -786,6 +820,7 @@ def mock_get_secret_id(
786820 "password" : key_encoding_with_wallet .credentials .password ,
787821 "service_name" : key_encoding_with_wallet .credentials .service_name ,
788822 "wallet_location" : f"{ os .path .join (wallet_dir ,'wallet.zip' )} " ,
823+ "dsn" : None ,
789824 }
790825 assert (
791826 os .environ .get ("user_name" )
@@ -809,6 +844,7 @@ def mock_get_secret_id(
809844 "password" : None ,
810845 "service_name" : None ,
811846 "wallet_location" : None ,
847+ "dsn" : None ,
812848 }
813849 assert os .environ .get ("user_name" ) is None
814850 assert os .environ .get ("password" ) is None
0 commit comments