-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-4621): ipv6 address handling in HostAddress
- Loading branch information
Showing
11 changed files
with
171 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { expect } from 'chai'; | ||
import * as net from 'net'; | ||
import * as process from 'process'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { TopologyType } from '../../../src'; | ||
import { byStrings, sorted } from '../../tools/utils'; | ||
|
||
describe('IPv6 Addresses', () => { | ||
let client; | ||
let ipv6Hosts; | ||
beforeEach(async function () { | ||
if ( | ||
process.platform !== 'win32' && | ||
this.configuration.topologyType !== TopologyType.ReplicaSetWithPrimary | ||
) { | ||
// Ubuntu 18 does not support localhost AAAA lookups (IPv6) | ||
// Windows (VS2019) does | ||
return this.skip(); | ||
} | ||
|
||
ipv6Hosts = this.configuration.options.hostAddresses.map(({ port }) => `[::1]:${port}`); | ||
client = this.configuration.newClient(`mongodb://${ipv6Hosts.join(',')}/test`, { | ||
family: 6, | ||
[Symbol.for('@@mdb.skipPingOnConnect')]: true | ||
}); | ||
}); | ||
|
||
afterEach(async function () { | ||
sinon.restore(); | ||
await client.close(); | ||
}); | ||
|
||
it('should successfully connect using ipv6', async () => { | ||
await client.db().command({ ping: 1 }); | ||
expect(sorted(client.topology.s.description.servers.keys(), byStrings)).to.deep.equal( | ||
ipv6Hosts | ||
); | ||
}); | ||
|
||
it('should connect using ipv6 in connection string', async () => { | ||
const createConnectionSpy = sinon.spy(net, 'createConnection'); | ||
await client.db().command({ ping: 1 }); | ||
|
||
expect(createConnectionSpy).to.be.calledWithMatch({ host: '::1' }); | ||
expect(createConnectionSpy).to.not.be.calledWithMatch({ host: 'localhost' }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters