diff --git a/.kokoro/continuous/node14/system-test.cfg b/.kokoro/continuous/node14/system-test.cfg index 9ba9ad1c7..c7c9507a8 100644 --- a/.kokoro/continuous/node14/system-test.cfg +++ b/.kokoro/continuous/node14/system-test.cfg @@ -8,5 +8,5 @@ env_vars: { env_vars: { key: "SECRET_MANAGER_KEYS" - value: "long-door-651-kokoro-system-test-service-account" + value: "long-door-651-kokoro-system-test-service-account,client-library-test-universe-domain-credential" } \ No newline at end of file diff --git a/.kokoro/presubmit/node14/system-test.cfg b/.kokoro/presubmit/node14/system-test.cfg index 9ba9ad1c7..c7c9507a8 100644 --- a/.kokoro/presubmit/node14/system-test.cfg +++ b/.kokoro/presubmit/node14/system-test.cfg @@ -8,5 +8,5 @@ env_vars: { env_vars: { key: "SECRET_MANAGER_KEYS" - value: "long-door-651-kokoro-system-test-service-account" + value: "long-door-651-kokoro-system-test-service-account,client-library-test-universe-domain-credential" } \ No newline at end of file diff --git a/.kokoro/release/publish.cfg b/.kokoro/release/publish.cfg index baea5db3c..019cc24a5 100644 --- a/.kokoro/release/publish.cfg +++ b/.kokoro/release/publish.cfg @@ -18,7 +18,7 @@ before_action { env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,client-library-test-universe-domain-credential" } # Download trampoline resources. diff --git a/.kokoro/system-test.sh b/.kokoro/system-test.sh index 0b3043d26..e219954ae 100755 --- a/.kokoro/system-test.sh +++ b/.kokoro/system-test.sh @@ -22,6 +22,12 @@ export NPM_CONFIG_PREFIX=${HOME}/.npm-global export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secret_manager/long-door-651-kokoro-system-test-service-account export GCLOUD_PROJECT=long-door-651 +# For universe domain testing +export TEST_UNIVERSE_DOMAIN_CREDENTIAL=${KOKORO_GFILE_DIR}/secret_manager/client-library-test-universe-domain-credential +export TEST_UNIVERSE_DOMAIN=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-domain) +export TEST_UNIVERSE_PROJECT_ID=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-project-id) +export TEST_UNIVERSE_LOCATION=$(gcloud secrets versions access latest --project cloud-devrel-kokoro-resources --secret=client-library-test-universe-storage-location) + cd $(dirname $0)/.. # Run a pre-test hook, if a pre-system-test.sh is in the project diff --git a/system-test/storage.ts b/system-test/storage.ts index f192a614c..4b004c830 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -3866,6 +3866,68 @@ describe('storage', function () { }); }); + describe('universeDomainTests', () => { + let universeDomainStorage: Storage; + const bucketName = generateName(); + const localFile = fs.readFileSync(FILES.logo.path); + let file: File; + + before(async () => { + const TEST_UNIVERSE_DOMAIN = isNullOrUndefined('TEST_UNIVERSE_DOMAIN'); + const TEST_PROJECT_ID = isNullOrUndefined('TEST_UNIVERSE_PROJECT_ID'); + const TEST_UNIVERSE_LOCATION = isNullOrUndefined( + 'TEST_UNIVERSE_LOCATION' + ); + const CREDENTIAL_PATH = isNullOrUndefined( + 'TEST_UNIVERSE_DOMAIN_CREDENTIAL' + ); + // Create a client with universe domain credentials + universeDomainStorage = new Storage({ + projectId: TEST_PROJECT_ID, + keyFilename: CREDENTIAL_PATH, + universeDomain: TEST_UNIVERSE_DOMAIN, + }); + + const [bucket] = await universeDomainStorage.createBucket(bucketName, { + location: TEST_UNIVERSE_LOCATION, + }); + + file = bucket.file('LogoToSign.jpg'); + fs.createReadStream(FILES.logo.path).pipe(file.createWriteStream()); + }); + + after(async () => { + await deleteFileAsync(file); + await deleteBucketAsync(bucket); + }); + + it('should get bucket', async () => { + const [buckets] = await universeDomainStorage.getBuckets(); + const getBucket = buckets.filter(item => item.name === bucketName); + assert.strictEqual(getBucket[0].name, bucketName); + }); + + it('should get files', async () => { + const fileName = await universeDomainStorage + .bucket(bucketName) + .file(file.name).name; + assert.strictEqual(fileName, file.name); + }); + + it('should create a signed read url', async () => { + const [signedReadUrl] = await file.getSignedUrl({ + version: 'v2', + action: 'read', + expires: Date.now() + 5000, + virtualHostedStyle: true, + }); + + const res = await fetch(signedReadUrl); + const body = await res.text(); + assert.strictEqual(body, localFile.toString()); + }); + }); + async function deleteBucketAsync(bucket: Bucket, options?: {}) { // After files are deleted, eventual consistency may require a bit of a // delay to ensure that the bucket recognizes that the files don't exist @@ -4015,4 +4077,12 @@ describe('storage', function () { function createFileWithContentPromise(content: string) { return bucket.file(`${generateName()}.txt`).save(content); } + + function isNullOrUndefined(envVarName: string) { + const value = process.env[envVarName]; + if (value === undefined || value === null) { + throw new Error(`Please set the ${envVarName} environment variable.`); + } + return value; + } });