Skip to content

Commit

Permalink
test: avoid DNS pollution on local env (#3034)
Browse files Browse the repository at this point in the history
closes #3033
  • Loading branch information
fengmk2 committed Sep 28, 2018
1 parent bace243 commit b13d904
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"lint": "eslint app config lib test *.js",
"test": "npm run lint -- --fix && egg-bin pkgfiles && npm run test-local",
"test-local": "egg-bin test",
"test-local-changed": "egg-bin test --changed",
"cov": "egg-bin cov --timeout 100000",
"ci": "npm run lint && egg-bin pkgfiles --check && npm run cov",
"doc-server": "doctools server",
Expand Down
29 changes: 29 additions & 0 deletions test/lib/core/dnscache_httpclient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ describe('test/lib/core/dnscache_httpclient.test.js', () => {
let app;
let url;
let host;
let originalDNSServers;

before(async () => {
app = utils.app('apps/dnscache_httpclient');
await app.ready();
url = await utils.startLocalServer();
url = url.replace('127.0.0.1', 'localhost');
host = urlparse(url).host;
originalDNSServers = dns.getServers();
});

afterEach(mm.restore);
afterEach(() => {
dns.setServers(originalDNSServers);
});

it('should ctx.curl work and set host', async () => {
await app.httpRequest()
Expand All @@ -38,6 +43,14 @@ describe('test/lib/core/dnscache_httpclient.test.js', () => {
});

it('should throw error when the first dns lookup fail', async () => {
if (!process.env.CI) {
// Avoid Network service provider DNS pollution
// alidns http://www.alidns.com/node-distribution/
dns.setServers([
'223.5.5.5',
'223.6.6.6',
]);
}
await app.httpRequest()
.get('/?url=' + encodeURIComponent('http://notexists-1111111local-domain.com'))
.expect(500)
Expand Down Expand Up @@ -78,6 +91,14 @@ describe('test/lib/core/dnscache_httpclient.test.js', () => {
});

it('should callback style work on domain not exists', done => {
if (!process.env.CI) {
// Avoid Network service provider DNS pollution
// alidns http://www.alidns.com/node-distribution/
dns.setServers([
'223.5.5.5',
'223.6.6.6',
]);
}
app.httpclient.curl('http://notexists-1111111local-domain.com', err => {
assert(err);
assert(err.code === 'ENOTFOUND');
Expand All @@ -96,6 +117,14 @@ describe('test/lib/core/dnscache_httpclient.test.js', () => {
});

it('should thunk style work on domain not exists', done => {
if (!process.env.CI) {
// Avoid Network service provider DNS pollution
// alidns http://www.alidns.com/node-distribution/
dns.setServers([
'223.5.5.5',
'223.6.6.6',
]);
}
app.httpclient.requestThunk('http://notexists-1111111local-domain.com')(err => {
assert(err);
assert(err.code === 'ENOTFOUND');
Expand Down

0 comments on commit b13d904

Please sign in to comment.