tests: more fixes, but stuff is still broken

This commit is contained in:
Matthew Penner 2022-12-14 19:53:07 -07:00
parent 10b2380e9e
commit 7f669828c6
No known key found for this signature in database
10 changed files with 36 additions and 85 deletions

View file

@ -224,7 +224,7 @@ class User extends Model implements
public function avatarURL(): string public function avatarURL(): string
{ {
return 'https://www.gravatar.com/avatar/' . md5($this->email) . '.jpg'; return 'https://www.gravatar.com/avatar/' . $this->md5 . '.jpg';
} }
/** /**

View file

@ -91,6 +91,8 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase
/** /**
* Return a transformer that can be used for testing purposes. * Return a transformer that can be used for testing purposes.
*
* @deprecated Instantiate the transformer directly.
*/ */
protected function getTransformer(string $abstract): Transformer protected function getTransformer(string $abstract): Transformer
{ {

View file

@ -125,13 +125,4 @@ class EggControllerTest extends ApplicationApiIntegrationTestCase
{ {
$this->markTestSkipped('todo: implement proper admin api key permissions system'); $this->markTestSkipped('todo: implement proper admin api key permissions system');
} }
/**
* Test that a nests's existence is not exposed unless an API key has permission
* to access the resource.
*/
public function testResourceIsNotExposedWithoutPermissions()
{
$this->markTestSkipped('todo: implement proper admin api key permissions system');
}
} }

View file

@ -259,10 +259,6 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testErrorReturnedIfNoPermission() public function testErrorReturnedIfNoPermission()
{ {
$location = Location::factory()->create(); $this->markTestSkipped('todo: implement proper admin api key permissions system');
$this->createNewDefaultApiKey($this->getApiUser(), ['r_locations' => 0]);
$response = $this->getJson('/api/application/locations/' . $location->id);
$this->assertAccessDeniedJson($response);
} }
} }

View file

@ -45,7 +45,7 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
'pagination' => [ 'pagination' => [
'total' => 4, 'total' => 4,
'count' => 4, 'count' => 4,
'per_page' => 50, 'per_page' => 10,
'current_page' => 1, 'current_page' => 1,
'total_pages' => 1, 'total_pages' => 1,
], ],
@ -118,10 +118,6 @@ class NestControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testErrorReturnedIfNoPermission() public function testErrorReturnedIfNoPermission()
{ {
$nest = $this->repository->find(1); $this->markTestSkipped('todo: implement proper admin api key permissions system');
$this->createNewDefaultApiKey($this->getApiUser(), ['r_nests' => 0]);
$response = $this->getJson('/api/application/nests/' . $nest->id);
$this->assertAccessDeniedJson($response);
} }
} }

View file

@ -37,7 +37,7 @@ class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase
'email' => $user->email, 'email' => $user->email,
'language' => $user->language, 'language' => $user->language,
'root_admin' => (bool) $user->root_admin, 'root_admin' => (bool) $user->root_admin,
'2fa' => (bool) $user->totp_enabled, '2fa' => (bool) $user->use_totp,
'created_at' => $this->formatTimestamp($user->created_at), 'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at), 'updated_at' => $this->formatTimestamp($user->updated_at),
], ],
@ -59,10 +59,6 @@ class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testErrorReturnedIfNoPermission() public function testErrorReturnedIfNoPermission()
{ {
$user = User::factory()->create(['external_id' => Str::random()]); $this->markTestSkipped('todo: implement proper admin api key permissions system');
$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]);
$response = $this->getJson('/api/application/users/external/' . $user->external_id);
$this->assertAccessDeniedJson($response);
} }
} }

View file

@ -4,7 +4,6 @@ namespace Pterodactyl\Tests\Integration\Api\Application\Users;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Transformers\Api\Application\UserTransformer; use Pterodactyl\Transformers\Api\Application\UserTransformer;
use Pterodactyl\Transformers\Api\Application\ServerTransformer; use Pterodactyl\Transformers\Api\Application\ServerTransformer;
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase; use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
@ -24,8 +23,8 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJsonStructure([ $response->assertJsonStructure([
'object', 'object',
'data' => [ 'data' => [
['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'root_admin', '2fa', 'created_at', 'updated_at']], ['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'admin_role_id', 'root_admin', '2fa', 'avatar_url', 'role_name', 'created_at', 'updated_at']],
['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'root_admin', '2fa', 'created_at', 'updated_at']], ['object', 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'admin_role_id', 'root_admin', '2fa', 'avatar_url', 'role_name', 'created_at', 'updated_at']],
], ],
'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages']], 'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages']],
]); ]);
@ -53,8 +52,11 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
'username' => $this->getApiUser()->username, 'username' => $this->getApiUser()->username,
'email' => $this->getApiUser()->email, 'email' => $this->getApiUser()->email,
'language' => $this->getApiUser()->language, 'language' => $this->getApiUser()->language,
'admin_role_id' => $this->getApiUser()->admin_role_id,
'root_admin' => $this->getApiUser()->root_admin, 'root_admin' => $this->getApiUser()->root_admin,
'2fa' => $this->getApiUser()->use_totp, '2fa' => $this->getApiUser()->use_totp,
'avatar_url' => $this->getApiUser()->avatarURL(),
'role_name' => $this->getApiUser()->adminRoleName(),
'created_at' => $this->formatTimestamp($this->getApiUser()->created_at), 'created_at' => $this->formatTimestamp($this->getApiUser()->created_at),
'updated_at' => $this->formatTimestamp($this->getApiUser()->updated_at), 'updated_at' => $this->formatTimestamp($this->getApiUser()->updated_at),
], ],
@ -68,8 +70,11 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
'username' => $user->username, 'username' => $user->username,
'email' => $user->email, 'email' => $user->email,
'language' => $user->language, 'language' => $user->language,
'admin_role_id' => $user->admin_role_id,
'root_admin' => (bool) $user->root_admin, 'root_admin' => (bool) $user->root_admin,
'2fa' => (bool) $user->use_totp, '2fa' => (bool) $user->use_totp,
'avatar_url' => $user->avatarURL(),
'role_name' => $user->adminRoleName(),
'created_at' => $this->formatTimestamp($user->created_at), 'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at), 'updated_at' => $this->formatTimestamp($user->updated_at),
], ],
@ -88,7 +93,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJsonCount(2); $response->assertJsonCount(2);
$response->assertJsonStructure([ $response->assertJsonStructure([
'object', 'object',
'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'root_admin', '2fa', 'created_at', 'updated_at'], 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'admin_role_id', 'root_admin', '2fa', 'avatar_url', 'role_name', 'created_at', 'updated_at'],
]); ]);
$response->assertJson([ $response->assertJson([
@ -100,8 +105,11 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
'username' => $user->username, 'username' => $user->username,
'email' => $user->email, 'email' => $user->email,
'language' => $user->language, 'language' => $user->language,
'admin_role_id' => $user->admin_role_id,
'root_admin' => (bool) $user->root_admin, 'root_admin' => (bool) $user->root_admin,
'2fa' => (bool) $user->totp_enabled, '2fa' => (bool) $user->use_totp,
'avatar_url' => $user->avatarURL(),
'role_name' => $user->adminRoleName(),
'created_at' => $this->formatTimestamp($user->created_at), 'created_at' => $this->formatTimestamp($user->created_at),
'updated_at' => $this->formatTimestamp($user->updated_at), 'updated_at' => $this->formatTimestamp($user->updated_at),
], ],
@ -122,7 +130,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJsonStructure([ $response->assertJsonStructure([
'object', 'object',
'attributes' => [ 'attributes' => [
'id', 'external_id', 'uuid', 'username', 'email', 'language', 'root_admin', '2fa', 'created_at', 'updated_at', 'id', 'external_id', 'uuid', 'username', 'email', 'language', 'admin_role_id', 'root_admin', '2fa', 'avatar_url', 'role_name', 'created_at', 'updated_at',
'relationships' => ['servers' => ['object', 'data' => [['object', 'attributes' => []]]]], 'relationships' => ['servers' => ['object', 'data' => [['object', 'attributes' => []]]]],
], ],
]); ]);
@ -144,33 +152,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testKeyWithoutPermissionCannotLoadRelationship() public function testKeyWithoutPermissionCannotLoadRelationship()
{ {
$this->createNewDefaultApiKey($this->getApiUser(), ['r_servers' => 0]); $this->markTestSkipped('todo: implement proper admin api key permissions system');
$user = User::factory()->create();
$this->createServerModel(['user_id' => $user->id]);
$response = $this->getJson('/api/application/users/' . $user->id . '?include=servers');
$response->assertStatus(Response::HTTP_OK);
$response->assertJsonCount(2)->assertJsonCount(1, 'attributes.relationships');
$response->assertJsonStructure([
'attributes' => [
'relationships' => [
'servers' => ['object', 'attributes'],
],
],
]);
// Just assert that we see the expected relationship IDs in the response.
$response->assertJson([
'attributes' => [
'relationships' => [
'servers' => [
'object' => 'null_resource',
'attributes' => null,
],
],
],
]);
} }
/** /**
@ -188,11 +170,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testErrorReturnedIfNoPermission() public function testErrorReturnedIfNoPermission()
{ {
$user = User::factory()->create(); $this->markTestSkipped('todo: implement proper admin api key permissions system');
$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]);
$response = $this->getJson('/api/application/users/' . $user->id);
$this->assertAccessDeniedJson($response);
} }
/** /**
@ -209,7 +187,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJsonCount(3); $response->assertJsonCount(3);
$response->assertJsonStructure([ $response->assertJsonStructure([
'object', 'object',
'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'root_admin', '2fa', 'created_at', 'updated_at'], 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'admin_role_id', 'root_admin', '2fa', 'avatar_url', 'role_name', 'created_at', 'updated_at'],
'meta' => ['resource'], 'meta' => ['resource'],
]); ]);
@ -240,7 +218,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
$response->assertJsonCount(2); $response->assertJsonCount(2);
$response->assertJsonStructure([ $response->assertJsonStructure([
'object', 'object',
'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'root_admin', '2fa', 'created_at', 'updated_at'], 'attributes' => ['id', 'external_id', 'uuid', 'username', 'email', 'language', 'admin_role_id', 'root_admin', '2fa', 'avatar_url', 'role_name', 'created_at', 'updated_at'],
]); ]);
$this->assertDatabaseHas('users', ['username' => 'new.test.name', 'email' => 'new@emailtest.com']); $this->assertDatabaseHas('users', ['username' => 'new.test.name', 'email' => 'new@emailtest.com']);
@ -274,15 +252,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase
*/ */
public function testApiKeyWithoutWritePermissions(string $method, string $url) public function testApiKeyWithoutWritePermissions(string $method, string $url)
{ {
$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => AdminAcl::READ]); $this->markTestSkipped('todo: implement proper admin api key permissions system');
if (str_contains($url, '{id}')) {
$user = User::factory()->create();
$url = str_replace('{id}', $user->id, $url);
}
$response = $this->$method($url);
$this->assertAccessDeniedJson($response);
} }
/** /**

View file

@ -14,10 +14,10 @@ use Pterodactyl\Models\Schedule;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Pterodactyl\Models\Allocation; use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\DatabaseHost; use Pterodactyl\Models\DatabaseHost;
use Pterodactyl\Transformers\Api\Transformer;
use Pterodactyl\Tests\Integration\TestResponse; use Pterodactyl\Tests\Integration\TestResponse;
use Pterodactyl\Tests\Integration\IntegrationTestCase; use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Illuminate\Database\Eloquent\Model as EloquentModel; use Illuminate\Database\Eloquent\Model as EloquentModel;
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
abstract class ClientApiIntegrationTestCase extends IntegrationTestCase abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
{ {
@ -89,7 +89,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
$transformer = sprintf('\\Pterodactyl\\Transformers\\Api\\Client\\%sTransformer', $reflect->getShortName()); $transformer = sprintf('\\Pterodactyl\\Transformers\\Api\\Client\\%sTransformer', $reflect->getShortName());
$transformer = new $transformer(); $transformer = new $transformer();
$this->assertInstanceOf(BaseClientTransformer::class, $transformer); $this->assertInstanceOf(Transformer::class, $transformer);
$this->assertSame( $this->assertSame(
$transformer->transform($model), $transformer->transform($model),

View file

@ -88,7 +88,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testCreatingDatabaseWithIdenticalNameTriggersAnException() public function testCreatingDatabaseWithIdenticalNameTriggersAnException()
{ {
$server = $this->createServerModel(); $server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id); $name = DatabaseManagementService::generateUniqueDatabaseName('something', $server->id);
$host = DatabaseHost::factory()->create(); $host = DatabaseHost::factory()->create();
$host2 = DatabaseHost::factory()->create(); $host2 = DatabaseHost::factory()->create();
@ -117,7 +117,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testServerDatabaseCanBeCreated() public function testServerDatabaseCanBeCreated()
{ {
$server = $this->createServerModel(); $server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id); $name = DatabaseManagementService::generateUniqueDatabaseName('something', $server->id);
$host = DatabaseHost::factory()->create(); $host = DatabaseHost::factory()->create();
@ -175,7 +175,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testExceptionEncounteredWhileCreatingDatabaseAttemptsToCleanup() public function testExceptionEncounteredWhileCreatingDatabaseAttemptsToCleanup()
{ {
$server = $this->createServerModel(); $server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id); $name = DatabaseManagementService::generateUniqueDatabaseName('something', $server->id);
$host = DatabaseHost::factory()->create(); $host = DatabaseHost::factory()->create();

View file

@ -61,8 +61,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{ {
$server = $this->createServerModel(); $server = $this->createServerModel();
$host = DatabaseHost::factory()->create();
$node = Node::factory()->create(['location_id' => $server->location->id]); $node = Node::factory()->create(['location_id' => $server->location->id]);
DatabaseHost::factory()->create();
config()->set('pterodactyl.client_features.databases.allow_random', false); config()->set('pterodactyl.client_features.databases.allow_random', false);
@ -96,9 +96,9 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{ {
$server = $this->createServerModel(); $server = $this->createServerModel();
$node = Node::factory()->create(['location_id' => $server->location->id]); $node = Node::factory()->create(['location_id' => $server->location->id, 'database_host_id' => DatabaseHost::factory()->create()->id]);
DatabaseHost::factory()->create();
$host = DatabaseHost::factory()->create(); $host = DatabaseHost::factory()->create();
$server->node->database_host_id = $host->id;
$this->managementService->expects('create')->with($server, [ $this->managementService->expects('create')->with($server, [
'database_host_id' => $host->id, 'database_host_id' => $host->id,
@ -123,8 +123,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{ {
$server = $this->createServerModel(); $server = $this->createServerModel();
$node = Node::factory()->create(['location_id' => $server->location->id]);
$host = DatabaseHost::factory()->create(); $host = DatabaseHost::factory()->create();
$node = Node::factory()->create(['location_id' => $server->location->id, 'database_host_id' => $host->id]);
$this->managementService->expects('create')->with($server, [ $this->managementService->expects('create')->with($server, [
'database_host_id' => $host->id, 'database_host_id' => $host->id,