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 :
@@ -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 (
@@ -144,23 +144,8 @@ def deployed_service() -> str:
144
144
.stdout .strip ()
145
145
.decode ()
146
146
)
147
- auth_token = (
148
- subprocess .run (
149
- [
150
- "gcloud" ,
151
- "auth" ,
152
- "print-identity-token" ,
153
- "--project" ,
154
- GOOGLE_CLOUD_PROJECT ,
155
- ],
156
- stdout = subprocess .PIPE ,
157
- check = True ,
158
- )
159
- .stdout .strip ()
160
- .decode ()
161
- )
162
147
163
- yield service_url , auth_token
148
+ yield service_url
164
149
165
150
# Cleanup
166
151
@@ -174,57 +159,75 @@ def deployed_service() -> str:
174
159
if SAMPLE_VERSION :
175
160
substitutions .append (f"_SAMPLE_VERSION={ SAMPLE_VERSION } " )
176
161
177
- subprocess .run (
178
- [
179
- "gcloud" ,
180
- "builds" ,
181
- "submit" ,
182
- "--project" ,
183
- GOOGLE_CLOUD_PROJECT ,
184
- "--config" ,
185
- "./test/e2e_test_cleanup.yaml" ,
186
- "--substitutions" ,
187
- ]
188
- + substitutions ,
189
- check = True ,
190
- )
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
+ # )
191
176
192
177
193
178
@pytest .fixture
194
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
+ print (auth_token )
195
196
custom_token = auth .create_custom_token ("a-user-id" ).decode ("UTF-8" )
196
- adapter = HTTPAdapter (max_retries = retry_strategy )
197
+ print (custom_token )
198
+ # adapter = HTTPAdapter(max_retries=retry_strategy)
197
199
198
200
client = requests .session ()
199
- client .mount ("https://" , adapter )
201
+ # client.mount("https://", adapter)
200
202
201
203
resp = client .post (
202
- f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken ?key={ IDP_KEY } " ,
203
- data = json .dumps ({"token" : custom_token , "returnSecureToken" : True }),
204
+ f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp ?key={ IDP_KEY } " ,
205
+ data = json .dumps ({"token" : auth_token , "returnSecureToken" : True }),
204
206
)
205
207
response = resp .json ()
206
208
assert "error" not in response .keys ()
207
209
assert "idToken" in response .keys ()
208
210
209
211
id_token = response ["idToken" ]
210
- yield id_token
212
+ yield id_token , auth_token
211
213
212
214
# no cleanup required
213
215
214
216
215
217
def test_end_to_end (jwt_token : str , deployed_service : str ) -> None :
216
- token = jwt_token
217
- service_url , auth_token = deployed_service
218
+ token , auth_token = jwt_token
219
+ service_url = deployed_service
218
220
219
221
adapter = HTTPAdapter (max_retries = retry_strategy )
220
222
221
223
client = requests .session ()
222
224
client .mount ("https://" , adapter )
223
-
225
+ print (auth_token )
226
+ print (token )
224
227
# Can successfully make a request
225
228
response = client .get (service_url , headers = {"Authorization" : f"Bearer { auth_token } " })
226
229
assert response .status_code == 200
227
-
230
+
228
231
# Can make post with token
229
232
response = client .post (
230
233
service_url , data = {"team" : "DOGS" }, headers = {"Authorization" : f"Bearer { token } " }
0 commit comments