Skip to content

Commit 190e6e2

Browse files
committed
Update test
1 parent fcf132a commit 190e6e2

File tree

2 files changed

+57
-55
lines changed

2 files changed

+57
-55
lines changed

run/idp-sql/test/e2e_test.py

Lines changed: 57 additions & 54 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:
@@ -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(
@@ -144,23 +144,8 @@ def deployed_service() -> str:
144144
.stdout.strip()
145145
.decode()
146146
)
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-
)
162147

163-
yield service_url, auth_token
148+
yield service_url
164149

165150
# Cleanup
166151

@@ -174,57 +159,75 @@ def deployed_service() -> str:
174159
if SAMPLE_VERSION:
175160
substitutions.append(f"_SAMPLE_VERSION={SAMPLE_VERSION}")
176161

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

192177

193178
@pytest.fixture
194179
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)
195196
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)
197199

198200
client = requests.session()
199-
client.mount("https://", adapter)
201+
# client.mount("https://", adapter)
200202

201203
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}),
204206
)
205207
response = resp.json()
206208
assert "error" not in response.keys()
207209
assert "idToken" in response.keys()
208210

209211
id_token = response["idToken"]
210-
yield id_token
212+
yield id_token, auth_token
211213

212214
# no cleanup required
213215

214216

215217
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
218220

219221
adapter = HTTPAdapter(max_retries=retry_strategy)
220222

221223
client = requests.session()
222224
client.mount("https://", adapter)
223-
225+
print(auth_token)
226+
print(token)
224227
# Can successfully make a request
225228
response = client.get(service_url, headers={"Authorization": f"Bearer {auth_token}"})
226229
assert response.status_code == 200
227-
230+
228231
# Can make post with token
229232
response = client.post(
230233
service_url, data={"team": "DOGS"}, headers={"Authorization": f"Bearer {token}"}

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)