This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fix some lint issues.
- Loading branch information
Showing
3 changed files
with
137 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
'use strict'; | ||
|
||
// TODO support ipv6 | ||
const common = require('../common'); | ||
if (!common.hasQuic) | ||
common.skip('missing quic'); | ||
|
||
const { createSocket } = require('quic'); | ||
const fixtures = require('../common/fixtures'); | ||
const key = fixtures.readKey('agent1-key.pem', 'binary'); | ||
const cert = fixtures.readKey('agent1-cert.pem', 'binary'); | ||
const ca = fixtures.readKey('ca1-cert.pem', 'binary'); | ||
|
||
const kServerName = 'agent2'; | ||
const kALPN = 'zzz'; | ||
|
||
// Setting `type` to `udp4` while setting `ipv6Only` to `true` is possible | ||
// and it will throw an error. | ||
{ | ||
const server = createSocket({ | ||
type: 'udp4', | ||
port: 0, | ||
ipv6Only: true, | ||
}); | ||
|
||
server.on('error', common.mustCall((err) => { | ||
common.expectsError({ | ||
code: 'EINVAL', | ||
type: Error, | ||
// TODO(@oyyd): Currently we cann't know the exact "syscall" so that it's | ||
// undefined here. | ||
message: 'undefined EINVAL', | ||
})(err); | ||
})); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
alpn: kALPN, | ||
}); | ||
} | ||
|
||
// Connecting ipv6 server by "127.0.0.1" should work when `ipv6Only` | ||
// is set to `false`. | ||
{ | ||
const server = createSocket({ | ||
type: 'udp6', | ||
port: 0, | ||
ipv6Only: false, | ||
}); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
alpn: kALPN, | ||
}); | ||
|
||
server.on('session', common.mustCall((serverSession) => { | ||
serverSession.on('stream', common.mustCall()); | ||
})); | ||
|
||
server.on('ready', common.mustCall(() => { | ||
const client = createSocket({ | ||
port: 0, | ||
}); | ||
|
||
const clientSession = client.connect({ | ||
key, | ||
cert, | ||
ca, | ||
address: common.localhostIPv4, | ||
port: server.address.port, | ||
servername: kServerName, | ||
alpn: kALPN, | ||
}); | ||
|
||
clientSession.on('secure', common.mustCall(() => { | ||
const clientStream = clientSession.openStream({ | ||
halfOpen: true, | ||
}); | ||
clientStream.end('hello'); | ||
clientStream.on('close', common.mustCall(() => { | ||
client.close(); | ||
server.close(); | ||
})); | ||
})); | ||
})); | ||
} | ||
|
||
// When the `ipv6Only` set to `true`, a client cann't connect to it | ||
// through "127.0.0.1". | ||
{ | ||
const server = createSocket({ | ||
type: 'udp6', | ||
port: 0, | ||
ipv6Only: true, | ||
}); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
alpn: kALPN, | ||
}); | ||
|
||
server.on('ready', common.mustCall(() => { | ||
const client = createSocket({ | ||
port: 0, | ||
}); | ||
|
||
client.on('ready', common.mustCall()); | ||
|
||
const clientSession = client.connect({ | ||
key, | ||
cert, | ||
ca, | ||
address: common.localhostIPv4, | ||
port: server.address.port, | ||
servername: kServerName, | ||
alpn: kALPN, | ||
idleTimeout: common.platformTimeout(500), | ||
}); | ||
|
||
clientSession.on('secure', common.mustNotCall()); | ||
clientSession.on('close', common.mustCall(() => { | ||
client.close(); | ||
server.close(); | ||
})); | ||
})); | ||
} |