Skip to content

Commit 015d234

Browse files
committed
Update
2 parents 4c27385 + 8759088 commit 015d234

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

run/idp-sql/test/e2e_test.py

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
default_app = firebase_admin.initialize_app()
3232

3333
# Unique suffix to create distinct service names
34-
SUFFIX = uuid.uuid4().hex[:10]
34+
SUFFIX = '0c6fc5c6e1'#uuid.uuid4().hex[:10] #idp-sql-
3535

3636
GOOGLE_CLOUD_PROJECT = os.environ.get("GOOGLE_CLOUD_PROJECT", None)
3737
if not GOOGLE_CLOUD_PROJECT:
@@ -79,7 +79,7 @@
7979

8080
retry_strategy = Retry(
8181
total=3,
82-
status_forcelist=[400, 401, 403, 500, 502, 503, 504],
82+
status_forcelist=[400, 403, 500, 502, 503, 504],
8383
allowed_methods=["GET", "POST"],
8484
backoff_factor=3
8585
)
@@ -106,20 +106,20 @@ def deployed_service() -> str:
106106
if SAMPLE_VERSION:
107107
substitutions.append(f"_SAMPLE_VERSION={SAMPLE_VERSION}")
108108

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+
# )
123123

124124
service_url = (
125125
subprocess.run(
@@ -159,46 +159,63 @@ def deployed_service() -> str:
159159
if SAMPLE_VERSION:
160160
substitutions.append(f"_SAMPLE_VERSION={SAMPLE_VERSION}")
161161

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+
# )
176176

177177

178178
@pytest.fixture
179179
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+
180196
custom_token = auth.create_custom_token("a-user-id").decode("UTF-8")
197+
181198
adapter = HTTPAdapter(max_retries=retry_strategy)
182199

183200
client = requests.session()
184201
client.mount("https://", adapter)
185202

186203
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}",
188205
data=json.dumps({"token": custom_token, "returnSecureToken": True}),
189206
)
190207
response = resp.json()
191208
assert "error" not in response.keys()
192209
assert "idToken" in response.keys()
193210

194211
id_token = response["idToken"]
195-
yield id_token
212+
yield id_token, auth_token
196213

197214
# no cleanup required
198215

199216

200217
def test_end_to_end(jwt_token: str, deployed_service: str) -> None:
201-
token = jwt_token
218+
token, auth_token = jwt_token
202219
service_url = deployed_service
203220

204221
adapter = HTTPAdapter(max_retries=retry_strategy)
@@ -207,18 +224,18 @@ def test_end_to_end(jwt_token: str, deployed_service: str) -> None:
207224
client.mount("https://", adapter)
208225

209226
# 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}"})
211228
assert response.status_code == 200
212-
229+
213230
# Can make post with token
214231
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}"}
216233
)
217234
assert response.status_code == 200
218235
assert "Vote successfully cast" in response.content.decode("UTF-8")
219236

220237
# Confirm updated results
221-
response = client.get(service_url)
238+
response = client.get(service_url, headers={"Authorization": f"Bearer {auth_token}"})
222239
assert response.status_code == 200
223240
assert "🐶" in response.content.decode("UTF-8")
224241

run/idp-sql/test/e2e_test_setup.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ steps:
6666
./test/retry.sh "gcloud beta run deploy ${_SERVICE} \
6767
--project $PROJECT_ID \
6868
--image gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} \
69-
--allow-unauthenticated \
7069
--region ${_REGION} \
7170
--platform ${_PLATFORM} \
7271
--add-cloudsql-instances ${_CLOUD_SQL_CONNECTION_NAME} \

0 commit comments

Comments
 (0)