Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Truman was built with the sole purpose of making recording and replaying test fixtures simple for single page JavaScript applications. It works like so:
Fixturing directly within the browser makes sense for single page applications:
Install via npm:
npm install truman --save
const config = {
// An array of query string parameters to omit from XHR comparison when matching fixtures.
omittedQueryParams: ['sid', 'token'],
// An array request body JSON parameters to omit from XHR comparison when matching fixtures.
omittedDataParams: ['requestid'],
// An array of remote domains (with scheme) for which you don't want to store or replay fixtures
// This is typically useful for tracking calls that do not affect functionality of your app.
omittedDomains: [
'https://my.trackingprovider.com'
],
// Domain synonyms let us treat requests to one domain as matches for requests to another. For example, you
// may record your fixtures against a local copy of an API but want to make sure those fixtures are replayed
// when requests to the staging copy of the API are made during your test run. Domain synonyms do just that.
// In the example below we're saying 'https://staging.myapi.com', 'https://staging2.myapi.com' are synonymous
// to 'http://localhost:8000'.
domainSynonyms: {
'http://localhost:8000': ['https://staging.myapi.com', 'https://staging2.myapi.com']
}
database: {
// URL for the remote CouchDB database.
url: 'https://mycouchdburl.com',
// Username for the remote CouchDB database.
user: 'mycouchuser',
// Password for the remove CouchDB database.
password: 'mycouchpassword'
}
}
The truman module exposes the following methods:
truman.initialize([config])
initialize
does exactly what is says on the tin, it initializes the truman module with some provided config. It also restores either the recording or replaying state of the Truman module if it has previously been set to record or replay (on another tab or prior to a page refresh). See the config options section for more details on what config truman accepts.
initialize
returns a promise that resolves once initialization is complete.
truman.record(fixtureCollectionName, [callback])
record
puts the Truman module into record mode, meaning all XHR requests and responses will be recorded to the named fixture collection in the order that they occur. The size of the local database is limited by the capabilities of your browser, as we defer to PouchDB for browser storage.
record
returns a promise that resolves once the fixtures have begun recording. This promise is useful if you want to do something like only start your application once the module is recording.
truman.replay(fixtureCollectionName, [callback])
replay
puts the Truman module into replay mode, meaning as each XHR request is made, the module will look for a matching fixture to replay from the fixture collection, instead of making the real request.
replay
returns a promise that resolves once the fixtures have begun replaying. This promise is useful if you want to do something like only start your application once the module is replaying.
truman.push(fixtureCollectionName, tag, [callback])
push
takes a recorded fixture collection and pushes it to your remote database for persistence. push
returns a promise that resolves once the fixture collection has been successfully pushed.
truman.pull(fixtureCollectionName, [tag(s)], [callback])
pull
loads a recorded fixture collection from your remote database for into the browser. pull
returns a promise that resolves once the fixtures have been successfully loaded from the remote database.
truman.restore()
restore
simply stops any recording or replaying of fixtures currently in progress, and restores the XHR object to its original state.
truman.clear(fixtureCollectionName, [callback])
clear
simply removes all local fixtures belonging to the provided fixture collection name. clear
returns a promise that resolves once the specified fixture collection has been cleared.
truman.currentStatus()
currentStatus
returns the current status of the Truman module, either 'recording'
, 'replaying'
or null
.
npm install # Install dependencies
npm start # Run dev server with sandbox page and live reloading
npm test # Run the tests
npm run lint # Check code style
# Run the unit tests in multiple browsers, on Sauce Labs (replace xxx with your credentials)
USE_CLOUD=t SAUCE_USERNAME=xxx SAUCE_PASSWORD=xxx npm run test:karma
See CONTRIBUTING.md for more information on making contributions.
FAQs
Simple test fixtures for single page apps
We found that truman demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.