Skip to content

Commit 83ac430

Browse files
committed
tests: refactor system tests
1 parent 8430bb2 commit 83ac430

6 files changed

Lines changed: 34 additions & 25 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,3 @@ pylintrc.test
6565

6666
# Ruff cache
6767
.ruff_cache
68-
69-
# google-auth system test credentials
70-
system_tests/data

.kokoro/system.sh

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,18 @@ run_package_test() {
5555
GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/google-auth-service-account.json"
5656
NOX_FILE="system_tests/noxfile.py"
5757
NOX_SESSION=""
58-
59-
# Activate gcloud for this specific package
60-
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
61-
gcloud config set project "$PROJECT_ID"
62-
63-
# Decrypt secrets
64-
gcloud kms decrypt \
65-
--location=global --keyring=ci --key=kokoro-secrets \
66-
--ciphertext-file="${package_path}/system_tests/secrets.tar.enc" \
67-
--plaintext-file="${package_path}/system_tests/secrets.tar"
68-
mkdir -p "${package_path}/system_tests/data"
69-
# Extract from the package root.
70-
# The tar already contains the 'system_tests/data/' path.
71-
tar xvf "${package_path}/system_tests/secrets.tar" -C "${package_path}/"
72-
73-
rm "${package_path}/system_tests/secrets.tar"
7458
;;
7559
*)
7660
PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
7761
GOOGLE_APPLICATION_CREDENTIALS="${KOKORO_GFILE_DIR}/service-account.json"
7862
NOX_FILE="noxfile.py"
7963
NOX_SESSION="system-3.12"
80-
81-
# Activate gcloud for this specific package
82-
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
83-
gcloud config set project "$PROJECT_ID"
8464
;;
8565
esac
8666

67+
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
68+
gcloud config set project "$PROJECT_ID"
69+
8770
# Export variables for the duration of this function's sub-processes
8871
export PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS NOX_FILE NOX_SESSION
8972

packages/google-auth/noxfile.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import pathlib
1717
import shutil
18+
import subprocess
1819

1920
import nox
2021

@@ -57,6 +58,36 @@
5758
]
5859

5960

61+
def _provision_kokoro_secrets():
62+
"""Downloads CI secrets directly from GCS and formats them for the tests."""
63+
if not os.environ.get("KOKORO_GFILE_DIR"):
64+
return
65+
66+
dest_dir = pathlib.Path(__file__).parent / "data"
67+
dest_dir.mkdir(parents=True, exist_ok=True)
68+
69+
# Map GCS filenames to the local filenames expected by tests
70+
secrets_map = {
71+
"google-auth-service-account.json": "service_account.json",
72+
"google-auth-authorized-user.json": "authorized_user.json",
73+
"google-auth-impersonated-service-account.json": "impersonated_service_account.json",
74+
}
75+
76+
gcs_base = "gs://cloud-devrel-kokoro-resources/google-cloud-python"
77+
78+
for src_name, dest_name in secrets_map.items():
79+
subprocess.run(
80+
["google", "storage", "cp", f"{gcs_base}/{src_name}", str(dest_dir)],
81+
check=True,
82+
capture_output=True,
83+
)
84+
# Rename to use underscores as per test conventions
85+
(dest_dir / src_name).replace(dest_dir / dest_name)
86+
87+
88+
_provision_kokoro_secrets()
89+
90+
6091
@nox.session(python=DEFAULT_PYTHON_VERSION)
6192
def lint(session):
6293
session.install(
-10.1 KB
Binary file not shown.

packages/google-auth/system_tests/system_tests_sync/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)