3232 "gl-python/3.7 auth/1.1 auth-request-type/at cred-type/imp"
3333)
3434
35+ LANG_LIBRARY_METRICS_HEADER_VALUE = "gl-python/3.7 auth/1.1"
36+
3537CLIENT_ID = "username"
3638CLIENT_SECRET = "password"
3739# Base64 encoding of "username:password".
@@ -1793,8 +1795,14 @@ def test_retrieve_subject_token_error_determining_aws_security_creds(self):
17931795
17941796 assert excinfo .match (r"Unable to retrieve AWS security credentials" )
17951797
1798+ @mock .patch (
1799+ "google.auth.metrics.python_and_auth_lib_version" ,
1800+ return_value = LANG_LIBRARY_METRICS_HEADER_VALUE ,
1801+ )
17961802 @mock .patch ("google.auth._helpers.utcnow" )
1797- def test_refresh_success_without_impersonation_ignore_default_scopes (self , utcnow ):
1803+ def test_refresh_success_without_impersonation_ignore_default_scopes (
1804+ self , utcnow , mock_auth_lib_value
1805+ ):
17981806 utcnow .return_value = datetime .datetime .strptime (
17991807 self .AWS_SIGNATURE_TIME , "%Y-%m-%dT%H:%M:%SZ"
18001808 )
@@ -1808,6 +1816,7 @@ def test_refresh_success_without_impersonation_ignore_default_scopes(self, utcno
18081816 token_headers = {
18091817 "Content-Type" : "application/x-www-form-urlencoded" ,
18101818 "Authorization" : "Basic " + BASIC_AUTH_ENCODING ,
1819+ "x-goog-api-client" : "gl-python/3.7 auth/1.1 google-byoid-sdk sa-impersonation/false config-lifetime/false source/aws" ,
18111820 }
18121821 token_request_data = {
18131822 "grant_type" : "urn:ietf:params:oauth:grant-type:token-exchange" ,
@@ -1849,8 +1858,14 @@ def test_refresh_success_without_impersonation_ignore_default_scopes(self, utcno
18491858 assert credentials .scopes == SCOPES
18501859 assert credentials .default_scopes == ["ignored" ]
18511860
1861+ @mock .patch (
1862+ "google.auth.metrics.python_and_auth_lib_version" ,
1863+ return_value = LANG_LIBRARY_METRICS_HEADER_VALUE ,
1864+ )
18521865 @mock .patch ("google.auth._helpers.utcnow" )
1853- def test_refresh_success_without_impersonation_use_default_scopes (self , utcnow ):
1866+ def test_refresh_success_without_impersonation_use_default_scopes (
1867+ self , utcnow , mock_auth_lib_value
1868+ ):
18541869 utcnow .return_value = datetime .datetime .strptime (
18551870 self .AWS_SIGNATURE_TIME , "%Y-%m-%dT%H:%M:%SZ"
18561871 )
@@ -1864,6 +1879,7 @@ def test_refresh_success_without_impersonation_use_default_scopes(self, utcnow):
18641879 token_headers = {
18651880 "Content-Type" : "application/x-www-form-urlencoded" ,
18661881 "Authorization" : "Basic " + BASIC_AUTH_ENCODING ,
1882+ "x-goog-api-client" : "gl-python/3.7 auth/1.1 google-byoid-sdk sa-impersonation/false config-lifetime/false source/aws" ,
18671883 }
18681884 token_request_data = {
18691885 "grant_type" : "urn:ietf:params:oauth:grant-type:token-exchange" ,
@@ -1909,9 +1925,13 @@ def test_refresh_success_without_impersonation_use_default_scopes(self, utcnow):
19091925 "google.auth.metrics.token_request_access_token_impersonate" ,
19101926 return_value = IMPERSONATE_ACCESS_TOKEN_REQUEST_METRICS_HEADER_VALUE ,
19111927 )
1928+ @mock .patch (
1929+ "google.auth.metrics.python_and_auth_lib_version" ,
1930+ return_value = LANG_LIBRARY_METRICS_HEADER_VALUE ,
1931+ )
19121932 @mock .patch ("google.auth._helpers.utcnow" )
19131933 def test_refresh_success_with_impersonation_ignore_default_scopes (
1914- self , utcnow , mock_metrics_header_value
1934+ self , utcnow , mock_metrics_header_value , mock_auth_lib_value
19151935 ):
19161936 utcnow .return_value = datetime .datetime .strptime (
19171937 self .AWS_SIGNATURE_TIME , "%Y-%m-%dT%H:%M:%SZ"
@@ -1929,6 +1949,7 @@ def test_refresh_success_with_impersonation_ignore_default_scopes(
19291949 token_headers = {
19301950 "Content-Type" : "application/x-www-form-urlencoded" ,
19311951 "Authorization" : "Basic " + BASIC_AUTH_ENCODING ,
1952+ "x-goog-api-client" : "gl-python/3.7 auth/1.1 google-byoid-sdk sa-impersonation/true config-lifetime/false source/aws" ,
19321953 }
19331954 token_request_data = {
19341955 "grant_type" : "urn:ietf:params:oauth:grant-type:token-exchange" ,
@@ -2000,9 +2021,13 @@ def test_refresh_success_with_impersonation_ignore_default_scopes(
20002021 "google.auth.metrics.token_request_access_token_impersonate" ,
20012022 return_value = IMPERSONATE_ACCESS_TOKEN_REQUEST_METRICS_HEADER_VALUE ,
20022023 )
2024+ @mock .patch (
2025+ "google.auth.metrics.python_and_auth_lib_version" ,
2026+ return_value = LANG_LIBRARY_METRICS_HEADER_VALUE ,
2027+ )
20032028 @mock .patch ("google.auth._helpers.utcnow" )
20042029 def test_refresh_success_with_impersonation_use_default_scopes (
2005- self , utcnow , mock_metrics_header_value
2030+ self , utcnow , mock_metrics_header_value , mock_auth_lib_value
20062031 ):
20072032 utcnow .return_value = datetime .datetime .strptime (
20082033 self .AWS_SIGNATURE_TIME , "%Y-%m-%dT%H:%M:%SZ"
@@ -2020,6 +2045,7 @@ def test_refresh_success_with_impersonation_use_default_scopes(
20202045 token_headers = {
20212046 "Content-Type" : "application/x-www-form-urlencoded" ,
20222047 "Authorization" : "Basic " + BASIC_AUTH_ENCODING ,
2048+ "x-goog-api-client" : "gl-python/3.7 auth/1.1 google-byoid-sdk sa-impersonation/true config-lifetime/false source/aws" ,
20232049 }
20242050 token_request_data = {
20252051 "grant_type" : "urn:ietf:params:oauth:grant-type:token-exchange" ,
0 commit comments