@@ -99,18 +99,7 @@ def test_default_state(self):
99
99
)
100
100
@mock .patch ("google.auth.compute_engine._metadata.get" , autospec = True )
101
101
def test_refresh_success (self , get , utcnow ):
102
- get .side_effect = [
103
- {
104
- # First request is for sevice account info.
105
- "email" : "service-account@example.com" ,
106
- "scopes" : ["one" , "two" ],
107
- },
108
- {
109
- # Second request is for the token.
110
- "access_token" : "token" ,
111
- "expires_in" : 500 ,
112
- },
113
- ]
102
+ get .side_effect = [{"access_token" : "token" , "expires_in" : 500 }]
114
103
115
104
# Refresh credentials
116
105
self .credentials .refresh (None )
@@ -120,8 +109,8 @@ def test_refresh_success(self, get, utcnow):
120
109
assert self .credentials .expiry == (utcnow () + datetime .timedelta (seconds = 500 ))
121
110
122
111
# Check the credential info
123
- assert self .credentials .service_account_email == "service-account@example.com "
124
- assert self .credentials ._scopes == [ "one" , "two" ]
112
+ assert self .credentials .service_account_email == "default "
113
+ assert self .credentials ._scopes is None
125
114
126
115
# Check that the credentials are valid (have a token and are not
127
116
# expired)
@@ -137,18 +126,7 @@ def test_refresh_success(self, get, utcnow):
137
126
)
138
127
@mock .patch ("google.auth.compute_engine._metadata.get" , autospec = True )
139
128
def test_refresh_success_with_scopes (self , get , utcnow , mock_metrics_header_value ):
140
- get .side_effect = [
141
- {
142
- # First request is for sevice account info.
143
- "email" : "service-account@example.com" ,
144
- "scopes" : ["one" , "two" ],
145
- },
146
- {
147
- # Second request is for the token.
148
- "access_token" : "token" ,
149
- "expires_in" : 500 ,
150
- },
151
- ]
129
+ get .side_effect = [{"access_token" : "token" , "expires_in" : 500 }]
152
130
153
131
# Refresh credentials
154
132
scopes = ["three" , "four" ]
@@ -160,7 +138,7 @@ def test_refresh_success_with_scopes(self, get, utcnow, mock_metrics_header_valu
160
138
assert self .credentials .expiry == (utcnow () + datetime .timedelta (seconds = 500 ))
161
139
162
140
# Check the credential info
163
- assert self .credentials .service_account_email == "service-account@example.com "
141
+ assert self .credentials .service_account_email == "default "
164
142
assert self .credentials ._scopes == scopes
165
143
166
144
# Check that the credentials are valid (have a token and are not
@@ -184,18 +162,7 @@ def test_refresh_error(self, get):
184
162
185
163
@mock .patch ("google.auth.compute_engine._metadata.get" , autospec = True )
186
164
def test_before_request_refreshes (self , get ):
187
- get .side_effect = [
188
- {
189
- # First request is for sevice account info.
190
- "email" : "service-account@example.com" ,
191
- "scopes" : "one two" ,
192
- },
193
- {
194
- # Second request is for the token.
195
- "access_token" : "token" ,
196
- "expires_in" : 500 ,
197
- },
198
- ]
165
+ get .side_effect = [{"access_token" : "token" , "expires_in" : 500 }]
199
166
200
167
# Credentials should start as invalid
201
168
assert not self .credentials .valid
@@ -473,20 +440,6 @@ def test_with_target_audience_integration(self):
473
440
have been mocked.
474
441
"""
475
442
476
- # mock information about credentials
477
- responses .add (
478
- responses .GET ,
479
- "http://metadata.google.internal/computeMetadata/v1/instance/"
480
- "service-accounts/default/?recursive=true" ,
481
- status = 200 ,
482
- content_type = "application/json" ,
483
- json = {
484
- "scopes" : "email" ,
485
- "email" : "service-account@example.com" ,
486
- "aliases" : ["default" ],
487
- },
488
- )
489
-
490
443
# mock information about universe_domain
491
444
responses .add (
492
445
responses .GET ,
@@ -501,7 +454,7 @@ def test_with_target_audience_integration(self):
501
454
responses .add (
502
455
responses .GET ,
503
456
"http://metadata.google.internal/computeMetadata/v1/instance/"
504
- "service-accounts/service-account@example.com /token" ,
457
+ "service-accounts/default /token" ,
505
458
status = 200 ,
506
459
content_type = "application/json" ,
507
460
json = {
@@ -641,25 +594,11 @@ def test_with_quota_project_integration(self):
641
594
have been mocked.
642
595
"""
643
596
644
- # mock information about credentials
645
- responses .add (
646
- responses .GET ,
647
- "http://metadata.google.internal/computeMetadata/v1/instance/"
648
- "service-accounts/default/?recursive=true" ,
649
- status = 200 ,
650
- content_type = "application/json" ,
651
- json = {
652
- "scopes" : "email" ,
653
- "email" : "service-account@example.com" ,
654
- "aliases" : ["default" ],
655
- },
656
- )
657
-
658
597
# mock token for credentials
659
598
responses .add (
660
599
responses .GET ,
661
600
"http://metadata.google.internal/computeMetadata/v1/instance/"
662
- "service-accounts/service-account@example.com /token" ,
601
+ "service-accounts/default /token" ,
663
602
status = 200 ,
664
603
content_type = "application/json" ,
665
604
json = {
0 commit comments