Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Penner <[email protected]>
  • Loading branch information
matthewpi committed Oct 22, 2024
1 parent b8c41f8 commit 7df927c
Show file tree
Hide file tree
Showing 34 changed files with 40 additions and 148 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
MYSQL_DATABASE: testing
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Code Checkout
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ public function testDeleteUser()
/**
* Test that an API key without write permissions cannot create, update, or
* delete a user model.
*
* @dataProvider userWriteEndpointsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('userWriteEndpointsDataProvider')]
public function testApiKeyWithoutWritePermissions(string $method, string $url)
{
$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => AdminAcl::READ]);
Expand Down
3 changes: 1 addition & 2 deletions tests/Integration/Api/Client/ApiKeyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public function testApiKeysAreReturned()
* Test that an API key can be created for the client account. This also checks that the
* API key secret is returned as metadata in the response since it will not be returned
* after that point.
*
* @dataProvider validIPAddressDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('validIPAddressDataProvider')]
public function testApiKeyCanBeCreatedForAccount(array $data)
{
/** @var \Pterodactyl\Models\User $user */
Expand Down
3 changes: 1 addition & 2 deletions tests/Integration/Api/Client/ClientControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,8 @@ public function testAllServersAreReturnedToAdmin()
/**
* Test that no servers get returned if the user requests all admin level servers by using
* ?type=admin or ?type=admin-all in the request.
*
* @dataProvider filterTypeDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('filterTypeDataProvider')]
public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser(string $type)
{
/** @var \Pterodactyl\Models\User[] $users */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class AllocationAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* @dataProvider methodDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('methodDataProvider')]
public function testAccessToAServersAllocationsIsRestrictedProperly(string $method, string $endpoint)
{
// The API $user is the owner of $server1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public function setUp(): void

/**
* Tests that a new allocation can be properly assigned to a server.
*
* @dataProvider permissionDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionDataProvider')]
public function testNewAllocationCanBeAssignedToServer(array $permission)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class DeleteAllocationTest extends ClientApiIntegrationTestCase
/**
* Test that an allocation is deleted from the server and the notes are properly reset
* to an empty value on assignment.
*
* @dataProvider permissionDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionDataProvider')]
public function testAllocationCanBeDeletedFromServer(array $permission)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class BackupAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* @dataProvider methodDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('methodDataProvider')]
public function testAccessToAServersBackupIsRestrictedProperly(string $method, string $endpoint)
{
// The API $user is the owner of $server1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

class DatabaseAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* @dataProvider methodDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('methodDataProvider')]
public function testAccessToAServersDatabasesIsRestrictedProperly(string $method, string $endpoint)
{
// The API $user is the owner of $server1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public function testServerAllocationsAreNotReturnedWithoutPermission()

/**
* Tests that notes on an allocation can be set correctly.
*
* @dataProvider updatePermissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('updatePermissionsDataProvider')]
public function testAllocationNotesCanBeUpdated(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down Expand Up @@ -96,9 +95,7 @@ public function testAllocationNotesCannotBeUpdatedByInvalidUsers()
$this->actingAs($user)->postJson($this->link($server->allocation))->assertForbidden();
}

/**
* @dataProvider updatePermissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('updatePermissionsDataProvider')]
public function testPrimaryAllocationCanBeModified(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
6 changes: 2 additions & 4 deletions tests/Integration/Api/Client/Server/PowerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class PowerControllerTest extends ClientApiIntegrationTestCase
* the command to the server.
*
* @param string[] $permissions
*
* @dataProvider invalidPermissionDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('invalidPermissionDataProvider')]
public function testSubuserWithoutPermissionsReceivesError(string $action, array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down Expand Up @@ -45,9 +44,8 @@ public function testInvalidPowerSignalResultsInError()

/**
* Test that sending a valid power actions works.
*
* @dataProvider validPowerActionDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('validPowerActionDataProvider')]
public function testActionCanBeSentToServer(string $action, string $permission)
{
$service = \Mockery::mock(DaemonPowerRepository::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class CreateServerScheduleTest extends ClientApiIntegrationTestCase
{
/**
* Test that a schedule can be created for the server.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testScheduleCanBeCreatedForServer(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase
{
/**
* Test that a schedule can be deleted from the system.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testScheduleCanBeDeleted(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase
{
/**
* Test that a schedule can be executed and is updated in the database correctly.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testScheduleIsExecutedRightAway(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ protected function tearDown(): void

/**
* Test that schedules for a server are returned.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testServerSchedulesAreReturned(array $permissions, bool $individual)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class ScheduleAuthorizationTest extends ClientApiIntegrationTestCase
*
* The comments within the test code itself are better at explaining exactly what is
* being tested and protected against.
*
* @dataProvider methodDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('methodDataProvider')]
public function testAccessToAServersSchedulesIsRestrictedProperly(string $method, string $endpoint)
{
// The API $user is the owner of $server1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase

/**
* Test that a schedule can be updated.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testScheduleCanBeUpdated(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase
{
/**
* Test that a task can be created.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testTaskCanBeCreated(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
{
/**
* Test that the server's name can be changed.
*
* @dataProvider renamePermissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('renamePermissionsDataProvider')]
public function testServerNameCanBeChanged(array $permissions)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down Expand Up @@ -68,9 +67,8 @@ public function testSubuserCannotChangeServerNameWithoutPermission()
/**
* Test that a server can be reinstalled. Honestly this test doesn't do much of anything other
* than make sure the endpoint works since.
*
* @dataProvider reinstallPermissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('reinstallPermissionsDataProvider')]
public function testServerCanBeReinstalled(array $permissions)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class GetStartupAndVariablesTest extends ClientApiIntegrationTestCase
/**
* Test that the startup command and variables are returned for a server, but only the variables
* that can be viewed by a user (e.g. user_viewable=true).
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testStartupVariablesAreReturnedForServer(array $permissions)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class UpdateStartupVariableTest extends ClientApiIntegrationTestCase
{
/**
* Test that a startup variable can be edited successfully for a server.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testStartupVariableCanBeUpdated(array $permissions)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down Expand Up @@ -47,9 +46,8 @@ public function testStartupVariableCanBeUpdated(array $permissions)
/**
* Test that variables that are either not user_viewable, or not user_editable, cannot be
* updated via this endpoint.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testStartupVariableCannotBeUpdatedIfNotUserViewableOrEditable(array $permissions)
{
/** @var \Pterodactyl\Models\Server $server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase

/**
* Test that a subuser can be created for a server.
*
* @dataProvider permissionsDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('permissionsDataProvider')]
public function testSubuserCanBeCreated(array $permissions)
{
[$user, $server] = $this->generateTestAccount($permissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class SubuserAuthorizationTest extends ClientApiIntegrationTestCase
{
/**
* Test that mismatched subusers are not accessible to a server.
*
* @dataProvider methodDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('methodDataProvider')]
public function testUserCannotAccessResourceBelongingToOtherServers(string $method)
{
// Generic subuser, the specific resource we're trying to access.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,8 @@ public function testPasswordIsValidatedCorrectly()
/**
* Test that providing an invalid key and/or invalid username triggers the throttle on
* the endpoint.
*
* @dataProvider authorizationTypeDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('authorizationTypeDataProvider')]
public function testUserIsThrottledIfInvalidCredentialsAreProvided()
{
for ($i = 0; $i <= 10; ++$i) {
Expand Down Expand Up @@ -128,9 +127,8 @@ public function testUserIsNotThrottledIfNoPublicKeyMatches()
/**
* Test that a request is rejected if the credentials are valid but the username indicates
* a server on a different node.
*
* @dataProvider authorizationTypeDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('authorizationTypeDataProvider')]
public function testRequestIsRejectedIfServerBelongsToDifferentNode(string $type)
{
$node2 = $this->createServerModel()->node;
Expand Down Expand Up @@ -165,9 +163,7 @@ public function testRequestIsDeniedIfUserLacksSftpPermission()
->assertJsonPath('errors.0.detail', 'You do not have permission to access SFTP for this server.');
}

/**
* @dataProvider serverStateDataProvider
*/
#[\PHPUnit\Framework\Attributes\DataProvider('serverStateDataProvider')]
public function testInvalidServerStateReturnsConflictError(string $status)
{
$this->server->update(['status' => $status]);
Expand Down
59 changes: 0 additions & 59 deletions tests/Integration/Http/Controllers/Admin/UserControllerTest.php

This file was deleted.

Loading

0 comments on commit 7df927c

Please sign in to comment.