31
31
default_app = firebase_admin .initialize_app ()
32
32
33
33
# Unique suffix to create distinct service names
34
- SUFFIX = uuid .uuid4 ().hex [:10 ]
34
+ SUFFIX = '0c6fc5c6e1' # uuid.uuid4().hex[:10] #idp-sql-
35
35
36
36
GOOGLE_CLOUD_PROJECT = os .environ .get ("GOOGLE_CLOUD_PROJECT" , None )
37
37
if not GOOGLE_CLOUD_PROJECT :
79
79
80
80
retry_strategy = Retry (
81
81
total = 3 ,
82
- status_forcelist = [400 , 401 , 403 , 500 , 502 , 503 , 504 ],
82
+ status_forcelist = [400 , 403 , 500 , 502 , 503 , 504 ],
83
83
allowed_methods = ["GET" , "POST" ],
84
84
backoff_factor = 3
85
85
)
@@ -106,20 +106,20 @@ def deployed_service() -> str:
106
106
if SAMPLE_VERSION :
107
107
substitutions .append (f"_SAMPLE_VERSION={ SAMPLE_VERSION } " )
108
108
109
- subprocess .run (
110
- [
111
- "gcloud" ,
112
- "builds" ,
113
- "submit" ,
114
- "--project" ,
115
- GOOGLE_CLOUD_PROJECT ,
116
- "--config" ,
117
- "./test/e2e_test_setup.yaml" ,
118
- "--substitutions" ,
119
- ]
120
- + substitutions ,
121
- check = True ,
122
- )
109
+ # subprocess.run(
110
+ # [
111
+ # "gcloud",
112
+ # "builds",
113
+ # "submit",
114
+ # "--project",
115
+ # GOOGLE_CLOUD_PROJECT,
116
+ # "--config",
117
+ # "./test/e2e_test_setup.yaml",
118
+ # "--substitutions",
119
+ # ]
120
+ # + substitutions,
121
+ # check=True,
122
+ # )
123
123
124
124
service_url = (
125
125
subprocess .run (
@@ -159,46 +159,63 @@ def deployed_service() -> str:
159
159
if SAMPLE_VERSION :
160
160
substitutions .append (f"_SAMPLE_VERSION={ SAMPLE_VERSION } " )
161
161
162
- subprocess .run (
163
- [
164
- "gcloud" ,
165
- "builds" ,
166
- "submit" ,
167
- "--project" ,
168
- GOOGLE_CLOUD_PROJECT ,
169
- "--config" ,
170
- "./test/e2e_test_cleanup.yaml" ,
171
- "--substitutions" ,
172
- ]
173
- + substitutions ,
174
- check = True ,
175
- )
162
+ # subprocess.run(
163
+ # [
164
+ # "gcloud",
165
+ # "builds",
166
+ # "submit",
167
+ # "--project",
168
+ # GOOGLE_CLOUD_PROJECT,
169
+ # "--config",
170
+ # "./test/e2e_test_cleanup.yaml",
171
+ # "--substitutions",
172
+ # ]
173
+ # + substitutions,
174
+ # check=True,
175
+ # )
176
176
177
177
178
178
@pytest .fixture
179
179
def jwt_token () -> str :
180
+ auth_token = (
181
+ subprocess .run (
182
+ [
183
+ "gcloud" ,
184
+ "auth" ,
185
+ "print-identity-token" ,
186
+ "--project" ,
187
+ GOOGLE_CLOUD_PROJECT ,
188
+ ],
189
+ stdout = subprocess .PIPE ,
190
+ check = True ,
191
+ )
192
+ .stdout .strip ()
193
+ .decode ()
194
+ )
195
+
180
196
custom_token = auth .create_custom_token ("a-user-id" ).decode ("UTF-8" )
197
+
181
198
adapter = HTTPAdapter (max_retries = retry_strategy )
182
199
183
200
client = requests .session ()
184
201
client .mount ("https://" , adapter )
185
202
186
203
resp = client .post (
187
- f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken ?key={ IDP_KEY } " ,
204
+ f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp ?key={ IDP_KEY } " ,
188
205
data = json .dumps ({"token" : custom_token , "returnSecureToken" : True }),
189
206
)
190
207
response = resp .json ()
191
208
assert "error" not in response .keys ()
192
209
assert "idToken" in response .keys ()
193
210
194
211
id_token = response ["idToken" ]
195
- yield id_token
212
+ yield id_token , auth_token
196
213
197
214
# no cleanup required
198
215
199
216
200
217
def test_end_to_end (jwt_token : str , deployed_service : str ) -> None :
201
- token = jwt_token
218
+ token , auth_token = jwt_token
202
219
service_url = deployed_service
203
220
204
221
adapter = HTTPAdapter (max_retries = retry_strategy )
@@ -207,18 +224,18 @@ def test_end_to_end(jwt_token: str, deployed_service: str) -> None:
207
224
client .mount ("https://" , adapter )
208
225
209
226
# Can successfully make a request
210
- response = client .get (service_url )
227
+ response = client .get (service_url , headers = { "Authorization" : f"Bearer { auth_token } , Bearer { token } " } )
211
228
assert response .status_code == 200
212
-
229
+
213
230
# Can make post with token
214
231
response = client .post (
215
- service_url , data = {"team" : "DOGS" }, headers = {"Authorization" : f"Bearer { token } " }
232
+ service_url , data = {"team" : "DOGS" }, headers = {"Authorization" : f"Bearer { auth_token } ,Bearer { token } " }
216
233
)
217
234
assert response .status_code == 200
218
235
assert "Vote successfully cast" in response .content .decode ("UTF-8" )
219
236
220
237
# Confirm updated results
221
- response = client .get (service_url )
238
+ response = client .get (service_url , headers = { "Authorization" : f"Bearer { auth_token } " } )
222
239
assert response .status_code == 200
223
240
assert "🐶" in response .content .decode ("UTF-8" )
224
241
0 commit comments