File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
app/Http/Requests/Api/Client/Account
tests/Integration/Api/Client Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 22
33namespace Pterodactyl \Http \Requests \Api \Client \Account ;
44
5+ use Pterodactyl \Models \ApiKey ;
56use Pterodactyl \Http \Requests \Api \Client \ClientApiRequest ;
67
78class StoreApiKeyRequest extends ClientApiRequest
@@ -11,9 +12,11 @@ class StoreApiKeyRequest extends ClientApiRequest
1112 */
1213 public function rules (): array
1314 {
15+ $ rules = ApiKey::getRules ();
16+
1417 return [
15- 'description ' => ' required|string|min:4 ' ,
16- 'allowed_ips ' => ' array ' ,
18+ 'description ' => $ rules [ ' memo ' ] ,
19+ 'allowed_ips ' => $ rules [ ' allowed_ips ' ] ,
1720 'allowed_ips.* ' => 'ip ' ,
1821 ];
1922 }
Original file line number Diff line number Diff line change @@ -121,6 +121,8 @@ public function testNoMoreThanFiveApiKeysCanBeCreatedForAnAccount()
121121
122122 /**
123123 * Test that a bad request results in a validation error being returned by the API.
124+ *
125+ * @see https://github.com/pterodactyl/panel/issues/2457
124126 */
125127 public function testValidationErrorIsReturnedForBadRequests ()
126128 {
@@ -135,6 +137,15 @@ public function testValidationErrorIsReturnedForBadRequests()
135137 $ response ->assertStatus (Response::HTTP_UNPROCESSABLE_ENTITY );
136138 $ response ->assertJsonPath ('errors.0.meta.rule ' , 'required ' );
137139 $ response ->assertJsonPath ('errors.0.detail ' , 'The description field is required. ' );
140+
141+ $ response = $ this ->actingAs ($ user )->postJson ('/api/client/account/api-keys ' , [
142+ 'description ' => str_repeat ('a ' , 501 ),
143+ 'allowed_ips ' => ['127.0.0.1 ' ],
144+ ]);
145+
146+ $ response ->assertStatus (Response::HTTP_UNPROCESSABLE_ENTITY );
147+ $ response ->assertJsonPath ('errors.0.meta.rule ' , 'max ' );
148+ $ response ->assertJsonPath ('errors.0.detail ' , 'The description may not be greater than 500 characters. ' );
138149 }
139150
140151 /**
You can’t perform that action at this time.
0 commit comments