Closed jamesjwarren closed 8 years ago
cool stuff :+1:
@edwardoparearyee added tests for the HMAC policy and integration test for the /api/events
endpoint
tests are failing for me for some reason:
➜ FM-Frontend-API git:(feature/events-endpoint) npm test
> FM-Frontend-API@0.0.0 test /Users/ed/Documents/Projects/thisissoon/FM-Frontend-API
> grunt test
Running "jshint:dev" (jshint) task
>> 32 files lint free.
Running "mocha_istanbul:all" (mocha_istanbul) task
Events
1) "before all" hook
POST /api/events
Tracks
GET /api/tracks
✓ should return an array (50ms)
✓ should return an array (47ms)
2) should handle play event
Policy: HMAC
3) should return error for invalid event
4) should return bad request for unrecognised client
5) should return bad request for unrecognised client
6) should return bad request for invalid signature
7) should call next middleware if verification passes
8) should call next middleware if verification passes
2 passing (2s)
8 failing
1) "before all" hook:
Uncaught Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Server._listen2 (net.js:1146:14)
at listen (net.js:1172:10)
at Server.listen (net.js:1257:5)
at Array.async.auto.start (node_modules/sails/lib/hooks/http/start.js:29:35)
at node_modules/sails/node_modules/async/lib/async.js:484:38
at _each (node_modules/sails/node_modules/async/lib/async.js:46:13)
at Object.async.auto (node_modules/sails/node_modules/async/lib/async.js:455:9)
at Sails.startServer (node_modules/sails/lib/hooks/http/start.js:16:11)
at Sails.emitter.emit (node_modules/sails/lib/app/private/after.js:50:11)
at afterBootstrap (node_modules/sails/lib/app/private/initialize.js:56:11)
at bootstrapDone (node_modules/sails/lib/app/private/bootstrap.js:51:14)
at Object.module.exports.bootstrap (config/bootstrap.js:18:3)
at Sails.runBootstrap (node_modules/sails/lib/app/private/bootstrap.js:44:25)
at Sails.bound [as runBootstrap] (node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
at Sails.initialize (node_modules/sails/lib/app/private/initialize.js:48:9)
at bound (node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
at node_modules/sails/node_modules/async/lib/async.js:607:21
at node_modules/sails/node_modules/async/lib/async.js:246:17
at iterate (node_modules/sails/node_modules/async/lib/async.js:146:13)
at node_modules/sails/node_modules/async/lib/async.js:157:25
at node_modules/sails/node_modules/async/lib/async.js:248:21
at node_modules/sails/node_modules/async/lib/async.js:612:34
at node_modules/sails/lib/app/load.js:201:13
at node_modules/sails/node_modules/async/lib/async.js:451:17
at node_modules/sails/node_modules/async/lib/async.js:441:17
at _each (node_modules/sails/node_modules/async/lib/async.js:46:13)
at Immediate.taskComplete (node_modules/sails/node_modules/async/lib/async.js:440:13)
2) Events POST /api/events should handle play event:
TypeError: Cannot set property '_event' of undefined
at Context.<anonymous> (tests/integration/events.js:44:24)
3) Events POST /api/events should return error for invalid event:
TypeError: Cannot set property '_event' of undefined
at Context.<anonymous> (tests/integration/events.js:66:24)
4) Policy: HMAC should return bad request for unrecognised client:
TypeError: Cannot read property 'headers' of undefined
at Context.<anonymous> (tests/unit/policies/hmac.js:41:8)
5) Policy: HMAC should return bad request for unrecognised client:
TypeError: Cannot read property 'headers' of undefined
at Context.<anonymous> (tests/unit/policies/hmac.js:41:8)
6) Events POST /api/events should return bad request for invalid signature:
TypeError: Cannot read property 'toString' of undefined
at Context.<anonymous> (tests/integration/events.js:82:82)
7) Policy: HMAC should call next middleware if verification passes:
TypeError: Cannot read property 'headers' of undefined
at module.exports (api/policies/hmac.js:9:365)
at Context.<anonymous> (tests/unit/policies/hmac.js:53:5)
8) Policy: HMAC should call next middleware if verification passes:
TypeError: Cannot read property 'headers' of undefined
at module.exports (api/policies/hmac.js:9:365)
at Context.<anonymous> (tests/unit/policies/hmac.js:53:5)
actually my mistake, was running another instance of sails at the same time
LGTM :+1:
Ahh yes, the test server runs on the same port. I guess it would be useful to have it run on a different port to avoid those circumstances. I'll change that in the test environment.
This PR provides an initial endpoint to handle incoming events from Perceptor.
POST /api/events
Accepts JSON data formatted as per the Async Spec.
Includes HMAC verification, the client secret key would need to be set here.
This supersedes the
EventService
which currently receives events from Redis.