Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-xmldom
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyars committed Feb 20, 2022
2 parents 91b8e2e + 2ac3fae commit 3c4fe06
Show file tree
Hide file tree
Showing 19 changed files with 14,122 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -88,7 +88,7 @@ jobs:

mac:
macos:
xcode: 11.3.0
xcode: 12.5.1
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -84,7 +84,7 @@ A few of these tests verify the correct behavior under DNS failures. If your IS
is kind enough to hijack the NXDOMAIN DNS response in an attempt to allow you to conveniently peruse their
advertising page, those tests will fail. I suggest that, under such circumstances, you talk to your ISP
and let them know that their policies are causing mountebank tests to fail. You can also set
the environment variable `MB_AIRPLANE=true`, which will avoid tests requiring your DNS resolver.
the environment variable `MB_AIRPLANE_MODE=true`, which will avoid tests requiring your DNS resolver.

## Support

Expand Down
59 changes: 59 additions & 0 deletions mbTest/api/http/httpFaultTest.js
@@ -0,0 +1,59 @@
'use strict';

const assert = require('assert'),
api = require('../../api').create(),
BaseHttpClient = require('../../baseHttpClient'),
port = api.port + 1,
timeout = parseInt(process.env.MB_SLOW_TEST_TIMEOUT || 2000);

['http', 'https'].forEach(protocol => {
const client = BaseHttpClient.create(protocol);

describe(`${protocol} imposter`, function () {
this.timeout(timeout);

afterEach(async function () {
await api.del('/imposters');
});

describe('POST /imposters with stubs', function () {
it('should drop the connection when fault CONNECTION_RESET_BY_PEER is specified', async function () {
const stub = { responses: [{ fault: 'CONNECTION_RESET_BY_PEER' }] },
request = { protocol, port, stubs: [stub] };
await api.createImposter(request);

try {
await client.get('/', port);
assert.fail('did not close socket');
}
catch (error) {
assert.strictEqual(error.code, 'ECONNRESET');
}
});

it('should write garbage then drop the connection when fault RANDOM_DATA_THEN_CLOSE is specified', async function () {
const stub = { responses: [{ fault: 'RANDOM_DATA_THEN_CLOSE' }] },
request = { protocol, port, stubs: [stub] };
await api.createImposter(request);

try {
await client.get('/', port);
assert.fail('did not close socket');
}
catch (error) {
assert.strictEqual(error.code, 'HPE_INVALID_CONSTANT');
}
});

it('should do nothing when undefined fault is specified', async function () {
const stub = { responses: [{ fault: 'NON_EXISTENT_FAULT' }] },
request = { protocol, port, stubs: [stub] };
await api.createImposter(request);
const response = await client.get('/', port);
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.body, '');
});

});
});
});

0 comments on commit 3c4fe06

Please sign in to comment.