44
55use Carbon \CarbonImmutable ;
66use Illuminate \Http \Response ;
7+ use Pterodactyl \Enum \JwtScope ;
78use Lcobucci \JWT \Configuration ;
89use Pterodactyl \Models \Permission ;
910use Lcobucci \JWT \Signer \Hmac \Sha256 ;
@@ -53,17 +54,19 @@ public function testJwtAndWebsocketUrlAreReturnedForServerOwner()
5354 $ server ->node ->scheme = 'https ' ;
5455 $ server ->node ->save ();
5556
56- $ response = $ this ->actingAs ($ user )->getJson ("/api/client/servers/ $ server ->uuid /websocket " );
57-
58- $ response ->assertOk ();
59- $ response ->assertJsonStructure (['data ' => ['token ' , 'socket ' ]]);
57+ $ response = $ this ->actingAs ($ user )
58+ ->withoutExceptionHandling ()
59+ ->getJson ("/api/client/servers/ $ server ->uuid /websocket " )
60+ ->assertOk ()
61+ ->assertJsonStructure (['data ' => ['token ' , 'socket ' ]]);
6062
6163 $ connection = $ response ->json ('data.socket ' );
6264 $ this ->assertStringStartsWith ('wss:// ' , $ connection , 'Failed asserting that websocket connection address has expected "wss://" prefix. ' );
6365 $ this ->assertStringEndsWith ("/api/servers/ $ server ->uuid /ws " , $ connection , 'Failed asserting that websocket connection address uses expected Wings endpoint. ' );
6466
6567 $ config = Configuration::forSymmetricSigner (new Sha256 (), $ key = InMemory::plainText ($ server ->node ->getDecryptedKey ()));
66- $ config ->setValidationConstraints (new SignedWith (new Sha256 (), $ key ));
68+ $ config = $ config ->withValidationConstraints (new SignedWith (new Sha256 (), $ key ));
69+
6770 /** @var \Lcobucci\JWT\Token\Plain $token */
6871 $ token = $ config ->parser ()->parse ($ response ->json ('data.token ' ));
6972
@@ -86,9 +89,10 @@ public function testJwtAndWebsocketUrlAreReturnedForServerOwner()
8689 $ this ->assertEquals ($ expect , $ token ->claims ()->get ('iat ' ));
8790 $ this ->assertEquals ($ expect ->subMinutes (5 ), $ token ->claims ()->get ('nbf ' ));
8891 $ this ->assertEquals ($ expect ->addMinutes (10 ), $ token ->claims ()->get ('exp ' ));
89- $ this ->assertSame ($ user ->id , $ token ->claims ()->get ('user_id ' ));
92+ $ this ->assertSame ($ user ->uuid , $ token ->claims ()->get ('user_uuid ' ));
9093 $ this ->assertSame ($ server ->uuid , $ token ->claims ()->get ('server_uuid ' ));
9194 $ this ->assertSame (['* ' ], $ token ->claims ()->get ('permissions ' ));
95+ $ this ->assertEquals (JwtScope::Websocket->value , $ token ->claims ()->get ('scope ' ));
9296 }
9397
9498 /**
@@ -102,13 +106,15 @@ public function testJwtIsConfiguredCorrectlyForServerSubuser()
102106 /** @var \Pterodactyl\Models\Server $server */
103107 [$ user , $ server ] = $ this ->generateTestAccount ($ permissions );
104108
105- $ response = $ this ->actingAs ($ user )->getJson ("/api/client/servers/ $ server ->uuid /websocket " );
106-
107- $ response ->assertOk ();
108- $ response ->assertJsonStructure (['data ' => ['token ' , 'socket ' ]]);
109+ $ response = $ this ->actingAs ($ user )
110+ ->withoutExceptionHandling ()
111+ ->getJson ("/api/client/servers/ $ server ->uuid /websocket " )
112+ ->assertOk ()
113+ ->assertJsonStructure (['data ' => ['token ' , 'socket ' ]]);
109114
110115 $ config = Configuration::forSymmetricSigner (new Sha256 (), $ key = InMemory::plainText ($ server ->node ->getDecryptedKey ()));
111- $ config ->setValidationConstraints (new SignedWith (new Sha256 (), $ key ));
116+ $ config = $ config ->withValidationConstraints (new SignedWith (new Sha256 (), $ key ));
117+
112118 /** @var \Lcobucci\JWT\Token\Plain $token */
113119 $ token = $ config ->parser ()->parse ($ response ->json ('data.token ' ));
114120
@@ -119,5 +125,6 @@ public function testJwtIsConfiguredCorrectlyForServerSubuser()
119125
120126 // Check that the claims are generated correctly.
121127 $ this ->assertSame ($ permissions , $ token ->claims ()->get ('permissions ' ));
128+ $ this ->assertEquals (JwtScope::Websocket->value , $ token ->claims ()->get ('scope ' ));
122129 }
123130}
0 commit comments