
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
superagent-httpbackend
Advanced tools
Stub out superagent requests using AngularJS' $httpBackend syntax
Stub out superagent requests using AngularJS' $httpBackend syntax
const httpBackend = require('../');
const superagent = require('superagent');
let response = null;
httpBackend.expect('GET', '/hello').respond({ hello: 'world' });
superagent.get('/hello', (err, res) => {
response = res;
});
assert.strictEqual(response, null);
httpBackend.flush();
assert.deepEqual(response.body, { hello: 'world' });
assert.throws(function() {
superagent.get('/hello', () => {});
}, /Unexpected request/);
httpBackend.expect('GET', '/hello').error(401, 'Not Authorized', { error: 'Fail!' });
superagent.get('/hello', (error) => {
assert.ok(error);
assert.equal(error.statusCode, 401);
assert.deepEqual(error.body, { error: 'Fail!' });
});
httpBackend.flush();
let response = null;
httpBackend.expect('GET', '/hello').respond({ hello: 'world' });
httpBackend.reset();
assert.throws(function() {
superagent.get('/hello', () => {});
}, /Unexpected request/);
let response = null;
httpBackend.expect('GET', '/hello').respond({ hello: 'world' });
superagent.get('/hello', (err, res) => {
response = res;
});
assert.strictEqual(response, null);
httpBackend.flush();
assert.deepEqual(response.body, { hello: 'world' });
let response = null;
httpBackend.expectGET('/hello').respond({ hello: 'world' });
superagent.get('/hello', (err, res) => {
response = res;
});
assert.strictEqual(response, null);
httpBackend.flush();
assert.deepEqual(response.body, { hello: 'world' });
let response = null;
const validateBody = (body) => {
throw new Error('Body validation failed');
};
httpBackend.expectPUT('/hello', validateBody).respond({ hello: 'world' });
assert.throws(() => {
superagent.put('/hello').send({ hello: 'world' }).end(() => {});
}, /Body validation failed/);
let response = null;
const validateBody = (body) => {
assert.deepEqual(body, { hello: 'world' });
};
httpBackend.expectPUT('/hello', validateBody).respond({ foo: 'bar' });
superagent.put('/hello').send({ hello: 'world' }).end((error, res) => {
assert.ifError(error);
assert.deepEqual(res.body, { foo: 'bar' });
});
httpBackend.flush();
let response = null;
httpBackend.expectGET('/hello', { autoFlush: true }).
respond({ hello: 'world' });
superagent.get('/hello', (err, res) => {
response = res;
});
assert.deepEqual(response.body, { hello: 'world' });
FAQs
Stub out superagent requests using AngularJS' $httpBackend syntax
The npm package superagent-httpbackend receives a total of 15 weekly downloads. As such, superagent-httpbackend popularity was classified as not popular.
We found that superagent-httpbackend 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.