Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b90797d
ci(idp-sql): run idp-sql tests in testing isolation
glasnt Feb 25, 2025
1312379
add secret
glasnt Feb 25, 2025
ae8a90c
update tests run, copied from eventarc/audit-storage
glasnt Feb 25, 2025
00e8114
debug: swap order
glasnt Feb 25, 2025
7e5ae5f
Revert "debug: swap order"
glasnt Feb 25, 2025
f573a2a
debug: update firebase-admin version
glasnt Feb 25, 2025
21b9605
add env, secrets
glasnt Feb 25, 2025
1a96dac
correct exit code on retry
glasnt Feb 25, 2025
b21482e
dynamic service name
glasnt Feb 25, 2025
dad045b
wip: pass service account as env, to test
glasnt Feb 25, 2025
bc3e82e
logging: CLOUD_LOGGING_ONLY
glasnt Feb 25, 2025
10e72a8
correct YAML is useful
glasnt Feb 26, 2025
e95da9d
dynamicsubtitutions
glasnt Feb 26, 2025
11a70c8
Merge branch 'main' into ariwete-run-idp-sql
glasnt Feb 28, 2025
df80739
rename token as not to confuse with new default envvar
glasnt Feb 28, 2025
8c2b879
use new envvar
glasnt Feb 28, 2025
1dfbefe
update SA usage
glasnt Feb 28, 2025
7c255fe
add custom audience
glasnt Feb 28, 2025
096ebe2
cleanup
glasnt Feb 28, 2025
189f17c
remove platform, extra SA var
glasnt Feb 28, 2025
d4cfd2d
lint
glasnt Feb 28, 2025
29a8f08
more lint
glasnt Feb 28, 2025
cc70a1d
format
glasnt Feb 28, 2025
429edee
add sample version value
glasnt Feb 28, 2025
1792e70
correct audience
glasnt Feb 28, 2025
0fc96bc
lint
glasnt Feb 28, 2025
b00cc9b
disable cleanup for debugging
glasnt Feb 28, 2025
06a72b2
Merge branch 'main' into ariwete-run-idp-sql
glasnt Mar 3, 2025
3867b44
add test to dev list
glasnt Mar 3, 2025
2cb4f04
Merge branch 'main' into ariwete-run-idp-sql
glasnt Mar 4, 2025
7eb82c7
attempt proxy powered
glasnt Mar 4, 2025
95896c0
lint
glasnt Mar 4, 2025
b096ca4
attempt: proxy shell
glasnt Mar 4, 2025
0ee57e2
lint
glasnt Mar 4, 2025
2faec3f
format
glasnt Mar 4, 2025
414ebff
try using x-headers
glasnt Mar 4, 2025
8dddbcf
Merge branch 'main' into ariwete-run-idp-sql
glasnt Mar 17, 2025
a2e7320
fix: headers
glasnt Mar 17, 2025
e97c91b
Merge branch 'main' into ariwete-run-idp-sql
glasnt Mar 23, 2025
4e64db2
pass db user/name if supplied
glasnt Mar 23, 2025
c05beef
revert "try using x-headers"
glasnt Mar 23, 2025
94cb82a
debugging: where 400 error coming from?
glasnt Mar 24, 2025
aafa923
reenable cleanup
glasnt Mar 24, 2025
1903807
try capturing the token error
glasnt Mar 24, 2025
717d351
lint
glasnt Mar 24, 2025
b69f4eb
use explicitly named secret reference
glasnt Mar 24, 2025
a0bcccf
restore: try x-headers (debug)
glasnt Mar 24, 2025
37518cf
Revert "restore: try x-headers (debug)"
glasnt Mar 24, 2025
1335ed7
revert custom audience (not required if not using ID_TOKEN)
glasnt Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/config/nodejs-dev.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"run/image-processing",
"run/jobs",
"run/logging-manual",
"run/idp-sql",
"run/markdown-preview/editor",
"run/markdown-preview/renderer",
"run/pubsub",
Expand Down
1 change: 0 additions & 1 deletion .github/config/nodejs-prod.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"functions/slack", // TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type ... Received undefined
"healthcare/fhir", // Error: Cannot find module 'whatwg-url'
"iam/deny", // PERMISSION_DENIED: Permission iam.googleapis.com/denypolicies.create denied on resource cloudresourcemanager.googleapis.com/projects/long-door-651
"run/idp-sql", // (untested) Error: Invalid contents in the credentials file
"storagetransfer", // CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
"video-intelligence", // PERMISSION_DENIED: The caller does not have permission
"workflows", // SyntaxError: Cannot use import statement outside a module
Expand Down
12 changes: 12 additions & 0 deletions run/idp-sql/ci-setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"SERVICE_NAME": "idp-sql-${RUN_ID}",
"SAMPLE_VERSION": "${RUN_ID}",
"CLOUD_SQL_CONNECTION_NAME": "nodejs-docs-samples-tests:us-central1:test-postgres-instance",
"DB_NAME": "ci-database",
"DB_USER": "ci-user"
},
"secrets": {
"IDP_KEY": "nodejs-docs-samples-tests/nodejs-docs-samples-idp-key",
"DB_PASSWORD": "nodejs-docs-samples-tests/nodejs-docs-samples-test-postgres-instance-ci-user-password" }
}
8 changes: 5 additions & 3 deletions run/idp-sql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
},
"scripts": {
"start": "node index.js",
"test": "c8 mocha -p -j 2 test/app.test.js --timeout=120000 --exit",
"system-test": "c8 mocha -p -j 2 test/system.test.js --timeout=1800000 --exit"
"unit-test": "c8 mocha -p -j 2 test/app.test.js --timeout=120000 --exit",
"system-test": "test/proxy-setup.sh && c8 mocha -p -j 2 test/system.test.js --timeout=1800000 --exit",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test/proxy-setup.sh powers this test; unsure if there's something more more scalable that can be done here.

"all-test": "npm run unit-test && npm run system-test",
"test": "npm -- run all-test"
},
"dependencies": {
"express": "^4.16.2",
"firebase-admin": "^12.0.0",
"firebase-admin": "^13.0.0",
"gcp-metadata": "^6.0.0",
"google-auth-library": "^9.0.0",
"handlebars": "^4.7.6",
Expand Down
25 changes: 22 additions & 3 deletions run/idp-sql/test/e2e_test_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


steps:

- id: 'Delete resources'
Expand All @@ -12,11 +27,15 @@ steps:
./test/retry.sh "gcloud container images describe gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION}" \
"gcloud container images delete gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} --quiet"

./test/retry.sh "gcloud run services describe ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM}" \
"gcloud run services delete ${_SERVICE} --region ${_REGION} --platform ${_PLATFORM} --quiet"
./test/retry.sh "gcloud run services describe ${_SERVICE} --region ${_REGION}" \
"gcloud run services delete ${_SERVICE} --region ${_REGION} --quiet"

substitutions:
_SERVICE: idp-sql
_VERSION: manual
_REGION: us-central1
_PLATFORM: managed

serviceAccount: 'projects/${PROJECT_ID}/serviceAccounts/${_SERVICE_ACCOUNT}'
options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true
33 changes: 29 additions & 4 deletions run/idp-sql/test/e2e_test_setup.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


steps:

- id: 'Add a Secret to Secret Manager'
Expand All @@ -12,9 +27,13 @@ steps:
sed -i "s/\"DB_USER\": \"postgres\"/\"DB_USER\": \"${_DB_USER}\"/" postgres-secrets.json

./test/retry.sh "gcloud secrets create ${_SERVICE}-secrets \
--replication-policy="automatic" \
--replication-policy=automatic \
--data-file=postgres-secrets.json"

./test/retry.sh "gcloud secrets add-iam-policy-binding ${_SERVICE}-secrets \
--member=serviceAccount:${_SERVICE_ACCOUNT} \
--role=roles/secretmanager.secretAccessor"

- id: 'Build Container Image'
name: 'gcr.io/cloud-builders/docker'
entrypoint: '/bin/bash'
Expand All @@ -37,12 +56,13 @@ steps:
args:
- '-c'
- |
./test/retry.sh "gcloud beta run deploy ${_SERVICE} \
./test/retry.sh "gcloud run deploy ${_SERVICE} \
--image gcr.io/${PROJECT_ID}/${_SERVICE}:${_VERSION} \
--allow-unauthenticated \
--region ${_REGION} \
--platform ${_PLATFORM} \
--service-account ${_SERVICE_ACCOUNT} \
--add-cloudsql-instances ${_CLOUD_SQL_CONNECTION_NAME} \
--add-custom-audiences="https://action.test/" \
--update-secrets CLOUD_SQL_CREDENTIALS_SECRET=${_SERVICE}-secrets:latest"

images:
Expand All @@ -52,8 +72,13 @@ substitutions:
_SERVICE: idp-sql
_VERSION: manual
_REGION: us-central1
_PLATFORM: managed
_CLOUD_SQL_CONNECTION_NAME: $PROJECT_ID:us-central1:idp-sql-instance
_DB_NAME: postgres
_DB_USER: postgres
_DB_PASSWORD: password1234
_SERVICE_ACCOUNT: ${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com

serviceAccount: 'projects/${PROJECT_ID}/serviceAccounts/${_SERVICE_ACCOUNT}'
options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true
19 changes: 19 additions & 0 deletions run/idp-sql/test/proxy-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Proof of concept: setting up proxy

curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.15.1/cloud-sql-proxy.linux.amd64
chmod +x cloud-sql-proxy
cloud-sql-proxy -dir=/cloudsql -instances=$INSTANCE_CONNECTION_NAME &
2 changes: 1 addition & 1 deletion run/idp-sql/test/retry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ do
if ((attempt_num==max_attempts))
then
echo "Attempt $attempt_num / $max_attempts failed! No more retries left!"
exit
exit 1
else
echo "Attempt $attempt_num / $max_attempts failed!"
sleep $((attempt_num++))
Expand Down
29 changes: 20 additions & 9 deletions run/idp-sql/test/system.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
console.log('"SERVICE_NAME" env var not found. Defaulting to "idp-sql"');
SERVICE_NAME = 'idp-sql';
}

const {SERVICE_ACCOUNT} = process.env;
const {SAMPLE_VERSION} = process.env;
const PLATFORM = 'managed';
const REGION = 'us-central1';
Expand All @@ -41,6 +43,9 @@
if (!CLOUD_SQL_CONNECTION_NAME) {
throw Error('"CLOUD_SQL_CONNECTION_NAME" env var not found.');
}

const {DB_NAME} = process.env;
const {DB_USER} = process.env;
const {DB_PASSWORD} = process.env;
if (!DB_PASSWORD) {
throw Error('"DB_PASSWORD" env var not found.');
Expand All @@ -52,15 +57,19 @@
throw Error('"IDP_KEY" env var not found.');
}

let BASE_URL, ID_TOKEN;
let BASE_URL, CUSTOM_TOKEN;
before(async () => {
// Deploy service using Cloud Build
let buildCmd =
`gcloud builds submit --project ${GOOGLE_CLOUD_PROJECT} ` +
'--config ./test/e2e_test_setup.yaml ' +
`--substitutions _SERVICE=${SERVICE_NAME},_PLATFORM=${PLATFORM},_REGION=${REGION}` +
`--substitutions _SERVICE=${SERVICE_NAME},_REGION=${REGION}` +
`,_DB_PASSWORD=${DB_PASSWORD},_CLOUD_SQL_CONNECTION_NAME=${CLOUD_SQL_CONNECTION_NAME}`;

if (SERVICE_ACCOUNT) buildCmd += `,_SERVICE_ACCOUNT=${SERVICE_ACCOUNT}`;
if (SAMPLE_VERSION) buildCmd += `,_VERSION=${SAMPLE_VERSION}`;
if (DB_USER) buildCmd += `,_DB_USER=${DB_USER}`;
if (DB_NAME) buildCmd += `,_DB_NAME=${DB_NAME}`;

console.log('Starting Cloud Build...');
execSync(buildCmd, {timeout: 240000, shell: true}); // timeout at 4 mins
Expand Down Expand Up @@ -100,18 +109,20 @@
);

const tokens = JSON.parse(response.body);
ID_TOKEN = tokens.idToken;
if (!ID_TOKEN) throw Error('Unable to acquire an ID token.');
CUSTOM_TOKEN = tokens.idToken;
if (!CUSTOM_TOKEN) throw Error('Unable to acquire an IDP token.');
});

