test_java_websockets.py (1443:433622b9cc55) test_java_websockets.py (1453:71af60a59338)
1import time
2import struct
3import unittest
4from unit.applications.lang.java import TestApplicationJava
5from unit.applications.websockets import TestApplicationWebsocket
6
7
8class TestJavaWebsockets(TestApplicationJava):

--- 12 unchanged lines hidden (view full) ---

21 'clear keepalive_interval',
22 )
23
24 self.skip_alerts.extend(
25 [r'socket close\(\d+\) failed']
26 )
27
28 def close_connection(self, sock):
1import time
2import struct
3import unittest
4from unit.applications.lang.java import TestApplicationJava
5from unit.applications.websockets import TestApplicationWebsocket
6
7
8class TestJavaWebsockets(TestApplicationJava):

--- 12 unchanged lines hidden (view full) ---

21 'clear keepalive_interval',
22 )
23
24 self.skip_alerts.extend(
25 [r'socket close\(\d+\) failed']
26 )
27
28 def close_connection(self, sock):
29 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty sock')
29 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
30
31 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
32
33 self.check_close(sock)
34
35 def check_close(self, sock, code=1000, no_close=False):
36 frame = self.ws.frame_read(sock)
37

--- 398 unchanged lines hidden (view full) ---

436 def test_java_websockets_2_7__2_9(self):
437 self.load('websockets_mirror')
438
439 # 2_7
440
441 _, sock, _ = self.ws.upgrade()
442
443 self.ws.frame_write(sock, self.ws.OP_PONG, '')
30
31 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
32
33 self.check_close(sock)
34
35 def check_close(self, sock, code=1000, no_close=False):
36 frame = self.ws.frame_read(sock)
37

--- 398 unchanged lines hidden (view full) ---

436 def test_java_websockets_2_7__2_9(self):
437 self.load('websockets_mirror')
438
439 # 2_7
440
441 _, sock, _ = self.ws.upgrade()
442
443 self.ws.frame_write(sock, self.ws.OP_PONG, '')
444 self.assertEqual(self.recvall(sock, read_timeout=1), b'', '2_7')
444 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '2_7')
445
446 # 2_8
447
448 self.ws.frame_write(sock, self.ws.OP_PONG, 'unsolicited pong payload')
445
446 # 2_8
447
448 self.ws.frame_write(sock, self.ws.OP_PONG, 'unsolicited pong payload')
449 self.assertEqual(self.recvall(sock, read_timeout=1), b'', '2_8')
449 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '2_8')
450
451 # 2_9
452
453 payload = 'ping payload'
454
455 self.ws.frame_write(sock, self.ws.OP_PONG, 'unsolicited pong payload')
456 self.ws.frame_write(sock, self.ws.OP_PING, payload)
457

--- 49 unchanged lines hidden (view full) ---

507 self.ws.frame_write(sock, self.ws.OP_TEXT, payload, rsv2=True)
508 self.ws.frame_write(sock, self.ws.OP_PING, '')
509
510 frame = self.ws.frame_read(sock)
511 self.check_frame(frame, True, self.ws.OP_TEXT, payload)
512
513 self.check_close(sock, 1002, no_close=True)
514
450
451 # 2_9
452
453 payload = 'ping payload'
454
455 self.ws.frame_write(sock, self.ws.OP_PONG, 'unsolicited pong payload')
456 self.ws.frame_write(sock, self.ws.OP_PING, payload)
457

--- 49 unchanged lines hidden (view full) ---

