Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
A JSON matcher for chai. This is really useful when you are testing API and want to ignore some attributes like: updatedAt, createdAt, id.
Install with npm
npm install --save-dev chai-like
Compare two JSON and ignore some keys based on expectation.
var object = {
id: 1,
name: 'test',
updatedAt: 'now'
};
object.should.like({
name: 'test'
});
object.should.not.like({
name: 'test1'
});
Deeply compare.
var object = {
id: 1,
name: 'test',
product: {
id: 1,
name: 'product'
},
updatedAt: 'now'
};
object.should.like({
name: 'test',
product: {
name: 'product'
}
});
object.should.not.like({
name: 'test',
product: {
name: 'product1'
}
});
Compare array.
var array = [{
id: 1,
name: 'test',
product: {
id: 1,
name: 'product'
},
updatedAt: 'now'
}];
array.should.like([{
name: 'test',
product: {
name: 'product'
}
}]);
array.should.not.like([{
name: 'test',
product: {
name: 'product1'
}
}]);
Compare JSON with an array sub node.
var object = {
id: 1,
name: 'test',
products: [{
id: 1,
name: 'product'
}],
updatedAt: 'now'
};
object.should.like({
name: 'test',
products: [{
name: 'product'
}]
});
object.should.not.like({
name: 'test',
products: [{
name: 'product1'
}]
});
You can extend chai-like with plugins as below format:
var chai = require('chai');
var like = require('chai-like');
var numberStringPlugin = {
match: function(object) {
return !isNaN(Number(object));
},
assert: function(object, expected) {
return object === Number(expected);
}
};
like.extend(numberStringPlugin);
chai.use(like);
Then we can assert as below:
var object = {
number: 123
};
object.should.like({
number: '123'
});
object.should.not.like({
number: 'not a number'
});
If some strings require fuzzy matching we can do this with a plugin as follows:
var chai = require('chai');
var like = require('chai-like');
var regexPlugin = {
match: function(object, expected) {
return typeof object === 'string' && expected instanceof RegExp;
},
assert: function(object, expected) {
return expected.test(object);
}
};
like.extend(regexPlugin);
chai.use(like);
Then we can assert as below:
var object = {
text: 'the quick brown fox jumps over the lazy dog'
};
object.should.like({
text: /.* jumps over .*/
});
object.should.not.like({
text: /\d/
});
FAQs
A JSON matcher for chai
The npm package chai-like receives a total of 26,708 weekly downloads. As such, chai-like popularity was classified as popular.
We found that chai-like demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.