Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #17; Better Domain Filtering #18

Merged
merged 4 commits into from
Apr 24, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you're filtering and allowing anything on a domain (good), but then looking for 0-infinite whitespace after before the end of the line? why not just trim?

});
}

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to help prevent this, add -a code to the lab command - it'll throw errors if not all the expect(...)s are resolved

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