Skip to content

Commit

Permalink
Ipv6 link local fix (#702)
Browse files Browse the repository at this point in the history
* Detect ipv6 addresses and append the network interface when connecting

* Make sure this.ip is a thing before trying to determine if the network interface needs to be appended

* Added unit tests, changed indexOf to includes (thanks @rwaldron)

* Added comments to the tests

* added expect(x) calls to tests

* Idiot forgot he wasn't using phpunit
  • Loading branch information
mattsoftware authored and rwaldron committed May 3, 2016
1 parent 7add2f8 commit 7b96324
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/lan-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ var LAN = {};
LAN.Connection = function(opts) {
this.auth = {};
this.ip = Array.isArray(opts.addresses) ? opts.addresses[0] : opts.host;
if (this.ip && this.ip.includes(':') && opts.networkInterface) {
this.ip = `${this.ip}%${opts.networkInterface}`;
}
this.host = opts.host || '';
this.auth.host = this.ip;
this.auth.port = opts.port || 22;
Expand Down
46 changes: 46 additions & 0 deletions test/unit/lan-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,52 @@ exports['LAN.Connection'] = {
test.equal(this.lanConnection.connectionType, 'LAN');
test.done();
},

ipWhenIpV6: function(test) {
test.expect(1);
this.lanConnection = new LAN.Connection({
addresses: ['fc00::', '172.16.2.5'],
host: 'home.loc',
});
// The first address was picked
test.equal(this.lanConnection.ip, 'fc00::');
test.done();
},

ipWhenIpV6LinkLocal: function(test) {
test.expect(1);
this.lanConnection = new LAN.Connection({
addresses: ['fc00::', '172.16.2.5'],
networkInterface: 'en0',
host: 'home.loc',
});
// THe first address was picked, which was ipv6, and a network interface also provided
test.equal(this.lanConnection.ip, 'fc00::%en0');
test.done();
},

ipWhenIpV4: function(test) {
test.expect(1);
this.lanConnection = new LAN.Connection({
addresses: ['172.16.2.5', 'fc00::'],
networkInterface: 'en0',
host: 'home.loc',
});
// The first address was picked
test.equal(this.lanConnection.ip, '172.16.2.5');
test.done();
},

// no ip addresses were found, fallback to the host
ipWhenNoIps: function(test) {
test.expect(1);
this.lanConnection = new LAN.Connection({
networkInterface: 'en0',
host: 'home.loc',
});
test.equal(this.lanConnection.ip, 'home.loc');
test.done();
},
};

exports['LAN.Scanner'] = {
Expand Down

0 comments on commit 7b96324

Please sign in to comment.