Skip to content

Commit

Permalink
add interface detection to REQUEST parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Dec 22, 2018
1 parent cdea6c9 commit 60ca34a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class REQUEST {
|| (this.requestContext['identity'] && this.requestContext['identity']['sourceIp']
&& this.requestContext['identity']['sourceIp'].split(',')[0].trim())

// Assign the requesting interface
this.interface = this.requestContext.elb ? 'alb' : 'apigateway'

// Set the pathParameters
this.pathParameters = this.app._event.pathParameters || {}

Expand Down
3 changes: 3 additions & 0 deletions test/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Request Tests:', function() {
expect(result.headers).to.deep.equal({ 'content-type': 'application/json' })
expect(body).to.have.property('request')
expect(body.request.id).is.not.null
expect(body.request.interface).to.equal('apigateway')
expect(body.request.userAgent).to.equal('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48')
expect(body.request).to.have.property('requestContext')
expect(body.request.ip).to.equal('192.168.100.1')
Expand All @@ -56,6 +57,7 @@ describe('Request Tests:', function() {
expect(result.headers).to.deep.equal({ 'content-type': 'application/json' })
expect(body).to.have.property('request')
expect(body.request.id).is.not.null
expect(body.request.interface).to.equal('apigateway')
expect(body.request.userAgent).to.equal('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48')
expect(body.request).to.have.property('requestContext')
expect(body.request.ip).to.equal('192.168.100.12')
Expand Down Expand Up @@ -83,6 +85,7 @@ describe('Request Tests:', function() {
expect(result.headers).to.deep.equal({ 'content-type': 'application/json' })
expect(body).to.have.property('request')
expect(body.request.id).is.not.null
expect(body.request.interface).to.equal('alb')
expect(body.request.userAgent).to.equal('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48')
expect(body.request).to.have.property('requestContext')
expect(body.request.ip).to.equal('192.168.100.1')
Expand Down

0 comments on commit 60ca34a

Please sign in to comment.