@fails-components/webtransport 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/old_test/echoserver.js +1 -1
- package/old_test/test.js +1 -1
- package/package.json +10 -25
- package/readme.md +2 -2
- package/test/bidirectional-streams.spec.js +0 -150
- package/test/datagrams.spec.js +0 -104
- package/test/fixtures/certificate.js +0 -456
- package/test/fixtures/chai.js +0 -8
- package/test/fixtures/known-bytes.js +0 -44
- package/test/fixtures/p-timeout.js +0 -33
- package/test/fixtures/quiche.browser.js +0 -2
- package/test/fixtures/quiche.js +0 -1
- package/test/fixtures/read-cert-hash.js +0 -7
- package/test/fixtures/read-stream.js +0 -57
- package/test/fixtures/reader-value.js +0 -51
- package/test/fixtures/server.js +0 -467
- package/test/fixtures/webtransport.browser.js +0 -19
- package/test/fixtures/webtransport.js +0 -3
- package/test/fixtures/write-stream.js +0 -24
- package/test/index.js +0 -124
- package/test/pw-no-https-errors.json +0 -5
- package/test/session.spec.js +0 -199
- package/test/stream-limits.spec.js +0 -259
- package/test/unidirectional-streams.spec.js +0 -133
package/test/session.spec.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import { readCertHash } from './fixtures/read-cert-hash.js'
|
|
4
|
-
import WebTransport from './fixtures/webtransport.js'
|
|
5
|
-
import { expect } from './fixtures/chai.js'
|
|
6
|
-
import { quicheLoaded } from './fixtures/quiche.js'
|
|
7
|
-
import { getReaderValue } from './fixtures/reader-value.js'
|
|
8
|
-
import { readStringFromStream } from './fixtures/read-stream.js'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @template T
|
|
12
|
-
* @typedef {import('../lib/types').Deferred<T>} Deferred<T>
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
describe('session', function () {
|
|
16
|
-
let forceReliable = false
|
|
17
|
-
if (process.env.USE_HTTP2 === 'true') forceReliable = true
|
|
18
|
-
const browser = process.env.BROWSER
|
|
19
|
-
const handshakemess =
|
|
20
|
-
browser !== 'firefox' ||
|
|
21
|
-
process.env.USE_POLYFILL === 'true' ||
|
|
22
|
-
process.env.USE_PONYFILL === 'true'
|
|
23
|
-
? 'Opening handshake failed.'
|
|
24
|
-
: 'WebTransport connection rejected'
|
|
25
|
-
|
|
26
|
-
/** @type {import('../lib/dom').WebTransport | undefined} */
|
|
27
|
-
let client
|
|
28
|
-
|
|
29
|
-
const wtOptions = {
|
|
30
|
-
serverCertificateHashes: [
|
|
31
|
-
{
|
|
32
|
-
algorithm: 'sha-256',
|
|
33
|
-
value: readCertHash(process.env.CERT_HASH)
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
forceReliable
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (process.env.NO_CERT_HASHES === 'true')
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
delete wtOptions.serverCertificateHashes
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
beforeEach(async () => {
|
|
46
|
-
if (
|
|
47
|
-
process.env.USE_HTTP2 !== 'true' &&
|
|
48
|
-
process.env.USE_PONYFILL !== 'true' &&
|
|
49
|
-
process.env.USE_POLYFILL !== 'true'
|
|
50
|
-
) {
|
|
51
|
-
await quicheLoaded
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
afterEach(async () => {
|
|
57
|
-
if (client != null) {
|
|
58
|
-
client.close()
|
|
59
|
-
client = undefined
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('should detect session closure', async () => {
|
|
64
|
-
client = new WebTransport(
|
|
65
|
-
`${process.env.SERVER_URL}/session_close`,
|
|
66
|
-
wtOptions
|
|
67
|
-
)
|
|
68
|
-
await client.ready
|
|
69
|
-
|
|
70
|
-
const result = await client.closed
|
|
71
|
-
expect(result).to.have.property('closeCode', 0)
|
|
72
|
-
expect(result).to.have.property('reason', '')
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('should detect session closure with close info', async () => {
|
|
76
|
-
// client context - connects to the server, sends some datagrams and reads the response
|
|
77
|
-
client = new WebTransport(
|
|
78
|
-
`${process.env.SERVER_URL}/session_close_with_reason`,
|
|
79
|
-
wtOptions
|
|
80
|
-
)
|
|
81
|
-
await client.ready
|
|
82
|
-
|
|
83
|
-
const result = await client.closed
|
|
84
|
-
expect(result).to.have.property('closeCode', 7)
|
|
85
|
-
expect(result).to.have.property('reason', 'this is the reason')
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should parse user data', async () => {
|
|
89
|
-
client = new WebTransport(
|
|
90
|
-
`${process.env.SERVER_URL}/session_with_userdata?foo=bar`,
|
|
91
|
-
wtOptions
|
|
92
|
-
)
|
|
93
|
-
await client.ready
|
|
94
|
-
|
|
95
|
-
const stream = await getReaderValue(client.incomingUnidirectionalStreams)
|
|
96
|
-
const string = await readStringFromStream(stream)
|
|
97
|
-
const userData = JSON.parse(string)
|
|
98
|
-
expect(userData).to.have.property('search', '?foo=bar')
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
if (browser === 'firefox') this.timeout(31000) // really firefox?
|
|
102
|
-
it('should error when connecting to a server that does not exist', async () => {
|
|
103
|
-
client = new WebTransport(`https://127.0.0.1:39821`, {
|
|
104
|
-
quicConnectTimeout: 100,
|
|
105
|
-
webTransportConnectTimeout: 100,
|
|
106
|
-
...wtOptions
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
const [closedResult, readyResult] = await Promise.all([
|
|
110
|
-
client.closed.catch((err) => err),
|
|
111
|
-
client.ready.catch((err) => err)
|
|
112
|
-
])
|
|
113
|
-
|
|
114
|
-
expect(closedResult)
|
|
115
|
-
.to.be.a('WebTransportError')
|
|
116
|
-
.with.property('message', handshakemess)
|
|
117
|
-
expect(readyResult)
|
|
118
|
-
.to.be.a('WebTransportError')
|
|
119
|
-
.with.property('message', handshakemess)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('should error when connecting to a path that does not exist', async () => {
|
|
123
|
-
client = new WebTransport(
|
|
124
|
-
`${process.env.SERVER_URL}/non_existant`,
|
|
125
|
-
wtOptions
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
const [closedResult, readyResult] = await Promise.all([
|
|
129
|
-
client.closed.catch((err) => err),
|
|
130
|
-
client.ready.catch((err) => err)
|
|
131
|
-
])
|
|
132
|
-
|
|
133
|
-
expect(closedResult)
|
|
134
|
-
.to.be.a('WebTransportError')
|
|
135
|
-
.with.property('message', handshakemess)
|
|
136
|
-
expect(readyResult)
|
|
137
|
-
.to.be.a('WebTransportError')
|
|
138
|
-
.with.property('message', handshakemess)
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
process.env.USE_POLYFILL !== 'true' &&
|
|
143
|
-
process.env.USE_PONYFILL !== 'true' &&
|
|
144
|
-
wtOptions.serverCertificateHashes
|
|
145
|
-
) {
|
|
146
|
-
// deactivated in polyfill case, no test necessary
|
|
147
|
-
it('should error when connecting with a bad certificate', async () => {
|
|
148
|
-
client = new WebTransport(`${process.env.SERVER_URL}/session_close`, {
|
|
149
|
-
serverCertificateHashes: [
|
|
150
|
-
{
|
|
151
|
-
algorithm: 'sha-256',
|
|
152
|
-
value: readCertHash(process.env.CERT_HASH + ':DE:AD:BE:EF')
|
|
153
|
-
}
|
|
154
|
-
],
|
|
155
|
-
// @ts-ignore
|
|
156
|
-
forceReliable
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
const [closedResult, readyResult] = await Promise.all([
|
|
160
|
-
client.closed.catch((err) => err),
|
|
161
|
-
client.ready.catch((err) => err)
|
|
162
|
-
])
|
|
163
|
-
|
|
164
|
-
expect(closedResult)
|
|
165
|
-
.to.be.a('WebTransportError')
|
|
166
|
-
.with.property('message', handshakemess)
|
|
167
|
-
expect(readyResult)
|
|
168
|
-
.to.be.a('WebTransportError')
|
|
169
|
-
.with.property('message', handshakemess)
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('should error when connecting with the wrong certificate', async () => {
|
|
173
|
-
client = new WebTransport(`${process.env.SERVER_URL}/session_close`, {
|
|
174
|
-
serverCertificateHashes: [
|
|
175
|
-
{
|
|
176
|
-
algorithm: 'sha-256',
|
|
177
|
-
value: readCertHash(
|
|
178
|
-
'DE:AD:BE:EF:' + process.env.CERT_HASH?.substring(12)
|
|
179
|
-
)
|
|
180
|
-
}
|
|
181
|
-
],
|
|
182
|
-
// @ts-ignore
|
|
183
|
-
forceReliable
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
const [closedResult, readyResult] = await Promise.all([
|
|
187
|
-
client.closed.catch((err) => err),
|
|
188
|
-
client.ready.catch((err) => err)
|
|
189
|
-
])
|
|
190
|
-
|
|
191
|
-
expect(closedResult)
|
|
192
|
-
.to.be.a('WebTransportError')
|
|
193
|
-
.with.property('message', handshakemess)
|
|
194
|
-
expect(readyResult)
|
|
195
|
-
.to.be.a('WebTransportError')
|
|
196
|
-
.with.property('message', handshakemess)
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
})
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import { readCertHash } from './fixtures/read-cert-hash.js'
|
|
4
|
-
import WebTransport from './fixtures/webtransport.js'
|
|
5
|
-
import { expect } from './fixtures/chai.js'
|
|
6
|
-
import { quicheLoaded } from './fixtures/quiche.js'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @template T
|
|
10
|
-
* @typedef {import('../lib/types').Deferred<T>} Deferred<T>
|
|
11
|
-
*/
|
|
12
|
-
describe('streamlimits', function () {
|
|
13
|
-
this.timeout(6000) // for debugging remove before commit
|
|
14
|
-
let forceReliable = false
|
|
15
|
-
let adjustlimit = 1
|
|
16
|
-
if (process.env.USE_HTTP2 === 'true') {
|
|
17
|
-
forceReliable = true
|
|
18
|
-
adjustlimit = 0
|
|
19
|
-
}
|
|
20
|
-
const browser = process.env.BROWSER
|
|
21
|
-
/* const handshakemess =
|
|
22
|
-
browser !== 'firefox' ||
|
|
23
|
-
process.env.USE_POLYFILL === 'true' ||
|
|
24
|
-
process.env.USE_PONYFILL === 'true'
|
|
25
|
-
? 'Opening handshake failed.'
|
|
26
|
-
: 'WebTransport connection rejected' */
|
|
27
|
-
|
|
28
|
-
const dowaitUntilAvailable = browser !== 'chromium' // remove after implementation
|
|
29
|
-
|
|
30
|
-
/** @type {import('../lib/dom').WebTransport | undefined} */
|
|
31
|
-
let client
|
|
32
|
-
|
|
33
|
-
const wtOptions = {
|
|
34
|
-
serverCertificateHashes: [
|
|
35
|
-
{
|
|
36
|
-
algorithm: 'sha-256',
|
|
37
|
-
value: readCertHash(process.env.CERT_HASH)
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
forceReliable
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (process.env.NO_CERT_HASHES === 'true')
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
delete wtOptions.serverCertificateHashes
|
|
47
|
-
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
beforeEach(async () => {
|
|
50
|
-
if (
|
|
51
|
-
process.env.USE_HTTP2 !== 'true' &&
|
|
52
|
-
process.env.USE_PONYFILL !== 'true' &&
|
|
53
|
-
process.env.USE_POLYFILL !== 'true'
|
|
54
|
-
) {
|
|
55
|
-
await quicheLoaded
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
afterEach(async () => {
|
|
61
|
-
if (client != null) {
|
|
62
|
-
client.close()
|
|
63
|
-
client = undefined
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
if (dowaitUntilAvailable) {
|
|
68
|
-
it('should detect stream limit bidi outgoing with waitUntilAvailable = true', async () => {
|
|
69
|
-
client = new WebTransport(
|
|
70
|
-
`${process.env.SERVER_URL}/streamlimits_getbidis_wua`,
|
|
71
|
-
{ ...wtOptions }
|
|
72
|
-
)
|
|
73
|
-
await client.ready
|
|
74
|
-
const bidistreams = []
|
|
75
|
-
let numbidi = 0
|
|
76
|
-
for (let i = 0; i < 150; i++) {
|
|
77
|
-
const curstream = client.createBidirectionalStream({
|
|
78
|
-
waitUntilAvailable: true
|
|
79
|
-
})
|
|
80
|
-
bidistreams.push(curstream)
|
|
81
|
-
curstream
|
|
82
|
-
.then(() => {
|
|
83
|
-
numbidi++
|
|
84
|
-
})
|
|
85
|
-
.catch(() => {})
|
|
86
|
-
}
|
|
87
|
-
await client.createUnidirectionalStream({
|
|
88
|
-
waitUntilAvailable: true
|
|
89
|
-
})
|
|
90
|
-
expect(numbidi).to.equal(100 - adjustlimit)
|
|
91
|
-
await client.createUnidirectionalStream({
|
|
92
|
-
waitUntilAvailable: true
|
|
93
|
-
})
|
|
94
|
-
for (let i = 0; i < 50 + adjustlimit; i++) {
|
|
95
|
-
const curstream = await bidistreams.shift()
|
|
96
|
-
await curstream.readable.cancel()
|
|
97
|
-
await curstream.writable.close()
|
|
98
|
-
}
|
|
99
|
-
await Promise.allSettled(bidistreams)
|
|
100
|
-
await client.createUnidirectionalStream({
|
|
101
|
-
waitUntilAvailable: true
|
|
102
|
-
})
|
|
103
|
-
expect(numbidi).to.equal(150)
|
|
104
|
-
|
|
105
|
-
const result = await client.closed
|
|
106
|
-
expect(result).to.have.property('closeCode', 0)
|
|
107
|
-
expect(result).to.have.property('reason', '')
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
it('should detect stream limit bidi outgoing', async () => {
|
|
112
|
-
client = new WebTransport(
|
|
113
|
-
`${process.env.SERVER_URL}/streamlimits_getbidis`,
|
|
114
|
-
{ ...wtOptions }
|
|
115
|
-
)
|
|
116
|
-
await client.ready
|
|
117
|
-
const bidistreams = []
|
|
118
|
-
let numbidi = 0
|
|
119
|
-
let numfailed = 0
|
|
120
|
-
for (let i = 0; i < 150; i++) {
|
|
121
|
-
const curstream = client.createBidirectionalStream()
|
|
122
|
-
bidistreams.push(curstream)
|
|
123
|
-
curstream
|
|
124
|
-
.then(() => {
|
|
125
|
-
numbidi++
|
|
126
|
-
})
|
|
127
|
-
.catch(() => {
|
|
128
|
-
numfailed++
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
await Promise.allSettled(bidistreams)
|
|
132
|
-
expect(numbidi).to.equal(100 - adjustlimit)
|
|
133
|
-
expect(numfailed).to.equal(50 + adjustlimit)
|
|
134
|
-
numfailed = 0
|
|
135
|
-
for (let i = 0; i < 50 + adjustlimit; i++) {
|
|
136
|
-
const curstream = await bidistreams.shift()
|
|
137
|
-
await curstream.readable.cancel()
|
|
138
|
-
await curstream.writable.close()
|
|
139
|
-
}
|
|
140
|
-
// as close is not a save measure, that the limit is updated
|
|
141
|
-
// actually no save measure exist, waiting for a typical rtt could be a way
|
|
142
|
-
// to ensure that the update of maxstreams arrives
|
|
143
|
-
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
144
|
-
|
|
145
|
-
for (let i = 0; i < 50 + adjustlimit; i++) {
|
|
146
|
-
const curstream = client.createBidirectionalStream()
|
|
147
|
-
bidistreams.push(curstream)
|
|
148
|
-
curstream
|
|
149
|
-
.then(() => {
|
|
150
|
-
numbidi++
|
|
151
|
-
})
|
|
152
|
-
.catch(() => {
|
|
153
|
-
numfailed++
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
await Promise.allSettled(bidistreams)
|
|
157
|
-
expect(numbidi).to.equal(150)
|
|
158
|
-
expect(numfailed).to.equal(0)
|
|
159
|
-
|
|
160
|
-
const result = await client.closed
|
|
161
|
-
expect(result).to.have.property('closeCode', 0)
|
|
162
|
-
expect(result).to.have.property('reason', '')
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
if (dowaitUntilAvailable) {
|
|
166
|
-
it('should detect stream limit unidi outgoing with waitUntilAvailable = true', async () => {
|
|
167
|
-
client = new WebTransport(
|
|
168
|
-
`${process.env.SERVER_URL}/streamlimits_getunidis_wua`,
|
|
169
|
-
{ ...wtOptions }
|
|
170
|
-
)
|
|
171
|
-
await client.ready
|
|
172
|
-
const unidistreams = []
|
|
173
|
-
let numunidi = 0
|
|
174
|
-
for (let i = 0; i < 150; i++) {
|
|
175
|
-
const curstream = client.createUnidirectionalStream({
|
|
176
|
-
waitUntilAvailable: true
|
|
177
|
-
})
|
|
178
|
-
unidistreams.push(curstream)
|
|
179
|
-
curstream
|
|
180
|
-
.then(() => {
|
|
181
|
-
numunidi++
|
|
182
|
-
})
|
|
183
|
-
.catch(() => {})
|
|
184
|
-
}
|
|
185
|
-
await client.createBidirectionalStream({
|
|
186
|
-
waitUntilAvailable: true
|
|
187
|
-
})
|
|
188
|
-
expect(numunidi).to.equal(100)
|
|
189
|
-
await client.createBidirectionalStream({
|
|
190
|
-
waitUntilAvailable: true
|
|
191
|
-
})
|
|
192
|
-
for (let i = 0; i < 50 + adjustlimit; i++) {
|
|
193
|
-
const curstream = await unidistreams.shift()
|
|
194
|
-
await curstream.close()
|
|
195
|
-
}
|
|
196
|
-
await Promise.allSettled(unidistreams)
|
|
197
|
-
await client.createBidirectionalStream({
|
|
198
|
-
waitUntilAvailable: true
|
|
199
|
-
})
|
|
200
|
-
expect(numunidi).to.equal(150)
|
|
201
|
-
|
|
202
|
-
const result = await client.closed
|
|
203
|
-
expect(result).to.have.property('closeCode', 0)
|
|
204
|
-
expect(result).to.have.property('reason', '')
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
it('should detect stream limit unidi outgoing', async () => {
|
|
209
|
-
client = new WebTransport(
|
|
210
|
-
`${process.env.SERVER_URL}/streamlimits_getunidis`,
|
|
211
|
-
{ ...wtOptions }
|
|
212
|
-
)
|
|
213
|
-
await client.ready
|
|
214
|
-
const unidistreams = []
|
|
215
|
-
let numunidi = 0
|
|
216
|
-
let numfailed = 0
|
|
217
|
-
for (let i = 0; i < 150; i++) {
|
|
218
|
-
const curstream = client.createUnidirectionalStream()
|
|
219
|
-
unidistreams.push(curstream)
|
|
220
|
-
curstream
|
|
221
|
-
.then(() => {
|
|
222
|
-
numunidi++
|
|
223
|
-
})
|
|
224
|
-
.catch(() => {
|
|
225
|
-
numfailed++
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
await Promise.allSettled(unidistreams)
|
|
229
|
-
expect(numunidi).to.equal(100)
|
|
230
|
-
expect(numfailed).to.equal(50)
|
|
231
|
-
numfailed = 0
|
|
232
|
-
for (let i = 0; i < 50 + adjustlimit; i++) {
|
|
233
|
-
const curstream = await unidistreams.shift()
|
|
234
|
-
await curstream.close()
|
|
235
|
-
}
|
|
236
|
-
// as close is not a save measure, that the limit is updated
|
|
237
|
-
// actually no save measure exist, waiting for a typical rtt could be a way
|
|
238
|
-
// to ensure that the update of maxstreams arrives
|
|
239
|
-
await new Promise((resolve) => setTimeout(resolve, 200))
|
|
240
|
-
for (let i = 0; i < 50; i++) {
|
|
241
|
-
const curstream = client.createUnidirectionalStream()
|
|
242
|
-
unidistreams.push(curstream)
|
|
243
|
-
curstream
|
|
244
|
-
.then(() => {
|
|
245
|
-
numunidi++
|
|
246
|
-
})
|
|
247
|
-
.catch(() => {
|
|
248
|
-
numfailed++
|
|
249
|
-
})
|
|
250
|
-
}
|
|
251
|
-
await Promise.allSettled(unidistreams)
|
|
252
|
-
expect(numunidi).to.equal(150)
|
|
253
|
-
expect(numfailed).to.equal(0)
|
|
254
|
-
|
|
255
|
-
const result = await client.closed
|
|
256
|
-
expect(result).to.have.property('closeCode', 0)
|
|
257
|
-
expect(result).to.have.property('reason', '')
|
|
258
|
-
})
|
|
259
|
-
})
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import { getReaderValue } from './fixtures/reader-value.js'
|
|
4
|
-
import WebTransport from './fixtures/webtransport.js'
|
|
5
|
-
import { expect } from 'chai'
|
|
6
|
-
import { readStream } from './fixtures/read-stream.js'
|
|
7
|
-
import { writeStream } from './fixtures/write-stream.js'
|
|
8
|
-
import { readCertHash } from './fixtures/read-cert-hash.js'
|
|
9
|
-
import * as ui8 from 'uint8arrays'
|
|
10
|
-
import { KNOWN_BYTES, KNOWN_BYTES_LENGTH } from './fixtures/known-bytes.js'
|
|
11
|
-
import { quicheLoaded } from './fixtures/quiche.js'
|
|
12
|
-
|
|
13
|
-
describe('unidirectional streams', function () {
|
|
14
|
-
/** @type {import('../lib/dom').WebTransport | undefined} */
|
|
15
|
-
let client
|
|
16
|
-
let forceReliable = false
|
|
17
|
-
if (process.env.USE_HTTP2 === 'true') forceReliable = true
|
|
18
|
-
|
|
19
|
-
const wtOptions = {
|
|
20
|
-
serverCertificateHashes: [
|
|
21
|
-
{
|
|
22
|
-
algorithm: 'sha-256',
|
|
23
|
-
value: readCertHash(process.env.CERT_HASH)
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
forceReliable
|
|
28
|
-
}
|
|
29
|
-
if (process.env.NO_CERT_HASHES === 'true')
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
delete wtOptions.serverCertificateHashes
|
|
32
|
-
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
beforeEach(async () => {
|
|
35
|
-
if (
|
|
36
|
-
process.env.USE_HTTP2 !== 'true' &&
|
|
37
|
-
process.env.USE_PONYFILL !== 'true' &&
|
|
38
|
-
process.env.USE_POLYFILL !== 'true'
|
|
39
|
-
) {
|
|
40
|
-
await quicheLoaded
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
afterEach(async () => {
|
|
46
|
-
if (client != null) {
|
|
47
|
-
client.close()
|
|
48
|
-
client = undefined
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('sends data over an outgoing unidirectional stream', async () => {
|
|
53
|
-
// client context - connects to the server, opens a bidi stream, sends some data and reads the response
|
|
54
|
-
try {
|
|
55
|
-
client = new WebTransport(
|
|
56
|
-
`${process.env.SERVER_URL}/unidirectional_client_send`,
|
|
57
|
-
wtOptions
|
|
58
|
-
)
|
|
59
|
-
await client.ready
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.log('Peak unidirectional error:', error)
|
|
62
|
-
throw error
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const stream = await client.createUnidirectionalStream()
|
|
66
|
-
// correct test
|
|
67
|
-
await writeStream(stream, KNOWN_BYTES)
|
|
68
|
-
|
|
69
|
-
// the remote will close the session
|
|
70
|
-
const result = await client.closed
|
|
71
|
-
client = undefined
|
|
72
|
-
|
|
73
|
-
// should receive the default close info
|
|
74
|
-
expect(result).to.have.property('reason', '')
|
|
75
|
-
expect(result).to.have.property('closeCode', 0)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('receives data over an incoming unidirectional stream', async () => {
|
|
79
|
-
// client context - waits for the server to open a bidi stream then pipes it back to them
|
|
80
|
-
client = new WebTransport(
|
|
81
|
-
`${process.env.SERVER_URL}/unidirectional_server_send`,
|
|
82
|
-
wtOptions
|
|
83
|
-
)
|
|
84
|
-
await client.ready
|
|
85
|
-
|
|
86
|
-
const stream = await getReaderValue(client.incomingUnidirectionalStreams)
|
|
87
|
-
const output = await readStream(stream, KNOWN_BYTES_LENGTH)
|
|
88
|
-
expect(ui8.concat(KNOWN_BYTES)).to.deep.equal(
|
|
89
|
-
ui8.concat(output),
|
|
90
|
-
'Did not receive the same bytes we sent'
|
|
91
|
-
)
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('handles fin when paused due to backpressure', async function () {
|
|
95
|
-
let addpolyfill = 0
|
|
96
|
-
if (
|
|
97
|
-
process.env.USE_POLYFILL === 'true' ||
|
|
98
|
-
process.env.USE_PONYFILL === 'true'
|
|
99
|
-
)
|
|
100
|
-
addpolyfill = 4000
|
|
101
|
-
this.timeout(6000 + addpolyfill)
|
|
102
|
-
client = new WebTransport(
|
|
103
|
-
`${process.env.SERVER_URL}/unidirectional_server_delay_before_read`,
|
|
104
|
-
wtOptions
|
|
105
|
-
)
|
|
106
|
-
await client.ready
|
|
107
|
-
|
|
108
|
-
const clientStream = await client.createUnidirectionalStream()
|
|
109
|
-
|
|
110
|
-
const writer = clientStream.getWriter()
|
|
111
|
-
|
|
112
|
-
for (const buf of KNOWN_BYTES) {
|
|
113
|
-
await writer.ready
|
|
114
|
-
await writer.write(buf)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
await new Promise((resolve) => setTimeout(resolve, 2000))
|
|
118
|
-
try {
|
|
119
|
-
await writer.ready
|
|
120
|
-
await writer.close()
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.log('Ignore stop sending', error)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// the remote will close the session cleanly if everything was ok
|
|
126
|
-
await client.closed
|
|
127
|
-
client = undefined
|
|
128
|
-
|
|
129
|
-
// should receive the default close info, not true on chromium
|
|
130
|
-
// expect(result).to.have.property('reason', '')
|
|
131
|
-
// expect(result).to.have.property('closeCode', 0)
|
|
132
|
-
})
|
|
133
|
-
})
|