5
5
use BeyondCode \LaravelWebSockets \Apps \App ;
6
6
use BeyondCode \LaravelWebSockets \Tests \Mocks \Message ;
7
7
use BeyondCode \LaravelWebSockets \WebSockets \Exceptions \ConnectionsOverCapacity ;
8
+ use BeyondCode \LaravelWebSockets \WebSockets \Exceptions \OriginNotAllowed ;
8
9
use BeyondCode \LaravelWebSockets \WebSockets \Exceptions \UnknownAppKey ;
9
10
10
11
class ConnectionTest extends TestCase
@@ -14,7 +15,7 @@ public function unknown_app_keys_can_not_connect()
14
15
{
15
16
$ this ->expectException (UnknownAppKey::class);
16
17
17
- $ this ->pusherServer ->onOpen ($ this ->getWebSocketConnection ('/?appKey= test ' ));
18
+ $ this ->pusherServer ->onOpen ($ this ->getWebSocketConnection ('test ' ));
18
19
}
19
20
20
21
/** @test */
@@ -65,4 +66,38 @@ public function ping_returns_pong()
65
66
66
67
$ connection ->assertSentEvent ('pusher:pong ' );
67
68
}
69
+
70
+ /** @test */
71
+ public function origin_validation_should_fail_for_no_origin ()
72
+ {
73
+ $ this ->expectException (OriginNotAllowed::class);
74
+
75
+ $ connection = $ this ->getWebSocketConnection ('TestOrigin ' );
76
+
77
+ $ this ->pusherServer ->onOpen ($ connection );
78
+
79
+ $ connection ->assertSentEvent ('pusher:connection_established ' );
80
+ }
81
+
82
+ /** @test */
83
+ public function origin_validation_should_fail_for_wrong_origin ()
84
+ {
85
+ $ this ->expectException (OriginNotAllowed::class);
86
+
87
+ $ connection = $ this ->getWebSocketConnection ('TestOrigin ' , ['Origin ' => 'https://google.ro ' ]);
88
+
89
+ $ this ->pusherServer ->onOpen ($ connection );
90
+
91
+ $ connection ->assertSentEvent ('pusher:connection_established ' );
92
+ }
93
+
94
+ /** @test */
95
+ public function origin_validation_should_pass_for_the_right_origin ()
96
+ {
97
+ $ connection = $ this ->getWebSocketConnection ('TestOrigin ' , ['Origin ' => 'https://test.origin.com ' ]);
98
+
99
+ $ this ->pusherServer ->onOpen ($ connection );
100
+
101
+ $ connection ->assertSentEvent ('pusher:connection_established ' );
102
+ }
68
103
}
0 commit comments