@@ -1043,6 +1043,56 @@ def test_retrieve_subject_token_success_environment_vars(self, utcnow, monkeypat
1043
1043
}
1044
1044
)
1045
1045
1046
+ @mock .patch ("google.auth._helpers.utcnow" )
1047
+ def test_retrieve_subject_token_success_environment_vars_with_default_region (
1048
+ self , utcnow , monkeypatch
1049
+ ):
1050
+ monkeypatch .setenv (environment_vars .AWS_ACCESS_KEY_ID , ACCESS_KEY_ID )
1051
+ monkeypatch .setenv (environment_vars .AWS_SECRET_ACCESS_KEY , SECRET_ACCESS_KEY )
1052
+ monkeypatch .setenv (environment_vars .AWS_SESSION_TOKEN , TOKEN )
1053
+ monkeypatch .setenv (environment_vars .AWS_DEFAULT_REGION , self .AWS_REGION )
1054
+ utcnow .return_value = datetime .datetime .strptime (
1055
+ self .AWS_SIGNATURE_TIME , "%Y-%m-%dT%H:%M:%SZ"
1056
+ )
1057
+ credentials = self .make_credentials (credential_source = self .CREDENTIAL_SOURCE )
1058
+
1059
+ subject_token = credentials .retrieve_subject_token (None )
1060
+
1061
+ assert subject_token == self .make_serialized_aws_signed_request (
1062
+ {
1063
+ "access_key_id" : ACCESS_KEY_ID ,
1064
+ "secret_access_key" : SECRET_ACCESS_KEY ,
1065
+ "security_token" : TOKEN ,
1066
+ }
1067
+ )
1068
+
1069
+ @mock .patch ("google.auth._helpers.utcnow" )
1070
+ def test_retrieve_subject_token_success_environment_vars_with_both_regions_set (
1071
+ self , utcnow , monkeypatch
1072
+ ):
1073
+ monkeypatch .setenv (environment_vars .AWS_ACCESS_KEY_ID , ACCESS_KEY_ID )
1074
+ monkeypatch .setenv (environment_vars .AWS_SECRET_ACCESS_KEY , SECRET_ACCESS_KEY )
1075
+ monkeypatch .setenv (environment_vars .AWS_SESSION_TOKEN , TOKEN )
1076
+ monkeypatch .setenv (environment_vars .AWS_DEFAULT_REGION , "Malformed AWS Region" )
1077
+ # This test makes sure that the AWS_REGION gets used over AWS_DEFAULT_REGION,
1078
+ # So, AWS_DEFAULT_REGION is set to something that would cause the test to fail,
1079
+ # And AWS_REGION is set to the a valid value, and it should succeed
1080
+ monkeypatch .setenv (environment_vars .AWS_REGION , self .AWS_REGION )
1081
+ utcnow .return_value = datetime .datetime .strptime (
1082
+ self .AWS_SIGNATURE_TIME , "%Y-%m-%dT%H:%M:%SZ"
1083
+ )
1084
+ credentials = self .make_credentials (credential_source = self .CREDENTIAL_SOURCE )
1085
+
1086
+ subject_token = credentials .retrieve_subject_token (None )
1087
+
1088
+ assert subject_token == self .make_serialized_aws_signed_request (
1089
+ {
1090
+ "access_key_id" : ACCESS_KEY_ID ,
1091
+ "secret_access_key" : SECRET_ACCESS_KEY ,
1092
+ "security_token" : TOKEN ,
1093
+ }
1094
+ )
1095
+
1046
1096
@mock .patch ("google.auth._helpers.utcnow" )
1047
1097
def test_retrieve_subject_token_success_environment_vars_no_session_token (
1048
1098
self , utcnow , monkeypatch
0 commit comments