-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improve samples and add tests (#576)
- Loading branch information
1 parent
16b776f
commit 7c498a1
Showing
14 changed files
with
175 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
rules: | ||
no-console: off | ||
node/no-missing-require: off | ||
node/no-unpublished-require: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
{ | ||
"name": "google-auth-library-samples", | ||
"description": "A set of samples for the google-auth-library npm module.", | ||
"files": [ | ||
"*.js" | ||
], | ||
"scripts": { | ||
"test": "mocha system-test" | ||
"test": "mocha --timeout 60000" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"google-auth-library": "^2.0.2", | ||
"node-fetch": "^2.3.0", | ||
"opn": "^5.3.0", | ||
"server-destroy": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"execa": "^1.0.0", | ||
"mocha": "^5.2.0" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
env: | ||
mocha: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright 2018 Google LLC. All Rights Reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
const execa = require('execa'); | ||
const {assert} = require('chai'); | ||
const fs = require('fs'); | ||
const {promisify} = require('util'); | ||
|
||
const readFile = promisify(fs.readFile); | ||
|
||
const exec = async cmd => { | ||
const res = await execa.shell(cmd); | ||
assert.isEmpty(res.stderr); | ||
return res.stdout; | ||
}; | ||
|
||
const keyFile = process.env.GOOGLE_APPLICATION_CREDENTIALS; | ||
|
||
describe('samples', () => { | ||
it('should acquire application default credentials', async () => { | ||
const output = await exec('node adc'); | ||
assert.match(output, /DNS Info:/); | ||
}); | ||
|
||
it.skip('should acquire compute credentials', async () => { | ||
// TODO: need to figure out deploying to GCF for this to work | ||
const output = await exec('node compute'); | ||
assert.match(output, /DNS Info:/); | ||
}); | ||
|
||
it('should create a JWT', async () => { | ||
const output = await exec('node jwt'); | ||
assert.match(output, /DNS Info:/); | ||
}); | ||
|
||
it('should read from a keyfile', async () => { | ||
const output = await exec('node keyfile'); | ||
assert.match(output, /DNS Info:/); | ||
}); | ||
|
||
it('should allow directly passing creds', async () => { | ||
const keys = JSON.parse(await readFile(keyFile, 'utf8')); | ||
const res = await execa('node', ['credentials'], { | ||
env: { | ||
CLIENT_EMAIL: keys.client_email, | ||
PRIVATE_KEY: keys.private_key, | ||
}, | ||
}); | ||
assert.isEmpty(res.stderr); | ||
assert.match(res.stdout, /DNS Info:/); | ||
}); | ||
|
||
it('should obtain headers for a request', async () => { | ||
const output = await exec('node headers'); | ||
assert.match(output, /Headers:/); | ||
assert.match(output, /DNS Info:/); | ||
}); | ||
}); |
Oops, something went wrong.