Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
mock-aws-s3
Advanced tools
The mock-aws-s3 npm package is a mock implementation of the AWS S3 SDK, allowing developers to simulate interactions with AWS S3 in a local environment. This is particularly useful for testing and development purposes without incurring costs or requiring an actual AWS account.
Mocking S3 Bucket Creation
This feature allows you to mock the creation of an S3 bucket. The code sample demonstrates how to create a bucket named 'my-bucket' using the mock-aws-s3 package.
const AWS = require('mock-aws-s3');
const s3 = new AWS.S3();
s3.createBucket({ Bucket: 'my-bucket' }, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Mocking S3 Object Upload
This feature allows you to mock the upload of an object to an S3 bucket. The code sample demonstrates how to upload a string 'Hello, world!' to a bucket named 'my-bucket' with the key 'my-key'.
const AWS = require('mock-aws-s3');
const s3 = new AWS.S3();
const params = {
Bucket: 'my-bucket',
Key: 'my-key',
Body: 'Hello, world!'
};
s3.upload(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Mocking S3 Object Retrieval
This feature allows you to mock the retrieval of an object from an S3 bucket. The code sample demonstrates how to retrieve an object with the key 'my-key' from a bucket named 'my-bucket' and log its content.
const AWS = require('mock-aws-s3');
const s3 = new AWS.S3();
const params = {
Bucket: 'my-bucket',
Key: 'my-key'
};
s3.getObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data.Body.toString()); // successful response
});
The aws-sdk-mock package allows you to easily mock AWS SDK methods for unit testing. It provides a more comprehensive mocking capability for various AWS services, not just S3. Compared to mock-aws-s3, aws-sdk-mock offers broader functionality and can be used to mock other AWS services like DynamoDB, Lambda, etc.
LocalStack is a fully functional local AWS cloud stack. It provides a local testing environment for AWS services, including S3, DynamoDB, Lambda, and more. Unlike mock-aws-s3, LocalStack runs a local instance of the services, providing a more realistic testing environment but requiring more resources to run.
S3rver is a lightweight server that simulates the S3 API. It is designed for testing S3 interactions locally. Compared to mock-aws-s3, s3rver provides a more realistic simulation of the S3 API by running a local server, which can be useful for integration testing.
This is a very simple interface that mocks the AWS SDK for Node.js. The implementation is incomplete but most basic features are supported.
Available:
It uses a directory to mock a bucket and its content.
If you'd like to see some more features or you have some suggestions, feel free to use the issues or submit a pull request.
var AWSMock = require('mock-aws-s3');
AWSMock.config.basePath = '/tmp/buckets/' // Can configure a basePath for your local buckets
var s3 = AWSMock.S3({
params: { Bucket: 'example' }
});
s3.putObject({Key: 'sea/animal.json', Body: '{"is dog":false,"name":"otter","stringified object?":true}'}, function(err, data) {
s3.listObjects({Prefix: 'sea'}, function (err, data) {
console.log(data);
});
});
var params = { Bucket: 'example' };
s3.createBucket(params, function(err) {
if(err) {
console.error(err);
}
});
var params = { Bucket: 'example' };
s3.deleteBucket(params, function(err) {
if(err) {
console.error(err);
}
});
FAQs
Mock AWS S3 SDK for Node.js
The npm package mock-aws-s3 receives a total of 366,174 weekly downloads. As such, mock-aws-s3 popularity was classified as popular.
We found that mock-aws-s3 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.