Skip to content

Commit

Permalink
Allow authentication without accessKeyId and secretAccessKey (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-essam authored Jul 23, 2019
1 parent 0bc9f16 commit b32d79c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ Constructs WTSQS object.
| --- | --- | --- | --- |
| options | <code>Object</code> | | Options object. |
| options.url | <code>String</code> | | SQS queue url. |
| options.accessKeyId | <code>String</code> | | AWS access key id. |
| options.secretAccessKey | <code>String</code> | | AWS secret access key. |
| [options.accessKeyId] | <code>String</code> | | AWS access key id. |
| [options.secretAccessKey] | <code>String</code> | | AWS secret access key. |
| [options.region] | <code>String</code> | <code>us-east-1</code> | AWS regions where queue exists. |
| [options.defaultMessageGroupId] | <code>String</code> | | FIFO queues only. Default tag assigned to a message that specifies it belongs to a specific message group. If not provided random uuid is assigned to each message which doesn't guarantee order but allows parallelism. |
| [options.defaultVisibilityTimeout] | <code>Integer</code> | <code>60</code> | Default duration (in seconds) that the received messages are hidden from subsequent retrieve requests. |
Expand Down
6 changes: 2 additions & 4 deletions lib/wtsqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class WTSQS {
* Constructs WTSQS object.
* @param {Object} options Options object.
* @param {String} options.url SQS queue url.
* @param {String} options.accessKeyId AWS access key id.
* @param {String} options.secretAccessKey AWS secret access key.
* @param {String} [options.accessKeyId] AWS access key id.
* @param {String} [options.secretAccessKey] AWS secret access key.
* @param {String} [options.region=us-east-1] AWS regions where queue exists.
* @param {String} [options.defaultMessageGroupId] FIFO queues only. Default tag assigned to a message that specifies it belongs to a specific message group. If not provided random uuid is assigned to each message which doesn't guarantee order but allows parallelism.
* @param {Integer} [options.defaultVisibilityTimeout=60] Default duration (in seconds) that the received messages are hidden from subsequent retrieve requests.
Expand All @@ -48,8 +48,6 @@ class WTSQS {
sqsOptions
}) {
if (url === undefined) throw new InvalidArgument('url required')
if (accessKeyId === undefined) throw new InvalidArgument('accessKeyId required')
if (secretAccessKey === undefined) throw new InvalidArgument('secretAccessKey required')

this.url = url
this.accessKeyId = accessKeyId
Expand Down
48 changes: 43 additions & 5 deletions test/wtsqs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,49 @@ const sleep = require('sleep-promise')
const { WTSQS } = require('../')

describe('WTSQS', () => {
const wtsqs = new WTSQS({
url: process.env.AWS_SQS_URL,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
defaultPollWaitTime: 1
let wtsqs

beforeEach('WTSQS:default', () => {
wtsqs = new WTSQS({
url: process.env.AWS_SQS_URL,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
defaultPollWaitTime: 1
})
})

describe('#constructor()', async () => {
it('should fail if url is not supplied', async () => {
try {
new WTSQS({ // eslint-disable-line no-new
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
})
throw new Error('no error thrown')
} catch (err) {
expect(err.name).to.equal('InvalidArgument')
}
})

it('should allow no accessKeyId and secretAccessKey', async () => {
new WTSQS({ // eslint-disable-line no-new
url: process.env.AWS_SQS_URL
})
})

it('should auto detect non fifo queues', async () => {
const _wtsqs = new WTSQS({
url: 'https://sqs.us-east-1.amazonaws.com/123/test'
})
expect(_wtsqs.isFIFO).to.be.false()
})

it('should auto detect fifo queues', async () => {
const _wtsqs = new WTSQS({
url: 'https://sqs.us-east-1.amazonaws.com/123/test.fifo'
})
expect(_wtsqs.isFIFO).to.be.true()
})
})

describe('#size()', () => {
Expand Down

0 comments on commit b32d79c

Please sign in to comment.