-
Notifications
You must be signed in to change notification settings - Fork 76
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
Showing
23 changed files
with
1,747 additions
and
13 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
64 changes: 64 additions & 0 deletions
64
__tests__/integration/sns/custom-mapping-template/service/serverless.yml
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,64 @@ | ||
service: sns-proxy | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs10.x | ||
stage: ${opt:stage, 'dev'} | ||
|
||
plugins: | ||
localPath: './../../../../../../' | ||
modules: | ||
- serverless-apigateway-service-proxy | ||
|
||
custom: | ||
apiGatewayServiceProxies: | ||
- sns: | ||
path: /sns | ||
method: post | ||
topicName: { 'Fn::GetAtt': ['SNSTopic', 'TopicName'] } | ||
cors: true | ||
request: | ||
template: | ||
application/json: | ||
'Fn::Join': | ||
- '' | ||
- - "Action=Publish&Message=$util.urlEncode('This is a fixed message')&TopicArn=$util.urlEncode('" | ||
- { Ref: SNSTopic } | ||
- "')" | ||
|
||
resources: | ||
Resources: | ||
SNSTopic: | ||
Type: AWS::SNS::Topic | ||
Properties: | ||
Subscription: | ||
- Endpoint: { 'Fn::GetAtt': ['SqsQueue', 'Arn'] } | ||
Protocol: sqs | ||
|
||
SqsQueue: | ||
Type: AWS::SQS::Queue | ||
|
||
SqsQueuePolicy: | ||
Type: AWS::SQS::QueuePolicy | ||
Properties: | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Id: SqsQueuePolicy | ||
Statement: | ||
- Sid: Allow-SendMessage-To-Queue-From-SNS-Topic | ||
Effect: Allow | ||
Principal: "*" | ||
Action: | ||
- sqs:SendMessage | ||
Resource: "*" | ||
Condition: | ||
ArnEquals: | ||
aws:SourceArn: | ||
Ref: SNSTopic | ||
|
||
Queues: | ||
- Ref: SqsQueue | ||
|
||
Outputs: | ||
SqsQueueUrl: | ||
Value: { Ref: SqsQueue } |
61 changes: 61 additions & 0 deletions
61
__tests__/integration/sns/custom-mapping-template/tests.js
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,61 @@ | ||
'use strict' | ||
|
||
const { default: awsTesting } = require('aws-testing-library/lib/chai') | ||
const chai = require('chai') | ||
chai.use(awsTesting) | ||
const { expect } = chai | ||
|
||
const fetch = require('node-fetch') | ||
const { deployWithRandomStage, removeService } = require('../../../utils') | ||
|
||
describe('Single SNS Proxy Integration Test', () => { | ||
let endpoint | ||
let stage | ||
let region | ||
let queueUrl | ||
const config = '__tests__/integration/sns/custom-mapping-template/service/serverless.yml' | ||
|
||
beforeAll(async () => { | ||
;({ | ||
stage, | ||
region, | ||
endpoint, | ||
outputs: { SqsQueueUrl: queueUrl } | ||
} = await deployWithRandomStage(config)) | ||
}) | ||
|
||
afterAll(() => { | ||
removeService(stage, config) | ||
}) | ||
|
||
it('should get correct response from sqs proxy endpoint', async () => { | ||
const testEndpoint = `${endpoint}/sns` | ||
|
||
const response = await fetch(testEndpoint, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
|
||
expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*') | ||
expect(response.status).to.be.equal(200) | ||
const json = await response.json() | ||
|
||
expect(json).to.have.own.property('PublishResponse') | ||
|
||
expect(json.PublishResponse).to.have.own.property('PublishResult') | ||
expect(json.PublishResponse).to.have.own.property('ResponseMetadata') | ||
|
||
expect(json.PublishResponse.PublishResult).to.have.own.property('MessageId') | ||
expect(json.PublishResponse.PublishResult).to.have.own.property('SequenceNumber') | ||
|
||
expect(json.PublishResponse.ResponseMetadata).to.have.own.property('RequestId') | ||
|
||
const expectedFixedMessage = 'This is a fixed message' | ||
await expect({ | ||
region, | ||
queueUrl, | ||
timeout: 10000, | ||
pollEvery: 2500 | ||
}).to.have.message((message) => message.Message === expectedFixedMessage) | ||
}) | ||
}) |
103 changes: 103 additions & 0 deletions
103
__tests__/integration/sns/multiple-integrations/service/serverless.yml
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,103 @@ | ||
service: multiple-sns-proxy | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs10.x | ||
|
||
plugins: | ||
localPath: './../../../../../../' | ||
modules: | ||
- serverless-apigateway-service-proxy | ||
|
||
custom: | ||
apiGatewayServiceProxies: | ||
- sns: | ||
path: /sns1 | ||
method: post | ||
topicName: { 'Fn::GetAtt': ['SNSTopic1', 'TopicName'] } | ||
cors: true | ||
|
||
- sns: | ||
path: /sns2 | ||
method: post | ||
topicName: { 'Fn::GetAtt': ['SNSTopic2', 'TopicName'] } | ||
cors: true | ||
|
||
- sns: | ||
path: /sns3 | ||
method: post | ||
topicName: { 'Fn::GetAtt': ['SNSTopic3', 'TopicName'] } | ||
cors: true | ||
|
||
resources: | ||
Resources: | ||
SNSTopic1: | ||
Type: AWS::SNS::Topic | ||
Properties: | ||
Subscription: | ||
- Endpoint: { 'Fn::GetAtt': ['SqsQueue', 'Arn'] } | ||
Protocol: sqs | ||
|
||
SNSTopic2: | ||
Type: AWS::SNS::Topic | ||
Properties: | ||
Subscription: | ||
- Endpoint: { 'Fn::GetAtt': ['SqsQueue', 'Arn'] } | ||
Protocol: sqs | ||
|
||
SNSTopic3: | ||
Type: AWS::SNS::Topic | ||
Properties: | ||
Subscription: | ||
- Endpoint: { 'Fn::GetAtt': ['SqsQueue', 'Arn'] } | ||
Protocol: sqs | ||
|
||
SqsQueue: | ||
Type: AWS::SQS::Queue | ||
|
||
SqsQueuePolicy: | ||
Type: AWS::SQS::QueuePolicy | ||
Properties: | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Id: SqsQueuePolicy | ||
Statement: | ||
- Sid: Allow-SendMessage-To-Queue-From-SNS-Topic1 | ||
Effect: Allow | ||
Principal: "*" | ||
Action: | ||
- sqs:SendMessage | ||
Resource: "*" | ||
Condition: | ||
ArnEquals: | ||
aws:SourceArn: | ||
Ref: SNSTopic1 | ||
|
||
- Sid: Allow-SendMessage-To-Queue-From-SNS-Topic2 | ||
Effect: Allow | ||
Principal: "*" | ||
Action: | ||
- sqs:SendMessage | ||
Resource: "*" | ||
Condition: | ||
ArnEquals: | ||
aws:SourceArn: | ||
Ref: SNSTopic2 | ||
|
||
- Sid: Allow-SendMessage-To-Queue-From-SNS-Topic3 | ||
Effect: Allow | ||
Principal: "*" | ||
Action: | ||
- sqs:SendMessage | ||
Resource: "*" | ||
Condition: | ||
ArnEquals: | ||
aws:SourceArn: | ||
Ref: SNSTopic3 | ||
|
||
Queues: | ||
- Ref: SqsQueue | ||
|
||
Outputs: | ||
SqsQueueUrl: | ||
Value: { Ref: SqsQueue } |
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,65 @@ | ||
'use strict' | ||
|
||
const { default: awsTesting } = require('aws-testing-library/lib/chai') | ||
const chai = require('chai') | ||
chai.use(awsTesting) | ||
const { expect } = chai | ||
|
||
const fetch = require('node-fetch') | ||
const { deployWithRandomStage, removeService } = require('../../../utils') | ||
|
||
describe('Multiple SQS Proxy Integrations Test', () => { | ||
let endpoint | ||
let stage | ||
let region | ||
let queueUrl | ||
const config = '__tests__/integration/sns/multiple-integrations/service/serverless.yml' | ||
|
||
beforeAll(async () => { | ||
;({ | ||
stage, | ||
region, | ||
endpoint, | ||
outputs: { SqsQueueUrl: queueUrl } | ||
} = await deployWithRandomStage(config)) | ||
}) | ||
|
||
afterAll(() => { | ||
removeService(stage, config) | ||
}) | ||
|
||
it('should get correct response from multiple sqs proxy endpoints', async () => { | ||
const topics = ['sns1', 'sns2', 'sns3'] | ||
|
||
for (const topic of topics) { | ||
const testEndpoint = `${endpoint}/${topic}` | ||
|
||
const body = JSON.stringify({ message: `message for ${topic}` }) | ||
const response = await fetch(testEndpoint, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body | ||
}) | ||
expect(response.headers.get('access-control-allow-origin')).to.deep.equal('*') | ||
expect(response.status).to.be.equal(200) | ||
const json = await response.json() | ||
|
||
expect(json).to.have.own.property('PublishResponse') | ||
|
||
expect(json.PublishResponse).to.have.own.property('PublishResult') | ||
expect(json.PublishResponse).to.have.own.property('ResponseMetadata') | ||
|
||
expect(json.PublishResponse.PublishResult).to.have.own.property('MessageId') | ||
expect(json.PublishResponse.PublishResult).to.have.own.property('SequenceNumber') | ||
|
||
expect(json.PublishResponse.ResponseMetadata).to.have.own.property('RequestId') | ||
|
||
await expect({ | ||
region, | ||
queueUrl, | ||
timeout: 10000, | ||
pollEvery: 2500 | ||
}).to.have.message((message) => message.Message === body) | ||
} | ||
}) | ||
}) |
Oops, something went wrong.