Socket
Socket
Sign inDemoInstall

@newrelic/aws-sdk

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@newrelic/aws-sdk - npm Package Compare versions

Comparing version 1.1.3 to 2.0.0

CODE_OF_CONDUCT.md

17

CHANGELOG.md

@@ -0,1 +1,18 @@

### 2.0.0 (2020-08-03):
* Updated to Apache 2.0 license.
* Bumped minimum peer dependency (and dev dependency) of newrelic (agent) to 6.11 for license matching.
* Added third party notices file and metadata for dependencies.
* Updated README with more detail.
* Added issue templates for bugs and enhancements.
* Added code of conduct file.
* Added contributing guide.
* Added pull request template.
* Migrated CI to GitHub Actions.
* Added copyright headers to all source files.
* Bumped @newrelic/test-utils to 4.0.0
* Added additional items to .npmignore.
* Removed AWS servers as dependency for versioned tests.
Enables versioned test to run successfully for forked repo PRs.
### 1.1.3 (2020-06-12):

@@ -2,0 +19,0 @@

96

CONTRIBUTING.md

@@ -1,2 +0,2 @@

# Guidelines for contributing code
# Guidelines for Contributing Code

@@ -7,21 +7,85 @@ New Relic welcomes code contributions by the Node community to this module, and

