Skip to content

Commit

Permalink
Merge pull request #18 from CodeNow/rsandor/strict-domain-check
Browse files Browse the repository at this point in the history
Closes #17; Better Domain Filtering
  • Loading branch information
rsandor committed Apr 24, 2015
2 parents c8834f6 + be4266c commit 2b373b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
10 changes: 7 additions & 3 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ function resolve(address, domainNames, cb) {
}

/**
* Filters out non-internal domains from the given list of names.
* Trims and filters out non-internal domains from the given list of
* names.
* @param {Array} names List of domain names to filter.
* @return {Array} Filtered domain name list.
*/
function filterNames(names) {
return names.filter(function (name) {
return ~name.indexOf(process.env.DOMAIN_FILTER);
var regexFilter = new RegExp('^.*' + process.env.DOMAIN_FILTER + '$');
return names.map(function(name) {
return name.trim();
}).filter(function (name) {
return name.match(regexFilter);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"lint": "jshint index.js lib/",
"test": "jshint index.js lib/ && NODE_ENV=test lab -v -c ./test/*",
"test": "jshint index.js lib/ && NODE_ENV=test lab -v -c -a code ./test/*",
"docs": "jsdoc -d docs/ lib/"
},
"repository": {
Expand Down
22 changes: 18 additions & 4 deletions test/unit/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ describe('query', function() {
});
done();
});

after(function (done) {
apiClient.user.fetchInternalIpForHostname.restore();
done();
});

it('should resolve internal dns names', function (done) {
it('should resolve internal domain names', function (done) {
var names = [
'web-codenow.runnableapp.com',
'api-codenow.runnableapp.com',
Expand All @@ -96,15 +97,28 @@ describe('query', function() {
});
});

it('should not resolve external dns names', function (done) {
it('should not resolve external domain names', function (done) {
var names = [
'www.google.com',
'www.wikipedia.org',
'www.ign.com'
];
query.resolve('127.0.0.1', names, function (err, records) {
if (err) { return done(err); }
expect(records).to.be.null;
expect(records).to.be.null();
done();
});
});

it('should not resolve domain names that contain the filter but are external', function (done) {
var names = [
'runnableapp.com.woza.com',
'www.runnableapp.com.neat.com',
'indeed.neat.runnable.com.app.com'
];
query.resolve('127.0.0.1', names, function (err, records) {
if (err) { return done(err); }
expect(records).to.be.null();
done();
});
});
Expand Down Expand Up @@ -184,7 +198,7 @@ describe('query', function() {
];
query.resolve('127.0.0.1', names, function (err, records) {
expect(err).to.exist();
expect(records).to.be.null;
expect(records).to.be.null();
done();
});
});
Expand Down

0 comments on commit 2b373b9

Please sign in to comment.