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

pass ping and rsv tests #27

Merged
merged 7 commits into from
Mar 8, 2018
Merged

pass ping and rsv tests #27

merged 7 commits into from
Mar 8, 2018

Conversation

Andrew-Lees11
Copy link
Contributor

This pull request if to make our websockets server pass Autobahn tests.

These changes make websockets pass:
Case 2.5 (oversized ping)
Case 3.* (Reserved bits are == 0)

Copy link
Contributor

@ianpartridge ianpartridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for the invalidRSV too?

@@ -81,8 +81,15 @@ struct WSFrameParser {

private mutating func parseOpCode(bytes: UnsafePointer<UInt8>, from: Int) -> (WebSocketError?, Int) {
let byte = bytes[from]
frame.finalFrame = byte & 0x80 != 0
// 0x.. is the hexidecimal representation of the bits you would like to check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hexadecimal


// Check RSV is equal to 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does RSV stand for - can we add that info somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSV us short for reserved. I'll add that into the comment


// Check RSV is equal to 0
let rsv = (byte & 0x70) >> 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to shift?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so from the first byte, rsv bits are at 01110000. The shift makes the int[8] value of rsv represent 0-7 instead of 0, 16, 32, 48, 64. In our case since we are just ensuring they are 0 this doesn't matter but seemed sensible if we are RSV in future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'm not sure shifting is meaningful really - if we ever need to support RSV bits in future we can just mask them as needed. We're only ever going to refer to them as part of a UInt8 byte including the opcode, aren't we?

@@ -19,6 +19,9 @@ import Foundation
/// An error enum used when throwing errors within KituraWebSocket.
public enum WebSocketError: Error {

/// An invalid RSV was received in a WebSocket frame
case invalidRSV(UInt8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change so will need a major version (switches have to be exhaustive)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could refactor the code so it returns an invalid opcode since currently the rsv values are being passed around as part of that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the RSV bits aren't part of the opcode so you did the right thing, but... ugh this is annoying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They kind of are with how we are currently treating them. Currently If you send an op code of 25 it will send a ping with rsv = 7

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps that's one of the other testcase failures!

@Andrew-Lees11
Copy link
Contributor Author

Andrew-Lees11 commented Mar 8, 2018

Have added a test for RSV and removed the RSV error so it is non-breaking.

We could change the extension to WebSocketError so it gives different text if opcode is wrong or rsv is wrong?

@codecov-io
Copy link

Codecov Report

Merging #27 into master will decrease coverage by 0.21%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
- Coverage   90.44%   90.22%   -0.22%     
==========================================
  Files           9        9              
  Lines         471      481      +10     
==========================================
+ Hits          426      434       +8     
- Misses         45       47       +2
Flag Coverage Δ
#KituraWebSocket 90.22% <100%> (-0.22%) ⬇️
Impacted Files Coverage Δ
Sources/KituraWebSocket/WebSocketConnection.swift 90.57% <100%> (-0.87%) ⬇️
Sources/KituraWebSocket/WSFrameParser.swift 98.26% <100%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f60e831...67d52dc. Read the comment docs.

@Andrew-Lees11 Andrew-Lees11 merged commit 7633575 into master Mar 8, 2018
@ianpartridge ianpartridge deleted the PassAutobahnTests branch March 8, 2018 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants