42
42
"fingerprint" : "test_fingerprint" ,
43
43
"tenancy" : "test_tenancy" ,
44
44
"region" : "us-ashburn-1" ,
45
- "key_file" : "test_key_file"
45
+ "key_file" : "test_key_file" ,
46
46
}
47
47
48
48
@@ -52,7 +52,11 @@ class TestEDAMixin(TestCase):
52
52
@mock .patch ("os.path.exists" )
53
53
@mock .patch ("oci.signer.load_private_key_from_file" )
54
54
def test_set_auth_overwrite_profile (
55
- self , mock_load_key_file , mock_path_exists , mock_config_from_file , mock_validate_config
55
+ self ,
56
+ mock_load_key_file ,
57
+ mock_path_exists ,
58
+ mock_config_from_file ,
59
+ mock_validate_config ,
56
60
):
57
61
mock_config_from_file .return_value = MOCK_CONFIG_FROM_FILE
58
62
set_auth (profile = "TEST" )
@@ -65,7 +69,11 @@ def test_set_auth_overwrite_profile(
65
69
@mock .patch ("os.path.exists" )
66
70
@mock .patch ("oci.signer.load_private_key_from_file" )
67
71
def test_set_auth_overwrite_config_location (
68
- self , mock_load_key_file , mock_path_exists , mock_config_from_file , mock_validate_config
72
+ self ,
73
+ mock_load_key_file ,
74
+ mock_path_exists ,
75
+ mock_config_from_file ,
76
+ mock_validate_config ,
69
77
):
70
78
mock_config_from_file .return_value = MOCK_CONFIG_FROM_FILE
71
79
mock_path_exists .return_value = True
@@ -77,14 +85,18 @@ def test_set_auth_overwrite_config_location(
77
85
@mock .patch ("oci.config.validate_config" )
78
86
@mock .patch ("oci.config.from_file" )
79
87
@mock .patch ("oci.signer.Signer" )
80
- def test_api_keys_using_test_profile (self , mock_signer , mock_config_from_file , mock_validate_config ):
88
+ def test_api_keys_using_test_profile (
89
+ self , mock_signer , mock_config_from_file , mock_validate_config
90
+ ):
81
91
api_keys ("test_path" , "TEST_PROFILE" )
82
92
mock_config_from_file .assert_called_with ("test_path" , "TEST_PROFILE" )
83
93
84
94
@mock .patch ("oci.config.validate_config" )
85
95
@mock .patch ("oci.config.from_file" )
86
96
@mock .patch ("oci.signer.Signer" )
87
- def test_api_keys_using_default_profile (self , mock_signer , mock_config_from_file , mock_validate_config ):
97
+ def test_api_keys_using_default_profile (
98
+ self , mock_signer , mock_config_from_file , mock_validate_config
99
+ ):
88
100
api_keys ("test_path" )
89
101
mock_config_from_file .assert_called_with ("test_path" , "DEFAULT" )
90
102
@@ -108,14 +120,16 @@ def test_resource_principal(self, mock_rp_signer):
108
120
109
121
@mock .patch ("oci.config.validate_config" )
110
122
@mock .patch ("oci.signer.load_private_key" )
111
- def test_set_auth_with_key_content (self , mock_load_private_key , mock_validate_config ):
123
+ def test_set_auth_with_key_content (
124
+ self , mock_load_private_key , mock_validate_config
125
+ ):
112
126
set_auth (
113
127
config = {
114
128
"user" : "test_user" ,
115
129
"fingerprint" : "test_fingerprint" ,
116
130
"tenancy" : "test_tenancy" ,
117
131
"region" : "us-ashburn-1" ,
118
- "key_content" : "test_key_content"
132
+ "key_content" : "test_key_content" ,
119
133
}
120
134
)
121
135
signer = default_signer ()
@@ -141,7 +155,12 @@ def tearDown(self) -> None:
141
155
@mock .patch ("oci.signer.Signer" )
142
156
@mock .patch ("oci.logging.LoggingManagementClient" )
143
157
def test_api_key_auth_with_logging (
144
- self , client , mock_signer , mock_path_exists , mock_config_from_file , mock_validate_config
158
+ self ,
159
+ client ,
160
+ mock_signer ,
161
+ mock_path_exists ,
162
+ mock_config_from_file ,
163
+ mock_validate_config ,
145
164
):
146
165
"""Tests initializing OCIMixin with default auth.
147
166
Without any explicit config, the client should be initialized from DEFAULT OCI API key config.
@@ -264,9 +283,9 @@ def test_set_auth_value_errors(self):
264
283
with pytest .raises (ValueError ):
265
284
AuthFactory ().signerGenerator ("not_existing_iam_type" )
266
285
267
- def test_register_singer (self ):
268
- AuthFactory ().register ("new_singer_type " , "signer_class" )
269
- assert "new_singer_type " in AuthFactory .classes .keys ()
286
+ def test_register_signer (self ):
287
+ AuthFactory ().register ("new_signer_type " , "signer_class" )
288
+ assert "new_signer_type " in AuthFactory .classes .keys ()
270
289
271
290
@mock .patch ("os.path.exists" )
272
291
@mock .patch (
@@ -281,7 +300,11 @@ def test_register_singer(self):
281
300
@mock .patch ("oci.config.validate_config" )
282
301
@mock .patch ("oci.signer.load_private_key_from_file" )
283
302
def test_api_key_create_signer (
284
- self , mock_load_key_file , mock_config_from_file , mock_path_exists , mock_validate_config
303
+ self ,
304
+ mock_load_key_file ,
305
+ mock_config_from_file ,
306
+ mock_path_exists ,
307
+ mock_validate_config ,
285
308
):
286
309
"""
287
310
Testing api key setup with set_auth() and getting it with default_signer()
@@ -358,7 +381,6 @@ def test_instance_principal_create_signer(self, mock_ip_signer):
358
381
@mock .patch ("ads.common.auth.AuthFactory" )
359
382
@mock .patch ("oci.auth.signers.InstancePrincipalsSecurityTokenSigner" )
360
383
def test_create_signer (self , mock_ip_signer , mock_signer_generator ):
361
-
362
384
auth = create_signer (signer = "test" )
363
385
assert auth ["signer" ] == "test"
364
386
@@ -389,7 +411,7 @@ def test_set_auth_multiple_times_with(
389
411
mock_config_from_file ,
390
412
mock_rp_signer ,
391
413
mock_ip_signer ,
392
- mock_validate_config
414
+ mock_validate_config ,
393
415
):
394
416
"""
395
417
Testing behaviour when multiple times invoked set_auth() with different parameters and validate,
@@ -537,41 +559,39 @@ def test_with_set_auth_returns_error(self):
537
559
538
560
539
561
class TestSecurityToken (TestCase ):
540
-
541
562
@mock .patch ("oci.auth.signers.SecurityTokenSigner.__init__" )
542
563
@mock .patch ("oci.signer.load_private_key_from_file" )
543
564
@mock .patch ("ads.common.auth.SecurityToken._read_security_token_file" )
544
565
@mock .patch ("ads.common.auth.SecurityToken._validate_and_refresh_token" )
545
566
def test_security_token (
546
567
self ,
547
- mock_validate_and_refresh_token ,
568
+ mock_validate_and_refresh_token ,
548
569
mock_read_security_token_file ,
549
570
mock_load_private_key_from_file ,
550
- mock_security_token_signer
571
+ mock_security_token_signer ,
551
572
):
552
573
config = {
553
574
"fingerprint" : "test_fingerprint" ,
554
575
"tenancy" : "test_tenancy" ,
555
576
"region" : "us-ashburn-1" ,
556
577
"key_file" : "test_key_file" ,
557
- "generic_headers" : [1 ,2 , 3 ],
558
- "body_headers" : [4 ,5 , 6 ]
578
+ "generic_headers" : [1 , 2 , 3 ],
579
+ "body_headers" : [4 , 5 , 6 ],
559
580
}
560
581
561
582
with pytest .raises (
562
583
ValueError ,
563
- match = "Parameter `security_token_file` must be provided for using `security_token` authentication."
584
+ match = "Parameter `security_token_file` must be provided for using `security_token` authentication." ,
564
585
):
565
586
signer = security_token (
566
587
oci_config = config ,
567
- client_kwargs = {"test_client_key" :"test_client_value" }
588
+ client_kwargs = {"test_client_key" : "test_client_value" },
568
589
)
569
590
570
591
config ["security_token_file" ] = "test_security_token"
571
592
mock_security_token_signer .return_value = None
572
593
signer = security_token (
573
- oci_config = config ,
574
- client_kwargs = {"test_client_key" :"test_client_value" }
594
+ oci_config = config , client_kwargs = {"test_client_key" : "test_client_value" }
575
595
)
576
596
577
597
mock_validate_and_refresh_token .assert_called_with (config )
@@ -593,50 +613,52 @@ def test_security_token(
593
613
@mock .patch ("oci.auth.security_token_container.SecurityTokenContainer.__init__" )
594
614
@mock .patch ("ads.common.auth.SecurityToken._read_security_token_file" )
595
615
def test_validate_and_refresh_token (
596
- self ,
597
- mock_read_security_token_file ,
616
+ self ,
617
+ mock_read_security_token_file ,
598
618
mock_security_token_container ,
599
619
mock_valid ,
600
620
mock_time ,
601
621
mock_get_jwt ,
602
- mock_system
622
+ mock_system ,
603
623
):
604
624
security_token = SecurityToken (
605
625
args = {
606
626
"oci_config_location" : DEFAULT_LOCATION ,
607
- "oci_key_profile" : "test_profile"
627
+ "oci_key_profile" : "test_profile" ,
608
628
}
609
629
)
610
630
mock_security_token_container .return_value = None
611
-
631
+
612
632
mock_valid .return_value = False
613
633
configuration = {
614
634
"fingerprint" : "test_fingerprint" ,
615
635
"tenancy" : "test_tenancy" ,
616
636
"region" : "us-ashburn-1" ,
617
637
"key_file" : "test_key_file" ,
618
638
"security_token_file" : "test_security_token" ,
619
- "generic_headers" : [1 ,2 , 3 ],
620
- "body_headers" : [4 ,5 , 6 ]
639
+ "generic_headers" : [1 , 2 , 3 ],
640
+ "body_headers" : [4 , 5 , 6 ],
621
641
}
622
642
with pytest .raises (
623
643
SecurityTokenError ,
624
- match = "Security token has expired. Call `oci session authenticate` to generate new session."
644
+ match = "Security token has expired. Call `oci session authenticate` to generate new session." ,
625
645
):
626
646
security_token ._validate_and_refresh_token (configuration )
627
-
647
+
628
648
mock_valid .return_value = True
629
649
mock_time .return_value = 1
630
- mock_get_jwt .return_value = {"exp" : 1 }
650
+ mock_get_jwt .return_value = {"exp" : 1 }
631
651
mock_system .return_value = 1
632
-
652
+
633
653
security_token ._validate_and_refresh_token (configuration )
634
-
654
+
635
655
mock_read_security_token_file .assert_called_with ("test_security_token" )
636
656
mock_security_token_container .assert_called ()
637
657
mock_time .assert_called ()
638
658
mock_get_jwt .assert_called ()
639
- mock_system .assert_called_with (f"oci session refresh --config-file { DEFAULT_LOCATION } --profile test_profile" )
659
+ mock_system .assert_called_with (
660
+ f"oci session refresh --config-file { DEFAULT_LOCATION } --profile test_profile"
661
+ )
640
662
641
663
@mock .patch ("builtins.open" )
642
664
@mock .patch ("os.path.isfile" )
@@ -645,8 +667,7 @@ def test_read_security_token_file(self, mock_isfile, mock_open):
645
667
646
668
mock_isfile .return_value = False
647
669
with pytest .raises (
648
- ValueError ,
649
- match = "Invalid `security_token_file`. Specify a valid path."
670
+ ValueError , match = "Invalid `security_token_file`. Specify a valid path."
650
671
):
651
672
security_token ._read_security_token_file ("test_security_token" )
652
673
0 commit comments