Skip to content

Commit

Permalink
style(url parser): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Lord committed Nov 20, 2017
1 parent 8c8fe5a commit e24574c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
12 changes: 4 additions & 8 deletions lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(url, options, callback) {

if (result.protocol === 'mongodb+srv:') {
if (result.hostname.split('.').length < 3) {
return callback(new Error('uri does not have hostname, domainname and tld'))
return callback(new Error('uri does not have hostname, domainname and tld'));
}

result.domainLength = result.hostname.split('.').length;
Expand All @@ -39,12 +39,8 @@ module.exports = function(url, options, callback) {
return callback(new Error('No addresses found at host'));
}

for (var i = 0; i < addresses.length; i ++) {
if (!matchesParentDomain(
addresses[i].name,
result.hostname,
result.domainLength
)) {
for (var i = 0; i < addresses.length; i++) {
if (!matchesParentDomain(addresses[i].name, result.hostname, result.domainLength)) {
return callback(new Error('srv record does not share hostname with parent uri'));
}
}
Expand Down Expand Up @@ -81,7 +77,7 @@ module.exports = function(url, options, callback) {
function matchesParentDomain(srvAddress, parentDomain, domains) {
let srv = srvAddress.split('.');
let parent = parentDomain.split('.');
for (let i = 1; i <= (domains - 1); i ++) {
for (let i = 1; i <= domains - 1; i++) {
if (srv[srv.length - i] !== parent[parent.length - i]) {
return false;
}
Expand Down
20 changes: 10 additions & 10 deletions test/functional/url_parser_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ describe('Url SRV Parser', function() {
requires: { topology: ['single'] }
},
test: function(done) {
parse('mongodb+srv://10gen.cc', function(err, object) {
parse('mongodb+srv://10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('uri does not have hostname, domainname and tld');
done();
Expand All @@ -1260,14 +1260,14 @@ describe('Url SRV Parser', function() {
/**
* @ignore
*/
it.skip("should fail because returned host name's parent (build.10gen.cc) misses 'test'", {
it.only("should fail because returned host name's parent (build.10gen.cc) misses 'test'", {
metadata: {
requires: { topology: ['single'] }
},
test: function(done) {
// TODO it does return 'test'
// test.build.10gen.cc
parse('mongodb+srv://test13.test.build.10gen.cc', function(err, object) {
parse('mongodb+srv://test13.test.build.10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('srv record does not share hostname with parent uri');
done();
Expand All @@ -1283,7 +1283,7 @@ describe('Url SRV Parser', function() {
requires: { topology: ['single'] }
},
test: function(done) {
parse('mongodb+srv://test14.test.build.10gen.cc', function(err, object) {
parse('mongodb+srv://test14.test.build.10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('srv record does not share hostname with parent uri');
done();
Expand All @@ -1294,12 +1294,12 @@ describe('Url SRV Parser', function() {
/**
* @ignore
*/
it("should fail because returned host name's part 'not-build' mismatches URI parent part 'build'", {
it("should fail because returned host name's 'not-build' mismatches URI parent 'build'", {
metadata: {
requires: { topology: ['single'] }
},
test: function(done) {
parse('mongodb+srv://test15.test.build.10gen.cc', function(err, object) {
parse('mongodb+srv://test15.test.build.10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('srv record does not share hostname with parent uri');
done();
Expand All @@ -1310,12 +1310,12 @@ describe('Url SRV Parser', function() {
/**
* @ignore
*/
it("Should fail because returned host name's part 'not-10gen' mismatches URI parent part '10gen'", {
it("Should fail because returned host name's 'not-10gen' mismatches URI part '10gen'", {
metadata: {
requires: { topology: ['single'] }
},
test: function(done) {
parse('mongodb+srv://test16.test.build.10gen.cc', function(err, object) {
parse('mongodb+srv://test16.test.build.10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('srv record does not share hostname with parent uri');
done();
Expand All @@ -1331,7 +1331,7 @@ describe('Url SRV Parser', function() {
requires: { topology: ['single'] }
},
test: function(done) {
parse('mongodb+srv://test17.test.build.10gen.cc', function(err, object) {
parse('mongodb+srv://test17.test.build.10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('srv record does not share hostname with parent uri');
done();
Expand All @@ -1347,7 +1347,7 @@ describe('Url SRV Parser', function() {
requires: { topology: ['single'] }
},
test: function(done) {
parse('mongodb+srv://test18.test.build.10gen.cc', function(err, object) {
parse('mongodb+srv://test18.test.build.10gen.cc', function(err) {
expect(err).to.be.null;
done();
});
Expand Down

0 comments on commit e24574c

Please sign in to comment.