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.
Fixes: #75 PR-URL: #150 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
6 changed files
with
438 additions
and
4 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,102 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasQuic) | ||
common.skip('missing quic'); | ||
|
||
const assert = require('assert'); | ||
const quic = require('quic'); | ||
const fs = require('fs'); | ||
|
||
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 variants = []; | ||
for (const variant of ['sendFD', 'sendFile', 'sendFD+fileHandle']) { | ||
for (const offset of [-1, 0, 100]) { | ||
for (const length of [-1, 100]) { | ||
variants.push({ variant, offset, length }); | ||
} | ||
} | ||
} | ||
|
||
for (const { variant, offset, length } of variants) { | ||
const server = quic.createSocket({ port: 0, validateAddress: true }); | ||
let fd; | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
rejectUnauthorized: false, | ||
maxCryptoBuffer: 4096, | ||
alpn: 'meow' | ||
}); | ||
|
||
server.on('session', common.mustCall((session) => { | ||
session.on('secure', common.mustCall((servername, alpn, cipher) => { | ||
const stream = session.openStream({ halfOpen: false }); | ||
|
||
stream.on('data', common.mustNotCall()); | ||
stream.on('finish', common.mustCall()); | ||
stream.on('close', common.mustCall()); | ||
stream.on('end', common.mustCall()); | ||
|
||
if (variant === 'sendFD') { | ||
fd = fs.openSync(__filename, 'r'); | ||
stream.sendFD(fd, { offset, length }); | ||
} else if (variant === 'sendFD+fileHandle') { | ||
fs.promises.open(__filename, 'r').then(common.mustCall((handle) => { | ||
fd = handle; | ||
stream.sendFD(handle, { offset, length }); | ||
})); | ||
} else { | ||
assert.strictEqual(variant, 'sendFile'); | ||
stream.sendFile(__filename, { offset, length }); | ||
} | ||
})); | ||
|
||
session.on('close', common.mustCall()); | ||
})); | ||
|
||
server.on('ready', common.mustCall(() => { | ||
const client = quic.createSocket({ | ||
port: 0, | ||
client: { | ||
key, | ||
cert, | ||
ca, | ||
alpn: 'meow' | ||
} | ||
}); | ||
|
||
const req = client.connect({ | ||
address: 'localhost', | ||
port: server.address.port | ||
}); | ||
|
||
req.on('stream', common.mustCall((stream) => { | ||
const data = []; | ||
stream.on('data', (chunk) => data.push(chunk)); | ||
stream.on('end', common.mustCall(() => { | ||
let expectedContent = fs.readFileSync(__filename); | ||
if (offset !== -1) expectedContent = expectedContent.slice(offset); | ||
if (length !== -1) expectedContent = expectedContent.slice(0, length); | ||
assert.deepStrictEqual(Buffer.concat(data), expectedContent); | ||
|
||
stream.end(); | ||
client.close(); | ||
server.close(); | ||
if (fd !== undefined) { | ||
if (fd.close) fd.close().then(common.mustCall()); | ||
else fs.closeSync(fd); | ||
} | ||
})); | ||
})); | ||
|
||
req.on('close', common.mustCall()); | ||
})); | ||
|
||
server.on('close', common.mustCall()); | ||
} |
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,63 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasQuic) | ||
common.skip('missing quic'); | ||
|
||
const quic = require('quic'); | ||
const fs = require('fs'); | ||
|
||
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 server = quic.createSocket({ port: 0, validateAddress: true }); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
rejectUnauthorized: false, | ||
maxCryptoBuffer: 4096, | ||
alpn: 'meow' | ||
}); | ||
|
||
server.on('session', common.mustCall((session) => { | ||
session.on('secure', common.mustCall((servername, alpn, cipher) => { | ||
const stream = session.openStream({ halfOpen: false }); | ||
|
||
fs.open = common.mustCall(fs.open); | ||
fs.close = common.mustCall(fs.close); | ||
|
||
stream.sendFile(__filename); | ||
stream.destroy(); // Destroy the stream before opening the fd finishes. | ||
|
||
session.close(); | ||
server.close(); | ||
})); | ||
|
||
session.on('close', common.mustCall()); | ||
})); | ||
|
||
server.on('ready', common.mustCall(() => { | ||
const client = quic.createSocket({ | ||
port: 0, | ||
client: { | ||
key, | ||
cert, | ||
ca, | ||
alpn: 'meow' | ||
} | ||
}); | ||
|
||
const req = client.connect({ | ||
address: 'localhost', | ||
port: server.address.port | ||
}); | ||
|
||
req.on('stream', common.mustNotCall()); | ||
|
||
req.on('close', common.mustCall(() => client.close())); | ||
})); | ||
|
||
server.on('close', common.mustCall()); |
Oops, something went wrong.