Skip to content

Commit

Permalink
check API key validity messages in system-test
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed Sep 14, 2017
1 parent 689a233 commit 80b5dd0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/error-reporting/src/google-apis/auth-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class RequestHandler extends common.Service {
method: 'POST',
json: {}
}, (err, body, response) => {
if (err && err.message !== 'Message cannot be empty.') {
if (err && err.message !== 'Message cannot be empty.' &&
response.statusCode === 400) {
this._logger.error([
'Encountered an error while attempting to validate the provided',
'API key'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var forEach = require('lodash.foreach');
var assign = require('lodash.assign');
var pick = require('lodash.pick');
var omitBy = require('lodash.omitby');
var request = require('request');
var util = require('util');
var path = require('path');

Expand Down Expand Up @@ -362,6 +363,52 @@ describe('Expected Behavior', function() {
});
});

describe('Error Reporting API', function() {
const API = 'https://clouderrorreporting.googleapis.com/v1beta1';

function getMessageForApiKey(key, cb) {
request.post({
url: `${API}/projects/${env.projectId}/events:report?key=${key}`,
json: {},
}, (err, response, body) => {
assert.ok(!err && body.error);
cb(body.error.message);
});
}

[
{
name: 'when a valid API key is given',
getKey: () => env.apiKey,
message: 'Message cannot be empty.'
},
{
name: 'when an empty API key is given',
getKey: () => '',
message: 'The request is missing a valid API key.'
},
{
name: 'when an invalid API key is given',
getKey: () => env.apiKey.slice(1) + env.apiKey[0],
message: 'API key not valid. Please pass a valid API key.'
}
].forEach(function(testCase) {
it(`should return an expected message ${testCase.name}`, function(done) {
this.timeout(30000);
const key = testCase.getKey();
request.post({
url: `${API}/projects/${env.projectId}/events:report?key=${key}`,
json: {},
}, (err, response, body) => {
assert.ok(!err && body.error);
assert.strictEqual(response.statusCode, 400);
assert.strictEqual(body.error.message, testCase.message);
done();
});
});
});
});

describe('error-reporting', function() {
const SRC_ROOT = path.join(__dirname, '..', 'src');
const TIMESTAMP = Date.now();
Expand Down

0 comments on commit 80b5dd0

Please sign in to comment.