This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
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
1 parent
c1cc40a
commit 2d67a3e
Showing
4 changed files
with
88 additions
and
3 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,41 @@ | ||
var expect = require('chai').expect; | ||
var LambdaTester = require( 'lambda-tester' ); | ||
var registerLambda = require( '../src/registerWebhook' ); | ||
var verifyLambda = require( './verifyWebhook' ); | ||
|
||
var data = { | ||
"config": { | ||
"url" : "https://9yui64kvxi.execute-api.us-east-1.amazonaws.com/cd/test-post-lambda", | ||
"content_type" : "json", | ||
"secret" : process.env.SECRET_KEY | ||
}, | ||
|
||
"events": [ "node-change/mac:14cfe2142142/.*","SYNC_NOTIFICATION","transaction-status", "device-status" ] | ||
}; | ||
|
||
describe( 'Webhook Unit Testing', function() { | ||
this.timeout(5000); | ||
|
||
it( 'Registered', function() { | ||
|
||
return LambdaTester( registerLambda.handler ) | ||
.event( { } ) | ||
.expectResult(function( result ) | ||
{ | ||
result = JSON.parse(result); | ||
expect(result.message).to.equal('Success'); | ||
|
||
}); | ||
}); | ||
|
||
it('Verified', function(){ | ||
|
||
return LambdaTester( verifyLambda.handler ) | ||
.event( data ) | ||
.expectResult(function( result ) | ||
{ | ||
expect(result).to.equal(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,42 @@ | ||
var https = require('https'); | ||
|
||
var options = { | ||
host: 'api-cd.webpa.comcast.net', | ||
port: 8090, | ||
path: '/api/v2/hooks', | ||
method: 'GET', | ||
headers: { | ||
'content-type': 'application/json', | ||
'Authorization': 'Basic '+process.env.WEBPA_AUTH_HEADER | ||
} | ||
}; | ||
|
||
exports.handler = (event, context, callback) => { | ||
const req = https.request(options, (res) => { | ||
var body = ''; | ||
console.log('Status:', res.statusCode); | ||
res.setEncoding('utf8'); | ||
res.on('data', (chunk) => body += chunk); | ||
res.on('end', () => { | ||
console.log('Successfully processed HTTPS response'); | ||
if (res.headers['content-type'] === 'application/json') { | ||
body = JSON.parse(body); | ||
for(var i=0; i<body.length; i++) | ||
{ | ||
if(JSON.stringify(body[i].config) === JSON.stringify(event.config)) | ||
{ | ||
if(JSON.stringify(body[i].events) === JSON.stringify(event.events)) | ||
{ | ||
callback(null, true); | ||
break; | ||
} | ||
callback(new Error(false)); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
req.on('error', callback); | ||
req.end(); | ||
}; |