-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support pre-shared sessions (#3325)
Co-authored-by: Ezekiel Keator <ekeator@paypal.com>
- Loading branch information
1 parent
7f54a24
commit 39869b2
Showing
2 changed files
with
52 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict' | ||
|
||
const { tspl } = require('@matteo.collina/tspl') | ||
const { test, after, mock } = require('node:test') | ||
const { Client } = require('..') | ||
const { createServer } = require('node:https') | ||
const pem = require('https-pem') | ||
const tls = require('node:tls') | ||
|
||
test('custom session passed to client will be used in tls connect call', async (t) => { | ||
t = tspl(t, { plan: 4 }) | ||
|
||
const mockConnect = mock.method(tls, 'connect') | ||
|
||
const server = createServer(pem, (req, res) => { | ||
t.strictEqual('/', req.url) | ||
t.strictEqual('GET', req.method) | ||
res.setHeader('content-type', 'text/plain') | ||
res.end('hello') | ||
}) | ||
after(() => server.close()) | ||
|
||
server.listen(0, async () => { | ||
const session = Buffer.from('test-session') | ||
|
||
const client = new Client(`https://localhost:${server.address().port}`, { | ||
connect: { | ||
rejectUnauthorized: false, | ||
session | ||
} | ||
}) | ||
after(() => client.close()) | ||
|
||
const { statusCode, headers, body } = await client.request({ | ||
path: '/', | ||
method: 'GET' | ||
}) | ||
|
||
t.strictEqual(statusCode, 200) | ||
t.strictEqual(headers['content-type'], 'text/plain') | ||
|
||
const responseText = await body.text() | ||
t.strictEqual('hello', responseText) | ||
|
||
const connectSession = mockConnect.mock.calls[0].arguments[0].session | ||
t.strictEqual(connectSession, session) | ||
}) | ||
|
||
await t.completed | ||
}) |