Skip to content

Commit 4122486

Browse files
committed
Fix failing tests (which caught a bug in the new client query)
1 parent 82d7fa1 commit 4122486

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

app/Models/RecoveryToken.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class RecoveryToken extends Model
1717
*/
1818
const UPDATED_AT = null;
1919

20+
/**
21+
* @var bool
22+
*/
23+
public $timestamps = true;
24+
2025
/**
2126
* @var bool
2227
*/

app/Models/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ public function recoveryTokens()
266266
* Returns all of the servers that a user can access by way of being the owner of the
267267
* server, or because they are assigned as a subuser for that server.
268268
*
269-
* @return \Illuminate\Database\Eloquent\Relations\HasMany
269+
* @return \Illuminate\Database\Eloquent\Builder
270270
*/
271271
public function accessibleServers()
272272
{
273-
return $this->hasMany(Server::class, 'owner_id')
273+
return Server::query()
274274
->select('servers.*')
275275
->leftJoin('subusers', 'subusers.server_id', '=', 'servers.id')
276276
->where(function (Builder $builder) {

tests/Integration/Api/Client/ClientControllerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testOnlyLoggedInUsersServersAreReturned()
3535
$response->assertJsonPath('data.0.attributes.identifier', $servers[0]->uuidShort);
3636
$response->assertJsonPath('data.0.attributes.server_owner', true);
3737
$response->assertJsonPath('meta.pagination.total', 1);
38-
$response->assertJsonPath('meta.pagination.per_page', config('pterodactyl.paginate.frontend.servers'));
38+
$response->assertJsonPath('meta.pagination.per_page', 50);
3939
}
4040

4141
/**
@@ -54,7 +54,7 @@ public function testFilterIncludeAllServersWhenAdministrator()
5454
$this->createServerModel(['user_id' => $users[2]->id]),
5555
];
5656

57-
$response = $this->actingAs($users[0])->getJson('/api/client?filter=all');
57+
$response = $this->actingAs($users[0])->getJson('/api/client?type=all');
5858

5959
$response->assertOk();
6060
$response->assertJsonCount(3, 'data');
@@ -117,7 +117,7 @@ public function testFilterOnlyOwnerServers()
117117
'permissions' => [Permission::ACTION_WEBSOCKET_CONNECT],
118118
]);
119119

120-
$response = $this->actingAs($users[0])->getJson('/api/client?filter=owner');
120+
$response = $this->actingAs($users[0])->getJson('/api/client?type=owner');
121121

122122
$response->assertOk();
123123
$response->assertJsonCount(1, 'data');

tests/Integration/Api/Client/TwoFactorControllerTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Pterodactyl\Models\User;
77
use Illuminate\Http\Response;
88
use PragmaRX\Google2FA\Google2FA;
9+
use Pterodactyl\Models\RecoveryToken;
10+
use PHPUnit\Framework\ExpectationFailedException;
911

1012
class TwoFactorControllerTest extends ClientApiIntegrationTestCase
1113
{
@@ -89,11 +91,29 @@ public function testTwoFactorCanBeEnabledOnAccount()
8991
'code' => $token,
9092
]);
9193

92-
$response->assertStatus(Response::HTTP_NO_CONTENT);
94+
$response->assertOk();
95+
$response->assertJsonPath('object', 'recovery_tokens');
9396

9497
$user = $user->refresh();
95-
9698
$this->assertTrue($user->use_totp);
99+
100+
$tokens = RecoveryToken::query()->where('user_id', $user->id)->get();
101+
$this->assertCount(10, $tokens);
102+
$this->assertStringStartsWith('$2y$10$', $tokens[0]->token);
103+
104+
$tokens = $tokens->pluck('token')->toArray();
105+
106+
foreach ($response->json('attributes.tokens') as $raw) {
107+
foreach ($tokens as $hashed) {
108+
if (password_verify($raw, $hashed)) {
109+
continue 2;
110+
}
111+
}
112+
113+
throw new ExpectationFailedException(
114+
sprintf('Failed asserting that token [%s] exists as a hashed value in recovery_tokens table.', $raw)
115+
);
116+
}
97117
}
98118

99119
/**

0 commit comments

Comments
 (0)