Skip to content

Commit edf858d

Browse files
authored
Merge pull request #43 from nhooyr/autobahn
Integrate autobahn tests
2 parents 9768e12 + b9465b2 commit edf858d

8 files changed

+440
-163
lines changed

Diff for: .github/test/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ LABEL "com.github.actions.description"="test"
55
LABEL "com.github.actions.icon"="code"
66
LABEL "com.github.actions.color"="purple"
77

8-
RUN apt update && apt install -y shellcheck
8+
RUN apt update && \
9+
apt install -y shellcheck python-pip && \
10+
pip install autobahntestsuite
911

1012
COPY entrypoint.sh /entrypoint.sh
1113

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
coverage.html
2+
wstest_reports

Diff for: opcode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const (
1010
opText
1111
opBinary
1212
// 3 - 7 are reserved for further non-control frames.
13-
opClose opcode = 8 + iota
13+
opClose opcode = 8 + iota - 3
1414
opPing
1515
opPong
1616
// 11-16 are reserved for further control frames.

Diff for: opcode_string.go

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: statuscode.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"math/bits"
8+
"unicode/utf8"
89

910
"golang.org/x/xerrors"
1011
)
@@ -21,7 +22,7 @@ const (
2122
StatusProtocolError
2223
StatusUnsupportedData
2324
// 1004 is reserved.
24-
StatusNoStatusRcvd StatusCode = 1005 + iota
25+
StatusNoStatusRcvd StatusCode = 1005 + iota - 4
2526
StatusAbnormalClosure
2627
StatusInvalidFramePayloadData
2728
StatusPolicyViolation
@@ -53,9 +54,38 @@ func parseClosePayload(p []byte) (code StatusCode, reason string, err error) {
5354
code = StatusCode(binary.BigEndian.Uint16(p))
5455
reason = string(p[2:])
5556

57+
if !utf8.ValidString(reason) {
58+
return 0, "", xerrors.Errorf("invalid utf-8: %q", reason)
59+
}
60+
if !isValidReceivedCloseCode(code) {
61+
return 0, "", xerrors.Errorf("invalid code %v", code)
62+
}
63+
5664
return code, reason, nil
5765
}
5866

67+
var validReceivedCloseCodes = map[StatusCode]bool{
68+
// see http://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
69+
StatusNormalClosure: true,
70+
StatusGoingAway: true,
71+
StatusProtocolError: true,
72+
StatusUnsupportedData: true,
73+
StatusNoStatusRcvd: false,
74+
StatusAbnormalClosure: false,
75+
StatusInvalidFramePayloadData: true,
76+
StatusPolicyViolation: true,
77+
StatusMessageTooBig: true,
78+
StatusMandatoryExtension: true,
79+
StatusInternalError: true,
80+
StatusServiceRestart: true,
81+
StatusTryAgainLater: true,
82+
StatusTLSHandshake: false,
83+
}
84+
85+
func isValidReceivedCloseCode(code StatusCode) bool {
86+
return validReceivedCloseCodes[code] || (code >= 3000 && code <= 4999)
87+
}
88+
5989
const maxControlFramePayload = 125
6090

6191
func closePayload(code StatusCode, reason string) ([]byte, error) {

Diff for: statuscode_string.go

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)