after(() => {
let cleanUpCmd =
`gcloud builds submit --project ${GOOGLE_CLOUD_PROJECT} ` +
'--config ./test/e2e_test_cleanup.yaml ' +
`--substitutions _SERVICE=${SERVICE_NAME},_PLATFORM=${PLATFORM},_REGION=${REGION}`;
`--substitutions _SERVICE=${SERVICE_NAME},_REGION=${REGION}`;
if (SAMPLE_VERSION) cleanUpCmd += `,_VERSION=${SAMPLE_VERSION}`;
if (SERVICE_ACCOUNT) cleanUpCmd += `,_SERVICE_ACCOUNT=${SERVICE_ACCOUNT}`;

Check failure on line 122 in run/idp-sql/test/system.test.js

View workflow job for this annotation

GitHub Actions / lint

'cleanUpCmd' is assigned a value but never used

execSync(cleanUpCmd, {shell: true});
//TODO(glasnt): re-enable cleanup
//execSync(cleanUpCmd, {shell: true});
});

it('Can successfully make a request', async () => {
Expand All @@ -128,14 +139,14 @@
});

it('Can make a POST request with token', async () => {
assert(ID_TOKEN && ID_TOKEN.length > 0);
assert(CUSTOM_TOKEN && CUSTOM_TOKEN.length > 0);

const options = {
prefixUrl: BASE_URL.trim(),
method: 'POST',
form: {team: 'DOGS'},
headers: {
Authorization: `Bearer ${ID_TOKEN.trim()}`,
Authorization: `Bearer ${CUSTOM_TOKEN.trim()}`

Check failure on line 149 in run/idp-sql/test/system.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
retry: {
limit: 5,
Expand All @@ -160,7 +171,7 @@
method: 'POST',
form: {team: 'DOGS'},
headers: {
Authorization: 'Bearer iam-a-token',
Authorization: 'Bearer iam-a-token'

Check failure on line 174 in run/idp-sql/test/system.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},
retry: {
limit: 5,
Expand Down
Loading