When contributing, keep in mind that New Relic customers (that's you!) are
running many different versions of Node, some of them pretty old. Changes that
depend on the newest version of Node will probably be rejected, with prejudice
if they replace something backwards compatible.
## Feature Requests
## Testing
Feature requests should be submitted in the [Issue tracker](../../issues), with
a description of the expected behavior & use case. Before submitting an Issue,
please search for similar ones in the [closed
issues](../../issues?q=is%3Aissue+is%3Aclosed+label%3Aenhancement).
The module includes a suite of unit and functional tests which should be used to
## Pull Requests
We can only accept PRs for version v2.0.0 or greater due to open source
licensing restrictions.
## Code of Conduct
Before contributing please read the [code of conduct](./CODE_OF_CONDUCT.md)
Note that our [code of conduct](./CODE_OF_CONDUCT.md) applies to all platforms
and venues related to this project; please follow it in all your interactions
with the project and its participants.
## Contributor License Agreement
Keep in mind that when you submit your Pull Request, you'll need to sign the
CLA via the click-through using CLA-Assistant. If you'd like to execute our
corporate CLA, or if you have any questions, please drop us an email at
opensource@newrelic.com.
For more information about CLAs, please check out Alex Russell’s excellent
post, [“Why Do I Need to Sign
This?”](https://infrequently.org/2008/06/why-do-i-need-to-sign-this/).
## Slack
We host a public Slack with a dedicated channel for contributors and
maintainers of open source projects hosted by New Relic. If you are
contributing to this project, you're welcome to request access to the
\#oss-contributors channel in the newrelicusers.slack.com workspace. To request
access, see https://newrelicusers-signup.herokuapp.com/.
## PR Guidelines
### Version Support
When contributing, keep in mind that New Relic customers (that's you!) are running many different versions of Node, some of them pretty old. Changes that depend on the newest version of Node will probably be rejected, especially if they replace something backwards compatible.
Be aware that the instrumentation needs to work with a wide range of versions of the instrumented modules, and that code that looks nonsensical or overcomplicated may be that way for compatibility-related reasons. Read all the comments and check the related tests before deciding whether existing code is incorrect.
If you’re planning on contributing a new feature or an otherwise complex contribution, we kindly ask you to start a conversation with the maintainer team by opening up an Github issue first.
### General Guidelines
In general, we try to limit adding third-party production dependencies. If one is necessary, please be prepared to make a clear case for the need.
### Coding Style Guidelines/Conventions
We use eslint to enforce certain coding standards. Please see our [.eslintrc](./.eslintrc.js) file for specific rule configuration.
### Testing Guidelines
The aws-sdk instrumentation module includes a suite of unit and functional tests which should be used to
verify your changes don't break existing functionality.
All tests are stored in `tests/` and are written using
[Tap](https://www.npmjs.com/package/tap) with the extension `.tap.js`.
Unit tests are stored in `tests/`. They're written in
[node-tap](https://github.com/isaacs/node-tap), and have the extension `.tap.js`.
Running the test suite is simple. Just run:
Functional tests against specific versions of instrumented modules are stored
in `test/versioned/`. They are also written in `node-tap`.
#### Running Tests
Running the test suite is simple. Just run:
npm test
### Writing tests
This will install all the necessary modules and run the unit tests in standalone mode, followed by
the functional tests if all of the unit tests pass.
To just run unit tests, run the following:
npm run unit
#### Writing Tests
For most contributions it is strongly recommended to add additional tests which

@@ -38,10 +102,2 @@ exercise your changes. This helps us efficiently incorporate your changes into

In general, including tests with your pull request dramatically increases the
chances it will be accepted.
## And finally...
You are welcome to send pull requests to us - however, by doing so you agree
that you are granting New Relic a non-exclusive, non-revokable, no-cost license
to use the code, algorithms, patents, and ideas in that code in our products if
we so choose. You also agree the code is provided as-is and you provide no
warranties as to its fitness or correctness for any purpose.
chances it will be accepted.

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@ function grabLastUrlSegment(url = '/') {

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

{
"name": "@newrelic/aws-sdk",
"version": "1.1.3",
"version": "2.0.0",
"description": "New Relic instrumentation of the aws-sdk package.",

@@ -20,9 +20,9 @@ "main": "index.js",

"author": "New Relic Node.js agent team <nodejs@newrelic.com>",
"license": "SEE LICENSE IN LICENSE",
"license": "Apache-2.0",
"devDependencies": {
"@newrelic/test-utilities": "^3.0.0",
"@newrelic/test-utilities": "^4.0.0",
"async": "^2.6.1",
"aws-sdk": "^2.403.0",
"eslint": "^5.12.1",
"newrelic": "^5.6.0",
"newrelic": "^6.11.0",
"sinon": "^7.2.3",

@@ -32,4 +32,4 @@ "tap": "^12.4.0"

"peerDependencies": {
"newrelic": ">=5.3.0"
"newrelic": ">=6.11.0"
}
}

@@ -1,12 +0,18 @@

[![Coverage Status][1]][2]
[![Community Project header](https://github.com/newrelic/open-source-office/raw/master/examples/categories/images/Community_Project.png)](https://github.com/newrelic/open-source-office/blob/master/examples/categories/index.md#community-project)
New Relic's official AWS-SDK package instrumentation for use with the
[Node agent](https://github.com/newrelic/node-newrelic).
# New Relic AWS SDK Instrumentation [![aws-sdk Instrumentation CI][1]][2]
It can be installed and loaded independently:
New Relic's official AWS SDK package instrumentation for use with [the Node.js agent](https://github.com/newrelic/node-newrelic). Provides instrumentation for the [AWS SDK (`aws-sdk`)](https://www.npmjs.com/package/aws-sdk) npm package.
## Installation
This package is [a dependency of the the Node Agent](https://github.com/newrelic/node-newrelic/blob/2121ffdc5001ea1bf9ab473138b9446c1f2a7eef/package.json#L147), and the average user should not need to install it manually.
If you are not the average user, you can add this package to your project using your package manager of choice (`npm` below), and then `require` the module into your project.
```
npm install @newrelic/aws-sdk
$ npm install @newrelic/aws-sdk
```
```js
```javascript
// index.js

@@ -16,10 +22,70 @@ require('@newrelic/aws-sdk')

### Supported AWS services
## Getting Started
For more information, please see the agent [installation guide][3], and
[compatibility and requirements][4].
Our instrumentation automatically tracks all SDK calls as "external" activities. In addition, the following have more specific instrumentation to capture additional data store or queue information.
[1]: https://coveralls.io/repos/github/newrelic/node-newrelic-aws-sdk/badge.svg?branch=master
[2]: https://coveralls.io/github/newrelic/node-newrelic-aws-sdk?branch=master
[3]: https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/install-nodejs-agent
[4]: https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent
- Amazon DynamoDB
- Amazon Simple Notification Service (SNS)
- Amazon Simple Queue Service (SQS)
## Testing
This module includes a list of unit and functional tests. To run these tests, use the following command
$ npm run test
You may also run individual test suites with the following commands
$ npm run unit
$ npm run versioned
## Support
Should you need assistance with New Relic products, you are in good hands with several support channels.
If the issue has been confirmed as a bug or is a feature request, please file a GitHub issue.
**Support Channels**
* [New Relic and AWS](https://docs.newrelic.com/docs/accounts/install-new-relic/partner-based-installation/new-relic-aws-amazon-web-services). AWS specific agent documentation
* [New Relic Documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/introduction-new-relic-nodejs): Comprehensive guidance for using our platform
* [New Relic Community](https://discuss.newrelic.com/c/support-products-agents/node-js-agent/): The best place to engage in troubleshooting questions
* [New Relic Developer](https://developer.newrelic.com/): Resources for building a custom observability applications
* [New Relic University](https://learn.newrelic.com/): A range of online training for New Relic users of every level
* [New Relic Technical Support](https://support.newrelic.com/) 24/7/365 ticketed support. Read more about our [Technical Support Offerings](https://docs.newrelic.com/docs/licenses/license-information/general-usage-licenses/support-plan).
## Privacy
At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise.
We define "Personal Data" as any information relating to an identified or identifiable individual, including, for example, your name, phone number, post code or zip code, Device ID, IP address and email address.
Please review [New Relic’s General Data Privacy Notice](https://newrelic.com/termsandconditions/privacy) for more information.
## Roadmap
See our [roadmap](https://github.com/newrelic/node-newrelic/blob/main/ROADMAP_Node.md), to learn more about our product vision, understand our plans, and provide us valuable feedback.
## Contributing
We encourage your contributions to improve New Relic's AWS SDK Instrumentation! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.
To [all contributors](https://github.com/newrelic/node-newrelic-aws-sdk/graphs/contributors), we thank you! Without your contribution, this project would not be what it is today.
We also host a community project page dedicated to
the [New Relic AWS SDK Instrumentation](https://opensource.newrelic.com/newrelic/node-newrelic-aws-sdk) package.
If you would like to contribute to this project, please review [these guidelines](https://github.com/newrelic/node-newrelic-aws-sdk/blob/main/CONTRIBUTING.md).
**A note about vulnerabilities**
As noted in our [security policy](https://github.com/newrelic/node-newrelic-aws-sdk/security/policy), New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through [HackerOne](https://hackerone.com/newrelic).
## License
The New Relic AWS SDK Instrumentation package is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
[1]: https://github.com/newrelic/node-newrelic-aws-sdk/workflows/aws-sdk%20Instrumentation%20CI/badge.svg
[2]: https://github.com/newrelic/node-newrelic-aws-sdk/actions?query=workflow%3A%22aws-sdk+Instrumentation+CI%22

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@ const tap = require('tap')

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -5,3 +9,5 @@

const utils = require('@newrelic/test-utilities')
const common = require('./common')
const { FAKE_CREDENTIALS } = require('./aws-server-stubs')

@@ -37,2 +43,3 @@ // This will not resolve / allow web requests. Even with real ones, requests

daxClient = new AmazonDaxClient({
credentials: FAKE_CREDENTIALS,
endpoints: DAX_ENDPOINTS,

@@ -39,0 +46,0 @@ maxRetries: 0 // fail fast

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -8,2 +12,4 @@

const { createEmptyResponseServer, FAKE_CREDENTIALS } = require('./aws-server-stubs')
tap.test('aws-sdk', (t) => {

@@ -15,14 +21,26 @@ t.autoend()

let server = null
let endpoint = null
t.beforeEach((done) => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
server = createEmptyResponseServer()
server.listen(0, () => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'})
endpoint = `http://localhost:${server.address().port}`
done()
})
AWS = require('aws-sdk')
done()
})
t.afterEach((done) => {
server.close()
server = null
helper && helper.unload()

@@ -33,39 +51,43 @@ AWS = null

t.test('should mark requests to be dt-disabled', (t) => {
const https = require('https')
sinon.spy(https, 'request')
t.test('should mark requests to be dt-disabled', {skip: true}, (t) => {
// http because we've changed endpoint to be http
const http = require('http')
sinon.spy(http, 'request')
t.tearDown(() => {
// `afterEach` runs before `tearDown`, so the sinon spy may have already
// been removed.
if (https.request.restore) {
https.request.restore()
if (http.request.restore) {
http.request.restore()
}
})
AWS.config.update({
region: 'region',
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'foobar'
})
})
const s3 = new AWS.S3({
apiVersion: '2006-03-01',
credentials: FAKE_CREDENTIALS,
endpoint: endpoint,
// allows using generic endpoint, instead of needing a
// bucket.endpoint server setup.
s3ForcePathStyle: true,
params: {Bucket: 'bucket'}
})
s3.listObjects({Delimiter: '/'}, () => {})
s3.listObjects({Delimiter: '/'}, (err) => {
t.error(err)
if (t.ok(https.request.calledOnce, 'should call http.request')) {
const args = https.request.getCall(0).args
const headers = args[0].headers
const symbols = Object.getOwnPropertySymbols(headers).filter((s) => {
return s.toString() === 'Symbol(Disable distributed tracing)'
})
t.equal(symbols.length, 1, 'should have disabled dt')
}
t.end()
if (t.ok(http.request.calledOnce, 'should call http.request')) {
const args = http.request.getCall(0).args
const headers = args[0].headers
const symbols = Object.getOwnPropertySymbols(headers).filter((s) => {
return s.toString() === 'Symbol(Disable distributed tracing)'
})
t.equal(symbols.length, 1, 'should have disabled dt')
}
t.end()
})
})
t.test('should maintain transaction state in promises', (t) => {
const service = new AWS.SES()
const service = new AWS.SES({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
helper.runInTransaction((tx) => {

@@ -75,3 +97,3 @@ service.cloneReceiptRuleSet({

RuleSetName: 'RuleSetToCreate'
}).promise().catch(() => {
}).promise().then(() => {
t.transaction(tx)

@@ -88,3 +110,3 @@ tx.end()

RuleSetName: 'RuleSetToCreate'
}).promise().catch(() => {
}).promise().then(() => {
t.transaction(tx)

@@ -91,0 +113,0 @@ tx.end()

@@ -0,5 +1,9 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const DATASTORE_PATTERN = /^Datastore/
const EXTERN_PATTERN = /^External\/.*?amazonaws\.com/
const EXTERN_PATTERN = /^External\/.*/
const SNS_PATTERN = /^MessageBroker\/SNS\/Topic/

@@ -6,0 +10,0 @@ const SQS_PATTERN = /^MessageBroker\/SQS\/Queue/

@@ -0,4 +1,7 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const common = require('./common')
const tap = require('tap')

@@ -8,8 +11,6 @@ const utils = require('@newrelic/test-utilities')

const RETRY_MS = 1500
const RETRY_MAX_MS = 30000
const common = require('./common')
const { createEmptyResponseServer, FAKE_CREDENTIALS } = require('./aws-server-stubs')
// NOTE: these take a while to run and can trigger tap CLI file timeout
// This can be avoided via --no-timeout or --timeout=<value>
tap.test('DynamoDB', {timeout: 90000}, (t) => {
tap.test('DynamoDB', (t) => {
t.autoend()

@@ -19,3 +20,2 @@

let AWS = null
let notInstrumentedDdb = null

@@ -25,41 +25,47 @@ let tableName = null

let server = null
t.beforeEach((done) => {
// For administrative tasks we don't want to impact metrics or risk breaking
const notInstrumentedAws = require('aws-sdk')
notInstrumentedDdb = new notInstrumentedAws.DynamoDB({region: 'us-east-1'})
server = createEmptyResponseServer()
server.listen(0, () => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
// Cleanup require cache so instrumentation will work afterwards.
const awsPath = require.resolve('aws-sdk')
delete require.cache[awsPath]
AWS = require('aws-sdk')
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
const endpoint = `http://localhost:${server.address().port}`
const ddb = new AWS.DynamoDB({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint,
region: 'us-east-1'
})
const docClient = new AWS.DynamoDB.DocumentClient({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint,
region: 'us-east-1'
})
AWS = require('aws-sdk')
const ddb = new AWS.DynamoDB({region: 'us-east-1'})
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-1'})
tableName = `delete-aws-sdk-test-table-${Math.floor(Math.random() * 100000)}`
tests = createTests(ddb, docClient, tableName)
tableName = `delete-aws-sdk-test-table-${Math.floor(Math.random() * 100000)}`
tests = createTests(ddb, docClient, tableName)
done()
done()
})
})
t.afterEach((done) => {
deleteTableIfNeeded(t, notInstrumentedDdb, tableName, () => {
helper && helper.unload()
server.close()
server = null
helper = null
helper && helper.unload()
helper = null
notInstrumentedDdb = null
AWS = null
tests = null
tableName = null
AWS = null
tests = null
tableName = null
done()
})
done()
})

@@ -74,11 +80,2 @@

if (cfg.method === 'createTable') {
const segment = helper.agent.tracer.getSegment()
return waitTableCreated(t, notInstrumentedDdb, tableName, segment)
.then(() => {
setImmediate(cb)
})
}
return setImmediate(cb)

@@ -106,7 +103,2 @@ })

await cfg.api[cfg.method](cfg.params).promise()
if (cfg.method === 'createTable') {
const segment = helper.agent.tracer.getSegment()
await waitTableCreated(t, notInstrumentedDdb, tableName, segment)
}
} catch (err) {

@@ -161,77 +153,2 @@ t.error(err)

async function waitTableCreated(t, ddb, tableName, segment, started) {
// A hack to avoid this showing via outbound http instrumentation.
forceOpaqueSegment(segment)
let data = null
try {
data = await ddb.describeTable({ TableName: tableName }).promise()
} catch (err) {
t.error(err)
}
if (data && data.Table.TableStatus === 'ACTIVE') {
segment.__NR_test_restoreOpaque()
t.comment('Table is active.')
return
}
const currentTime = Date.now()
const startTime = started || currentTime
const elapsed = currentTime - startTime
if (elapsed > RETRY_MAX_MS) {
segment.__NR_test_restoreOpaque()
t.ok(false, `Should not take longer than ${RETRY_MAX_MS}ms for table create.`)
return
}
t.comment(`Table does not yet exist, scheduling ${RETRY_MS}ms out.`)
await delay(RETRY_MS)
await waitTableCreated(t, ddb, tableName, segment, startTime)
}
function deleteTableIfNeeded(t, api, tableName, cb) {
api.describeTable({ TableName: tableName }, (err, data) => {
const tableExists = !(err && err.code === 'ResourceNotFoundException')
if (!tableExists || (data && data.Table.TableStatus === 'DELETING')) {
// table deleted or in process of deleting, all is good.
return setImmediate(cb)
}
t.error(err)
t.comment('Attempting to manually delete table')
const deleteTableParams = getDeleteTableParams(tableName)
return api.deleteTable(deleteTableParams, (err) => {
t.error(err)
cb()
})
})
}
/**
* Manually sets segment.opaque to true.
* Adds __NR_test_restoreOpaque to restore state.
* @param {*} segment
*/
function forceOpaqueSegment(segment) {
const originalOpaque = segment.opaque
// Our promise instrumentation will reset opaque status each call
// so we always need to set this.
segment.opaque = true
if (segment.__NR_test_restoreOpaque != null) {
return
}
segment.__NR_test_restoreOpaque = function restoreOpaque() {
segment.opaque = originalOpaque
delete segment.__NR_test_restoreOpaque
}
}
function createTests(ddb, docClient, tableName) {

@@ -373,7 +290,1 @@ const ddbUniqueArtist = `DELETE_One You Know ${Math.floor(Math.random() * 100000)}`

}
function delay(delayms) {
return new Promise(function(resolve) {
setTimeout(resolve, delayms)
})
}

@@ -0,7 +1,12 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const common = require('./common')
const tap = require('tap')
const utils = require('@newrelic/test-utilities')
const common = require('./common')
const { createEmptyResponseServer, FAKE_CREDENTIALS } = require('./aws-server-stubs')

@@ -14,15 +19,26 @@ tap.test('AWS HTTP Services', (t) => {

let server = null
let endpoint = null
t.beforeEach((done) => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
server = createEmptyResponseServer()
server.listen(0, () => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'})
endpoint = `http://localhost:${server.address().port}`
done()
})
AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'})
done()
})
t.afterEach((done) => {
server.close()
server = null
helper && helper.unload()

@@ -34,3 +50,6 @@ done()

helper.runInTransaction((tx) => {
const service = new AWS.APIGateway()
const service = new AWS.APIGateway({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.createApiKey({

@@ -49,4 +68,3 @@ customerId: 'STRING_VALUE',

value: 'STRING_VALUE'
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -60,3 +78,6 @@ setImmediate(finish, t, 'API Gateway', 'createApiKey', tx)

helper.runInTransaction((tx) => {
const service = new AWS.ELB()
const service = new AWS.ELB({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.addTags({

@@ -73,4 +94,3 @@ LoadBalancerNames: [

}]
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -84,3 +104,6 @@ setImmediate(finish, t, 'Elastic Load Balancing', 'addTags', tx)

helper.runInTransaction((tx) => {
const service = new AWS.ElastiCache()
const service = new AWS.ElastiCache({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.addTagsToResource({

@@ -94,4 +117,3 @@ ResourceName: 'STRING_VALUE', /* required */

]
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -105,3 +127,6 @@ setImmediate(finish, t, 'ElastiCache', 'addTagsToResource', tx)

helper.runInTransaction((tx) => {
const service = new AWS.Lambda()
const service = new AWS.Lambda({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.addLayerVersionPermission({

@@ -115,4 +140,3 @@ Action: 'lambda:GetLayerVersion', /* required */

RevisionId: 'STRING_VALUE'
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -126,8 +150,10 @@ setImmediate(finish, t, 'Lambda', 'addLayerVersionPermission', tx)

helper.runInTransaction((tx) => {
const service = new AWS.RDS()
const service = new AWS.RDS({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.addRoleToDBCluster({
DBClusterIdentifier: 'STRING_VALUE', /* required */
RoleArn: 'arn:aws:iam::123456789012:role/AuroraAccessRole' /* required */
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -141,8 +167,10 @@ setImmediate(finish, t, 'Amazon RDS', 'addRoleToDBCluster', tx)

helper.runInTransaction((tx) => {
const service = new AWS.Redshift()
const service = new AWS.Redshift({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.acceptReservedNodeExchange({
ReservedNodeId: 'STRING_VALUE', /* required */
TargetReservedNodeOfferingId: 'STRING_VALUE' /* required */
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -156,3 +184,6 @@ setImmediate(finish, t, 'Redshift', 'acceptReservedNodeExchange', tx)

helper.runInTransaction((tx) => {
const service = new AWS.Rekognition()
const service = new AWS.Rekognition({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.compareFaces({

@@ -172,4 +203,3 @@ SimilarityThreshold: 90,

}
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -183,8 +213,10 @@ setImmediate(finish, t, 'Rekognition', 'compareFaces', tx)

helper.runInTransaction((tx) => {
const service = new AWS.SES()
const service = new AWS.SES({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint
})
service.cloneReceiptRuleSet({
OriginalRuleSetName: 'RuleSetToClone',
RuleSetName: 'RuleSetToCreate'
}, (err) => {
t.matches(err, {name: 'AccessDenied'}, 'should have a permissions error')
}, () => {
tx.end()

@@ -191,0 +223,0 @@ setImmediate(finish, t, 'Amazon SES', 'cloneReceiptRuleSet', tx)

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -0,1 +1,5 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'

@@ -2,0 +6,0 @@

@@ -34,3 +34,5 @@ {

"instrumentation-supported.tap.js",
"s3.tap.js"
"s3.tap.js",
"sqs.tap.js",
"sns.tap.js"
]

@@ -37,0 +39,0 @@ },

@@ -0,7 +1,13 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const common = require('./common')
const tap = require('tap')
const utils = require('@newrelic/test-utilities')
const common = require('./common')
const { createEmptyResponseServer, FAKE_CREDENTIALS } = require('./aws-server-stubs')
tap.test('S3 buckets', (t) => {

@@ -14,15 +20,30 @@ t.autoend()

let server = null
t.beforeEach((done) => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
server = createEmptyResponseServer()
server.listen(0, () => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
AWS = require('aws-sdk')
S3 = new AWS.S3({
credentials: FAKE_CREDENTIALS,
endpoint: `http://localhost:${server.address().port}`,
// allows using generic endpoint, instead of needing a
// bucket.endpoint server setup.
s3ForcePathStyle: true,
apiVersion: '2006-03-01'
})
done()
})
AWS = require('aws-sdk')
S3 = new AWS.S3({apiVersion: '2006-03-01'})
done()
})
t.afterEach((done) => {
server.close()
server = null
helper && helper.unload()

@@ -34,19 +55,12 @@ done()

const Bucket = 'delete-aws-sdk-test-bucket-' + Math.floor(Math.random() * 100000)
t.tearDown(() => {
// Ensure bucket gets deleted even if test goes awry.
S3.deleteBucket({Bucket}, () => {})
})
helper.runInTransaction((tx) => {
S3.headBucket({Bucket}, (err) => {
t.matches(err, {code: 'NotFound'}, 'should get not found for bucket')
S3.createBucket({Bucket}, (err, data) => {
t.error(err)
S3.createBucket({Bucket}, (err) => {
t.error(err)
t.matches(data, {Location: `/${Bucket}`}, 'should have matching location')
S3.deleteBucket({Bucket}, (err) => {
// Sometimes S3 doesn't make the bucket quickly enough. The cleanup
// in `t.tearDown` should get it after we do all our checks.
if (err && err.code !== 'NoSuchBucket') {
t.error(err)
}
t.error(err)
tx.end()

@@ -64,21 +78,14 @@

const Bucket = 'delete-aws-sdk-test-bucket-' + Math.floor(Math.random() * 100000)
t.tearDown(() => {
// Ensure bucket gets deleted even if test goes awry.
S3.deleteBucket({Bucket}, () => {})
})
helper.runInTransaction(async tx => {
const bucketParams = {Bucket}
let headBucketError = null
try {
await S3.headBucket(bucketParams).promise()
await S3.headBucket({Bucket}).promise()
} catch (err) {
headBucketError = err
} finally {
t.matches(headBucketError, {code: 'NotFound'}, 'should get not found for bucket')
t.error(err)
}
try {
const createData = await S3.createBucket(bucketParams).promise()
t.matches(createData, {Location: `/${Bucket}`}, 'should have matching location')
// using pathstyle will result in the params being mutated due to this call,
// which is why the params are manually pasted in each call.
await S3.createBucket({Bucket}).promise()
} catch (err) {

@@ -89,9 +96,5 @@ t.error(err)

try {
await S3.deleteBucket(bucketParams).promise()
await S3.deleteBucket({Bucket}).promise()
} catch (err) {
// Sometimes S3 doesn't make the bucket quickly enough. The cleanup
// in `t.tearDown` should get it after we do all our checks.
if (err && err.code !== 'NoSuchBucket') {
t.error(err)
}
t.error(err)
}

@@ -98,0 +101,0 @@

@@ -0,8 +1,12 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const common = require('./common')
const tap = require('tap')
const utils = require('@newrelic/test-utilities')
const TOPIC_NAME = `delete-aws-sdk-test-topic-${Math.floor(Math.random() * 100000)}`
const common = require('./common')
const { createEmptyResponseServer, FAKE_CREDENTIALS } = require('./aws-server-stubs')

@@ -17,13 +21,21 @@ tap.test('SNS', (t) => {

let server = null
t.beforeEach((done) => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
AWS = require('aws-sdk')
sns = new AWS.SNS({region: 'us-east-1'})
sns.createTopic({Name: TOPIC_NAME}, (err, data) => {
TopicArn = data.TopicArn
server = createEmptyResponseServer()
server.listen(0, () => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
AWS = require('aws-sdk')
sns = new AWS.SNS({
credentials: FAKE_CREDENTIALS,
endpoint: `http://localhost:${server.address().port}`,
region: 'us-east-1'
})
done()

@@ -34,4 +46,8 @@ })

t.afterEach((done) => {
server.close()
server = null
helper && helper.unload()
sns.deleteTopic({TopicArn}, () => done())
done()
})

@@ -44,5 +60,3 @@

sns.publish(params, (err) => {
if (err) {
t.error(err)
}
t.error(err)
tx.end()

@@ -63,3 +77,3 @@

} catch (error) {
t.error()
t.error(error)
}

@@ -66,0 +80,0 @@

@@ -0,7 +1,13 @@

/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
const common = require('./common')
const tap = require('tap')
const utils = require('@newrelic/test-utilities')
const common = require('./common')
const { createSqsServer, FAKE_CREDENTIALS } = require('./aws-server-stubs')
const AWS_REGION = 'us-east-1'

@@ -22,34 +28,47 @@

let server = null
t.beforeEach((done) => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
AWS = require('aws-sdk')
sqs = new AWS.SQS({apiVersion: '2012-11-05', region: AWS_REGION})
server = createSqsServer()
server.listen(0, () => {
helper = utils.TestAgent.makeInstrumented()
helper.registerInstrumentation({
moduleName: 'aws-sdk',
type: 'conglomerate',
onRequire: require('../../lib/instrumentation')
})
queueName = 'delete-aws-sdk-test-queue-' + Math.floor(Math.random() * 100000)
AWS = require('aws-sdk')
done()
const endpoint = `http://localhost:${server.address().port}`
sqs = new AWS.SQS({
credentials: FAKE_CREDENTIALS,
endpoint: endpoint,
apiVersion: '2012-11-05',
region: AWS_REGION
})
queueName = 'delete-aws-sdk-test-queue-' + Math.floor(Math.random() * 100000)
done()
})
})
t.afterEach((done) => {
deleteQueue(sqs, queueUrl, (err) => {
t.error(err)
helper && helper.unload()
helper && helper.unload()
helper = null
sqs = null
AWS = null
server.close()
server = null
queueName = null
queueUrl = null
sendMessageRequestId = null
sendMessageBatchRequestId = null
receiveMessageRequestId = null
helper = null
sqs = null
AWS = null
done()
})
queueName = null
queueUrl = null
sendMessageRequestId = null
sendMessageBatchRequestId = null
receiveMessageRequestId = null
done()
})

@@ -174,13 +193,2 @@

function deleteQueue(sqs, queueUrl, cb) {
// Cleanup queue after test
const deleteParams = {
QueueUrl: queueUrl
}
sqs.deleteQueue(deleteParams, function(err) {
cb(err)
})
}
function checkName(t, name, action, queueName) {

@@ -187,0 +195,0 @@ const specificName = `/${action}/Named/${queueName}`

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc