Skip to content
Open
9 changes: 1 addition & 8 deletions functions/composer-storage-trigger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ exports.triggerDag = async data => {
try {
const iap = await authorizeIap(CLIENT_ID, PROJECT_ID, USER_AGENT);

return makeIapPostRequest(
WEBSERVER_URL,
BODY,
iap.idToken,
USER_AGENT,
iap.jwt
);
return makeIapPostRequest(WEBSERVER_URL, BODY, iap.idToken, USER_AGENT);
} catch (err) {
console.error('Error authorizing IAP:', err.message);
throw new Error(err);
Expand Down Expand Up @@ -142,7 +136,6 @@ const authorizeIap = async (clientId, projectId, userAgent) => {
}

return {
jwt: jwt,
idToken: tokenJson.id_token,
};
};
Expand Down
2 changes: 1 addition & 1 deletion functions/spanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test": "mocha test/*.test.js --timeout=20000"
},
"dependencies": {
"@google-cloud/spanner": "^3.1.0"
"@google-cloud/spanner": "^4.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.3.0",
Expand Down
123 changes: 0 additions & 123 deletions functions/tokenservice/functions/.eslintrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions functions/tokenservice/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"test": "mocha test/*.test.js --timeout=5000",
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"local-test": "mocha test/index.test.js",
"test": "npm run local-test",
"start": "functions-framework --target=getOAuthToken"
},
"dependencies": {
"child-process-promise": "^2.2.1",
"firebase-admin": "^8.0.0",
"firebase-functions": "^3.0.0",
"request": "^2.88.0",
Expand All @@ -22,6 +21,7 @@
"@google-cloud/functions-framework": "^1.1.1",
"@google-cloud/nodejs-repo-tools": "^3.3.0",
"babel-eslint": "^10.0.2",
"child-process-promise": "^2.2.1",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-node": "^9.1.0",
Expand All @@ -32,7 +32,7 @@
"supertest": "^4.0.0"
},
"engines": {
"node": "8"
"node": ">=8.0.0"
},
"private": true
}
55 changes: 34 additions & 21 deletions functions/tokenservice/functions/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
/**
* Copyright 2019, 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.
*/

/* eslint-env node, mocha */

const assert = require('assert');
const index = require('../index.js');
const execPromise = require('child-process-promise').exec;
const path = require('path');
const cwd = path.join(__dirname, '..');
const BASE_URL = process.env.BASE_URL || 'http://localhost:8080';
const FF_TIMEOUT = 3000;
const PORT = 8080;
let requestRetry = require('requestretry');

// let requestRetryForCredentials = require('requestretry');

const defaults = {
uri: `${BASE_URL}/getOAuthToken`,
maxAttempts: 1,
fullResponse: true,
};

requestRetry = requestRetry.defaults({
retryDelay: 500,
retryStrategy: requestRetry.RetryStrategies.NetworkError,
method: 'GET',
json: true,
Expand All @@ -33,30 +43,34 @@ const contextValue = (uid = 'test-uid', email_verified = true) => ({
},
});

const handleLinuxFailures = async proc => {
try {
return await proc;
} catch (err) {
// Timeouts always cause errors on Linux, so catch them
// Don't return proc, as await-ing it re-throws the error
if (!err.name || err.name !== 'ChildProcessError') {
throw err;
}
}
};

describe('getOAuthToken tests', () => {
let ffProc;
before(() => {
ffProc = execPromise(
`functions-framework --target=getOAuthToken --signature-type=http`,
`functions-framework --target=getOAuthToken --signature-type=http --port=${PORT}`,
{timeout: FF_TIMEOUT, shell: true, cwd}
);
});

after(async () => {
try {
await ffProc;
} catch (err) {
// Timeouts always cause errors on Linux, so catch them
if (err.name && err.name === 'ChildProcessError') {
return;
}
throw err;
}
await handleLinuxFailures(ffProc);
});

describe('Firebase OAuth Token', () => {
// no argument 400 error
it('should give 400 if no Context is provided', async () => {
//new requestRetry(defaults, (error, response, body) => done())
const response = await requestRetry({
body: {
deviceID: '',
Expand All @@ -68,7 +82,6 @@ describe('getOAuthToken tests', () => {
});

it('should give 400 if no deviceID is provided', async () => {
//new requestRetry(defaults, (error, response, body) => done())
const response = await requestRetry({
contextValue,
});
Expand Down