-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adnan Rahic
committed
Jun 25, 2021
1 parent
082f3ba
commit 3c11a81
Showing
3 changed files
with
69 additions
and
9 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
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,47 @@ | ||
/* global describe, it */ | ||
const assert = require('assert') | ||
const crypto = require('crypto') | ||
const sampleClientSecret = 'idmnMEd7Yx4QmgzZpZ4axXoe' | ||
const sampleBody = { | ||
id: 1, | ||
message: '1' | ||
} | ||
const sampleBodyBuf = Buffer.from(JSON.stringify(sampleBody)) | ||
const sampleSignature = crypto | ||
.createHmac('sha1', sampleClientSecret) | ||
.update(sampleBodyBuf) | ||
.digest('hex') | ||
|
||
const sampleReq = { | ||
headers: { | ||
'x-zeit-signature': sampleSignature | ||
} | ||
} | ||
const configWithArrayWithTwoClientSecrets = { | ||
clientSecrets: [sampleClientSecret, sampleClientSecret] | ||
} | ||
const configWithArrayWithOneClientSecret = { | ||
clientSecrets: [sampleClientSecret] | ||
} | ||
const EventEmitter = require('events') | ||
const evem = new EventEmitter() | ||
|
||
/** | ||
* Init Vercel Class | ||
*/ | ||
const Vercel = require('../../lib/plugins/input/vercel') | ||
const vercelWithArrayWithTwoSecrets = new Vercel(configWithArrayWithTwoClientSecrets, evem) | ||
const vercelWithArrayWithOneSecret = new Vercel(configWithArrayWithOneClientSecret, evem) | ||
|
||
describe('verifySignature should', function () { | ||
it('return true for an array with 2 secrets', function (done) { | ||
const signature = vercelWithArrayWithTwoSecrets.verifySignature(sampleReq, sampleBodyBuf) | ||
assert.strictEqual(signature, true) | ||
done() | ||
}) | ||
it('return true for an array with 1 secret', function (done) { | ||
const signature = vercelWithArrayWithOneSecret.verifySignature(sampleReq, sampleBodyBuf) | ||
assert.strictEqual(signature, true) | ||
done() | ||
}) | ||
}) |