spec/unit/framing_spec.rb in em-websocket-0.5.0 vs spec/unit/framing_spec.rb in em-websocket-0.5.1

- old
+ new

@@ -13,11 +13,11 @@ end end def <<(data) @data << data - process_data(data) + process_data end def debug(*args); end end @@ -138,11 +138,11 @@ end end def <<(data) @data << data - process_data(data) + process_data end def debug(*args); end end @@ -207,11 +207,11 @@ end end def <<(data) @data << data - process_data(data) + process_data end def debug(*args); end end @@ -273,8 +273,26 @@ it "should accept a fragmented unmasked text message in 3 frames" do @f.should_receive(:message).with(:text, '', 'Hello world') @f << "\x01\x03Hel" @f << "\x00\x02lo" @f << "\x80\x06 world" + end + + it "should raise if non-fin frame is followed by a non-continuation data frame (continuation frame would be expected)" do + lambda { + @f << 0b00000001 # Not fin, text + @f << 0b00000001 # Length 1 + @f << 'f' + @f << 0b10000001 # fin, text (continutation expected) + @f << 0b00000001 # Length 1 + @f << 'b' + }.should raise_error(EM::WebSocket::WebSocketError, 'Continuation frame expected') + end + + it "should raise on non-fin control frames (control frames must not be fragmented)" do + lambda { + @f << 0b00001010 # Not fin, pong (opcode 10) + @f << 0b00000000 # Length 1 + }.should raise_error(EM::WebSocket::WebSocketError, 'Control frames must not be fragmented') end end end