Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit b224c03

Browse files
oyyddanbev
authored andcommitted
test: add tests for quic
Also fix some lint issues. PR-URL: #171 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a19682e commit b224c03

3 files changed

Lines changed: 137 additions & 5 deletions

File tree

doc/api/quic.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ added: REPLACEME
8484
recently validated addresses are remembered. Setting `validateAddressLRU`
8585
to `true`, will enable the `validateAddress` option as well. Default:
8686
`false`.
87+
* `ipv6Only` {boolean}
8788

8889
Creates a new `QuicSocket` instance.
8990

@@ -1118,8 +1119,8 @@ added: REPLACEME
11181119
* `length` {number} The amount of data from the fd to send.
11191120
Default: `-1`.
11201121

1121-
Instead of using a `Quicstream` as a writable stream, send data from a given file
1122-
descriptor.
1122+
Instead of using a `Quicstream` as a writable stream, send data from a given
1123+
file descriptor.
11231124

11241125
If `offset` is set to a non-negative number, reading starts from that position
11251126
and the file offset will not be advanced.
@@ -1146,8 +1147,8 @@ added: REPLACEME
11461147
* `length` {number} The amount of data from the fd to send.
11471148
Default: `-1`.
11481149

1149-
Instead of using a `QuicStream` as a writable stream, send data from a given file
1150-
path.
1150+
Instead of using a `QuicStream` as a writable stream, send data from a given
1151+
file path.
11511152

11521153
The `options.onError` callback will be called if the file could not be opened.
11531154
If `offset` is set to a non-negative number, reading starts from that position.

lib/internal/quic/core.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const {
2121
validateQuicClientSessionOptions,
2222
validateQuicSocketOptions,
2323
} = require('internal/quic/util');
24-
const { validateNumber } = require('internal/validators');
2524
const util = require('util');
2625
const assert = require('internal/assert');
2726
const EventEmitter = require('events');
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
'use strict';
2+
3+
// TODO support ipv6
4+
const common = require('../common');
5+
if (!common.hasQuic)
6+
common.skip('missing quic');
7+
8+
const { createSocket } = require('quic');
9+
const fixtures = require('../common/fixtures');
10+
const key = fixtures.readKey('agent1-key.pem', 'binary');
11+
const cert = fixtures.readKey('agent1-cert.pem', 'binary');
12+
const ca = fixtures.readKey('ca1-cert.pem', 'binary');
13+
14+
const kServerName = 'agent2';
15+
const kALPN = 'zzz';
16+
17+
// Setting `type` to `udp4` while setting `ipv6Only` to `true` is possible
18+
// and it will throw an error.
19+
{
20+
const server = createSocket({
21+
type: 'udp4',
22+
port: 0,
23+
ipv6Only: true,
24+
});
25+
26+
server.on('error', common.mustCall((err) => {
27+
common.expectsError({
28+
code: 'EINVAL',
29+
type: Error,
30+
// TODO(@oyyd): Currently we can't know the exact "syscall" so that it's
31+
// undefined here.
32+
message: 'undefined EINVAL',
33+
})(err);
34+
}));
35+
36+
server.listen({
37+
key,
38+
cert,
39+
ca,
40+
alpn: kALPN,
41+
});
42+
}
43+
44+
// Connecting ipv6 server by "127.0.0.1" should work when `ipv6Only`
45+
// is set to `false`.
46+
{
47+
const server = createSocket({
48+
type: 'udp6',
49+
port: 0,
50+
ipv6Only: false,
51+
});
52+
53+
server.listen({
54+
key,
55+
cert,
56+
ca,
57+
alpn: kALPN,
58+
});
59+
60+
server.on('session', common.mustCall((serverSession) => {
61+
serverSession.on('stream', common.mustCall());
62+
}));
63+
64+
server.on('ready', common.mustCall(() => {
65+
const client = createSocket({
66+
port: 0,
67+
});
68+
69+
const clientSession = client.connect({
70+
key,
71+
cert,
72+
ca,
73+
address: common.localhostIPv4,
74+
port: server.address.port,
75+
servername: kServerName,
76+
alpn: kALPN,
77+
});
78+
79+
clientSession.on('secure', common.mustCall(() => {
80+
const clientStream = clientSession.openStream({
81+
halfOpen: true,
82+
});
83+
clientStream.end('hello');
84+
clientStream.on('close', common.mustCall(() => {
85+
client.close();
86+
server.close();
87+
}));
88+
}));
89+
}));
90+
}
91+
92+
// When the `ipv6Only` set to `true`, a client cann't connect to it
93+
// through "127.0.0.1".
94+
{
95+
const server = createSocket({
96+
type: 'udp6',
97+
port: 0,
98+
ipv6Only: true,
99+
});
100+
101+
server.listen({
102+
key,
103+
cert,
104+
ca,
105+
alpn: kALPN,
106+
});
107+
108+
server.on('ready', common.mustCall(() => {
109+
const client = createSocket({
110+
port: 0,
111+
});
112+
113+
client.on('ready', common.mustCall());
114+
115+
const clientSession = client.connect({
116+
key,
117+
cert,
118+
ca,
119+
address: common.localhostIPv4,
120+
port: server.address.port,
121+
servername: kServerName,
122+
alpn: kALPN,
123+
idleTimeout: common.platformTimeout(500),
124+
});
125+
126+
clientSession.on('secure', common.mustNotCall());
127+
clientSession.on('close', common.mustCall(() => {
128+
client.close();
129+
server.close();
130+
}));
131+
}));
132+
}

0 commit comments

Comments
 (0)