Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket: fix 6 autobahn tests #3254

Merged
merged 1 commit into from
May 13, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/autobahn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Autobahn
on:
workflow_dispatch:

pull_request:
pull_request_target:
paths:
- '.github/workflows/autobahn.yml'
- 'lib/web/websocket/**'
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
run: npm run test:websocket:autobahn:report

- name: Generate Report for PR Comment
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request_target'
id: report-markdown
run: |
echo "comment<<nEOFn" >> $GITHUB_OUTPUT
Expand All @@ -64,7 +64,7 @@ jobs:
REPORTER: markdown

- name: Comment PR
if: github.event_name == 'pull_request'
if: github.event_name == 'pull_request_target'
uses: thollander/actions-comment-pull-request@v2
with:
message: ${{ steps.report-markdown.outputs.comment }}
Expand Down
12 changes: 10 additions & 2 deletions lib/web/websocket/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ByteParser extends Writable {

if (isControlFrame(opcode)) {
const loop = this.parseControlFrame(callback, {
header: buffer,
opcode,
fragmented,
payloadLength
Expand All @@ -122,6 +123,7 @@ class ByteParser extends Writable {
}
} else if (isContinuationFrame(opcode)) {
const loop = this.parseContinuationFrame(callback, {
header: buffer,
fin,
fragmented,
payloadLength
Expand Down Expand Up @@ -297,7 +299,7 @@ class ByteParser extends Writable {
* Parses control frames.
* @param {Buffer} data
* @param {(err?: Error) => void} callback
* @param {{ opcode: number, fragmented: boolean, payloadLength: number }} info
* @param {{ opcode: number, fragmented: boolean, payloadLength: number, header: Buffer }} info
*/
parseControlFrame (callback, info) {
assert(!info.fragmented)
Expand All @@ -307,6 +309,9 @@ class ByteParser extends Writable {
failWebsocketConnection(this.ws, 'Payload length for control frame exceeded 125 bytes.')
return false
} else if (this.#byteOffset < info.payloadLength) {
this.#buffers.unshift(info.header)
this.#byteOffset += 2

callback()
return false
}
Expand Down Expand Up @@ -405,14 +410,17 @@ class ByteParser extends Writable {
* Parses continuation frames.
* @param {Buffer} data
* @param {(err?: Error) => void} callback
* @param {{ fin: boolean, fragmented: boolean, payloadLength: number }} info
* @param {{ fin: boolean, fragmented: boolean, payloadLength: number, header: Buffer }} info
*/
parseContinuationFrame (callback, info) {
// If we received a continuation frame before we started parsing another frame.
if (this.#info.opcode === undefined) {
failWebsocketConnection(this.ws, 'Received unexpected continuation frame.')
return false
} else if (this.#byteOffset < info.payloadLength) {
this.#buffers.unshift(info.header)
this.#byteOffset += 2

callback()
return false
}
Expand Down
Loading