Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
fantasy-laws
Advanced tools
Property-based tests for Fantasy Land -compliant algebraic data types
Property-based tests to verify the lawfulness of Fantasy Land -compliant algebraic data types.
Add fantasy-laws
, jsverify
, sanctuary-show
, and
sanctuary-type-classes
to "devDependencies"
in package.json,
then run npm install
.
Usage is best explained by example. The following code defines a Sum type which is intended to satisfy Setoid, Semigroup, Monoid, and Group:
function Sum(value) {
if (!(this instanceof Sum)) return new Sum (value);
this.value = value;
}
// Sum.fantasy-land/empty :: () -> Sum
Sum['fantasy-land/empty'] = function() { return Sum (0); };
// Sum#fantasy-land/equals :: Sum ~> Sum -> Boolean
Sum.prototype['fantasy-land/equals'] = function(other) {
return Z.equals (this.value, other.value);
};
// Sum#fantasy-land/concat :: Sum ~> Sum -> Sum
Sum.prototype['fantasy-land/concat'] = function(other) {
return Sum (this.value + other.value);
};
// Sum#fantasy-land/invert :: Sum ~> () -> Sum
Sum.prototype['fantasy-land/invert'] = function() {
return Sum (-this.value);
};
The following steps demonstrate how to test the Group laws:
Import fantasy-laws
, jsverify
, sanctuary-show
, and
sanctuary-type-classes
:
import laws from 'fantasy-laws';
import jsc from 'jsverify';
import show from 'sanctuary-show';
import Z from 'sanctuary-type-classes';
Import the type to be tested:
import Sum from '../Sum.js';
Define an "arbitrary" for the type:
// SumArb :: Arbitrary Sum
const SumArb = jsc.number.smap (Sum, sum => sum.value, show);
Provide the fixed parameters to laws.Group
:
const {leftInverse, rightInverse} = laws.Group (Z.equals, Sum);
Provide the appropriate number of arbitraries to the function associated with a particular law to produce a thunk:
// testLeftInverse :: () -> Undefined !
const testLeftInverse = leftInverse (SumArb);
// testRightInverse :: () -> Undefined !
const testRightInverse = rightInverse (SumArb);
To run the tests, invoke the thunk or use a test runner such as Mocha:
suite ('Group laws', () => {
test ('left inverse', testLeftInverse);
test ('right inverse', testRightInverse);
});
FAQs
Property-based tests for Fantasy Land -compliant algebraic data types
The npm package fantasy-laws receives a total of 2,771 weekly downloads. As such, fantasy-laws popularity was classified as popular.
We found that fantasy-laws demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.