507 self.ws.frame_write(sock, self.ws.OP_TEXT, payload, rsv2=True)
508 self.ws.frame_write(sock, self.ws.OP_PING, '')
509
510 frame = self.ws.frame_read(sock)
511 self.check_frame(frame, True, self.ws.OP_TEXT, payload)
512
513 self.check_close(sock, 1002, no_close=True)
514
515 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty 3_2')
515 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty 3_2')
516 sock.close()
517
518 # 3_3
519
520 _, sock, _ = self.ws.upgrade()
521
522 self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
523
524 frame = self.ws.frame_read(sock)
525 self.check_frame(frame, True, self.ws.OP_TEXT, payload)
526
527 self.ws.frame_write(
528 sock, self.ws.OP_TEXT, payload, rsv1=True, rsv2=True
529 )
530
531 self.check_close(sock, 1002, no_close=True)
532
516 sock.close()
517
518 # 3_3
519
520 _, sock, _ = self.ws.upgrade()
521
522 self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
523
524 frame = self.ws.frame_read(sock)
525 self.check_frame(frame, True, self.ws.OP_TEXT, payload)
526
527 self.ws.frame_write(
528 sock, self.ws.OP_TEXT, payload, rsv1=True, rsv2=True
529 )
530
531 self.check_close(sock, 1002, no_close=True)
532
533 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty 3_3')
533 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty 3_3')
534 sock.close()
535
536 # 3_4
537
538 _, sock, _ = self.ws.upgrade()
539
540 self.ws.frame_write(sock, self.ws.OP_TEXT, payload, chopsize=1)
541 self.ws.frame_write(
542 sock, self.ws.OP_TEXT, payload, rsv3=True, chopsize=1
543 )
544 self.ws.frame_write(sock, self.ws.OP_PING, '')
545
546 frame = self.ws.frame_read(sock)
547 self.check_frame(frame, True, self.ws.OP_TEXT, payload)
548
549 self.check_close(sock, 1002, no_close=True)
550
534 sock.close()
535
536 # 3_4
537
538 _, sock, _ = self.ws.upgrade()
539
540 self.ws.frame_write(sock, self.ws.OP_TEXT, payload, chopsize=1)
541 self.ws.frame_write(
542 sock, self.ws.OP_TEXT, payload, rsv3=True, chopsize=1
543 )
544 self.ws.frame_write(sock, self.ws.OP_PING, '')
545
546 frame = self.ws.frame_read(sock)
547 self.check_frame(frame, True, self.ws.OP_TEXT, payload)
548
549 self.check_close(sock, 1002, no_close=True)
550
551 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty 3_4')
551 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty 3_4')
552 sock.close()
553
554 # 3_5
555
556 _, sock, _ = self.ws.upgrade()
557
558 self.ws.frame_write(
559 sock,

--- 169 unchanged lines hidden (view full) ---

729 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
730
731 frame = self.ws.frame_read(sock)
732 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
733
734 # 5_4
735
736 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
552 sock.close()
553
554 # 3_5
555
556 _, sock, _ = self.ws.upgrade()
557
558 self.ws.frame_write(
559 sock,

--- 169 unchanged lines hidden (view full) ---

729 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
730
731 frame = self.ws.frame_read(sock)
732 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
733
734 # 5_4
735
736 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
737 self.assertEqual(self.recvall(sock, read_timeout=1), b'', '5_4')
737 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '5_4')
738 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
739
740 frame = self.ws.frame_read(sock)
741 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
742
743 # 5_5
744
745 self.ws.frame_write(

--- 20 unchanged lines hidden (view full) ---

766 frame = self.ws.frame_read(sock)
767 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
768
769 # 5_7
770
771 ping_payload = 'ping payload'
772
773 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
738 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
739
740 frame = self.ws.frame_read(sock)
741 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
742
743 # 5_5
744
745 self.ws.frame_write(

--- 20 unchanged lines hidden (view full) ---

766 frame = self.ws.frame_read(sock)
767 self.check_frame(frame, True, self.ws.OP_TEXT, 'fragment1fragment2')
768
769 # 5_7
770
771 ping_payload = 'ping payload'
772
773 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
774 self.assertEqual(self.recvall(sock, read_timeout=1), b'', '5_7')
774 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '5_7')
775
776 self.ws.frame_write(sock, self.ws.OP_PING, ping_payload)
777
778 frame = self.ws.frame_read(sock)
779 self.check_frame(frame, True, self.ws.OP_PONG, ping_payload)
780
781 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
782

--- 167 unchanged lines hidden (view full) ---

950
951 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
952 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment4', fin=False)
953 self.ws.frame_write(sock, self.ws.OP_PING, 'pongme 2!')
954
955 frame = self.ws.frame_read(sock)
956 self.check_frame(frame, True, self.ws.OP_PONG, 'pongme 2!')
957
775
776 self.ws.frame_write(sock, self.ws.OP_PING, ping_payload)
777
778 frame = self.ws.frame_read(sock)
779 self.check_frame(frame, True, self.ws.OP_PONG, ping_payload)
780
781 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2', fin=True)
782

--- 167 unchanged lines hidden (view full) ---

950
951 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment3', fin=False)
952 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment4', fin=False)
953 self.ws.frame_write(sock, self.ws.OP_PING, 'pongme 2!')
954
955 frame = self.ws.frame_read(sock)
956 self.check_frame(frame, True, self.ws.OP_PONG, 'pongme 2!')
957
958 self.assertEqual(self.recvall(sock, read_timeout=1), b'', '5_20')
958 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', '5_20')
959 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment5')
960
961 self.check_frame(
962 self.ws.frame_read(sock),
963 True,
964 self.ws.OP_TEXT,
965 'fragment1fragment2fragment3fragment4fragment5',
966 )

--- 116 unchanged lines hidden (view full) ---

1083 # 7_1_3
1084
1085 _, sock, _ = self.ws.upgrade()
1086
1087 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1088 self.check_close(sock, no_close=True)
1089
1090 self.ws.frame_write(sock, self.ws.OP_PING, '')
959 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment5')
960
961 self.check_frame(
962 self.ws.frame_read(sock),
963 True,
964 self.ws.OP_TEXT,
965 'fragment1fragment2fragment3fragment4fragment5',
966 )

--- 116 unchanged lines hidden (view full) ---

1083 # 7_1_3
1084
1085 _, sock, _ = self.ws.upgrade()
1086
1087 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1088 self.check_close(sock, no_close=True)
1089
1090 self.ws.frame_write(sock, self.ws.OP_PING, '')
1091 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty sock')
1091 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
1092
1093 sock.close()
1094
1095 # 7_1_4
1096
1097 _, sock, _ = self.ws.upgrade()
1098
1099 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1100 self.check_close(sock, no_close=True)
1101
1102 self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
1092
1093 sock.close()
1094
1095 # 7_1_4
1096
1097 _, sock, _ = self.ws.upgrade()
1098
1099 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1100 self.check_close(sock, no_close=True)
1101
1102 self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
1103 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty sock')
1103 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
1104
1105 sock.close()
1106
1107 # 7_1_5
1108
1109 _, sock, _ = self.ws.upgrade()
1110
1111 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
1112 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1113 self.check_close(sock, no_close=True)
1114
1115 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2')
1104
1105 sock.close()
1106
1107 # 7_1_5
1108
1109 _, sock, _ = self.ws.upgrade()
1110
1111 self.ws.frame_write(sock, self.ws.OP_TEXT, 'fragment1', fin=False)
1112 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1113 self.check_close(sock, no_close=True)
1114
1115 self.ws.frame_write(sock, self.ws.OP_CONT, 'fragment2')
1116 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty sock')
1116 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
1117
1118 sock.close()
1119
1120 # 7_1_6
1121
1122 _, sock, _ = self.ws.upgrade()
1123
1124 self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2 ** 10)
1125 self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
1126 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1127
1128 self.recvall(sock, read_timeout=1)
1129
1130 self.ws.frame_write(sock, self.ws.OP_PING, '')
1117
1118 sock.close()
1119
1120 # 7_1_6
1121
1122 _, sock, _ = self.ws.upgrade()
1123
1124 self.ws.frame_write(sock, self.ws.OP_TEXT, 'BAsd7&jh23' * 26 * 2 ** 10)
1125 self.ws.frame_write(sock, self.ws.OP_TEXT, payload)
1126 self.ws.frame_write(sock, self.ws.OP_CLOSE, self.ws.serialize_close())
1127
1128 self.recvall(sock, read_timeout=1)
1129
1130 self.ws.frame_write(sock, self.ws.OP_PING, '')
1131 self.assertEqual(self.recvall(sock, read_timeout=1), b'', 'empty sock')
1131 self.assertEqual(self.recvall(sock, read_timeout=0.1), b'', 'empty soc')
1132
1133 sock.close()
1134
1135 # 7_3_1
1136
1137 _, sock, _ = self.ws.upgrade()
1138
1139 self.ws.frame_write(sock, self.ws.OP_CLOSE, '')

--- 297 unchanged lines hidden ---
1132
1133 sock.close()
1134
1135 # 7_3_1
1136
1137 _, sock, _ = self.ws.upgrade()
1138
1139 self.ws.frame_write(sock, self.ws.OP_CLOSE, '')

--- 297 unchanged lines hidden ---