Skip to content

Integrate autobahn tests #43

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

Merged
merged 4 commits into from
Apr 7, 2019
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
4 changes: 3 additions & 1 deletion .github/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ LABEL "com.github.actions.description"="test"
LABEL "com.github.actions.icon"="code"
LABEL "com.github.actions.color"="purple"

RUN apt update && apt install -y shellcheck
RUN apt update && \
apt install -y shellcheck python-pip && \
pip install autobahntestsuite

COPY entrypoint.sh /entrypoint.sh

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage.html
wstest_reports
2 changes: 1 addition & 1 deletion opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
opText
opBinary
// 3 - 7 are reserved for further non-control frames.
opClose opcode = 8 + iota
opClose opcode = 8 + iota - 3
opPing
opPong
// 11-16 are reserved for further control frames.
Expand Down
10 changes: 5 additions & 5 deletions opcode_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion statuscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/bits"
"unicode/utf8"

"golang.org/x/xerrors"
)
Expand All @@ -21,7 +22,7 @@ const (
StatusProtocolError
StatusUnsupportedData
// 1004 is reserved.
StatusNoStatusRcvd StatusCode = 1005 + iota
StatusNoStatusRcvd StatusCode = 1005 + iota - 4
StatusAbnormalClosure
StatusInvalidFramePayloadData
StatusPolicyViolation
Expand Down Expand Up @@ -53,9 +54,38 @@ func parseClosePayload(p []byte) (code StatusCode, reason string, err error) {
code = StatusCode(binary.BigEndian.Uint16(p))
reason = string(p[2:])

if !utf8.ValidString(reason) {
return 0, "", xerrors.Errorf("invalid utf-8: %q", reason)
}
if !isValidReceivedCloseCode(code) {
return 0, "", xerrors.Errorf("invalid code %v", code)
}

return code, reason, nil
}

var validReceivedCloseCodes = map[StatusCode]bool{
// see http://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
StatusNormalClosure: true,
StatusGoingAway: true,
StatusProtocolError: true,
StatusUnsupportedData: true,
StatusNoStatusRcvd: false,
StatusAbnormalClosure: false,
StatusInvalidFramePayloadData: true,
StatusPolicyViolation: true,
StatusMessageTooBig: true,
StatusMandatoryExtension: true,
StatusInternalError: true,
StatusServiceRestart: true,
StatusTryAgainLater: true,
StatusTLSHandshake: false,
}

func isValidReceivedCloseCode(code StatusCode) bool {
return validReceivedCloseCodes[code] || (code >= 3000 && code <= 4999)
}

const maxControlFramePayload = 125

func closePayload(code StatusCode, reason string) ([]byte, error) {
Expand Down
26 changes: 13 additions & 13 deletions statuscode_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading