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

test: add tests for quic ipv6Only #171

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ added: REPLACEME
recently validated addresses are remembered. Setting `validateAddressLRU`
to `true`, will enable the `validateAddress` option as well. Default:
`false`.
* `ipv6Only` {boolean}

Creates a new `QuicSocket` instance.

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

Instead of using a `Quicstream` as a writable stream, send data from a given file
descriptor.
Instead of using a `Quicstream` as a writable stream, send data from a given
file descriptor.

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

Instead of using a `QuicStream` as a writable stream, send data from a given file
path.
Instead of using a `QuicStream` as a writable stream, send data from a given
file path.

The `options.onError` callback will be called if the file could not be opened.
If `offset` is set to a non-negative number, reading starts from that position.
Expand Down
1 change: 0 additions & 1 deletion lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
validateQuicClientSessionOptions,
validateQuicSocketOptions,
} = require('internal/quic/util');
const { validateNumber } = require('internal/validators');
const util = require('util');
const assert = require('internal/assert');
const EventEmitter = require('events');
Expand Down
132 changes: 132 additions & 0 deletions test/parallel/test-quic-ipv6only.js
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 can't know the exact "syscall" so that it's
// undefined here.
message: 'undefined EINVAL',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a heads up, with #165 the syscall is correctly set to bind.

})(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();
}));
}));
}