Skip to content

Commit 3f8697b

Browse files
authored
Merge pull request #187 from web-push-libs/gcm_api_key_sanity_checks
Add basic sanity checks for the GCM API key.
2 parents 292b68a + cf1d41a commit 3f8697b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ require('util').inherits(WebPushError, Error);
9292
var gcmAPIKey = '';
9393

9494
function setGCMAPIKey(apiKey) {
95+
if (!apiKey || typeof apiKey !== 'string') {
96+
throw new Error('The GCM API Key should be a non-emtpy string.');
97+
}
98+
9599
gcmAPIKey = apiKey;
96100
}
97101

test/testSetGCMAPIKey.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ suite('setGCMAPIKey', function() {
66
assert(webPush.setGCMAPIKey);
77
});
88

9-
test('call', function() {
10-
webPush.setGCMAPIKey('hello');
11-
})
9+
test('non-empty string', function() {
10+
assert.doesNotThrow(function() { webPush.setGCMAPIKey('AIzaSyAwmdX6KKd4hPfIcGU2SOfj9vuRDW6u-wo') });
11+
});
12+
13+
test('empty string', function() {
14+
assert.throws(function() { webPush.setGCMAPIKey('') }, Error);
15+
});
16+
17+
test('non string', function() {
18+
assert.throws(function() { webPush.setGCMAPIKey(42) }, Error);
19+
});
1220
});

0 commit comments

Comments
 (0)