Add support for allowing subusers to access SFTP. (#918)
This commit is contained in:
parent
f61a5fa0cb
commit
d8be167a9c
10 changed files with 64 additions and 70 deletions
|
@ -11,6 +11,7 @@ use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
|
|||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Services\Sftp\AuthenticateUsingPasswordService;
|
||||
use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;
|
||||
|
||||
class AuthenticateUsingPasswordServiceTest extends TestCase
|
||||
{
|
||||
|
@ -23,6 +24,11 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\SubuserRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
private $subuserRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
|
||||
|
@ -38,6 +44,7 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
|
||||
$this->keyProviderService = m::mock(DaemonKeyProviderService::class);
|
||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
||||
$this->subuserRepository = m::mock(SubuserRepositoryInterface::class);
|
||||
$this->userRepository = m::mock(UserRepositoryInterface::class);
|
||||
}
|
||||
|
||||
|
@ -130,8 +137,8 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is thrown if the user is not the owner of the server
|
||||
* and is not an administrator.
|
||||
* Test that an exception is thrown if the user is not the owner of the server,
|
||||
* is not a sub user and is not an administrator.
|
||||
*
|
||||
* @expectedException \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
|
@ -146,6 +153,8 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid', 'installed', 'suspended'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->subuserRepository->shouldReceive('getWithPermissionsUsingUserAndServer')->with($user->id, $server->id)->once()->andThrow(new RecordNotFoundException);
|
||||
|
||||
$this->getService()->handle($user->username, 'password', 1, $server->uuidShort);
|
||||
}
|
||||
|
||||
|
@ -214,6 +223,6 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
*/
|
||||
private function getService(): AuthenticateUsingPasswordService
|
||||
{
|
||||
return new AuthenticateUsingPasswordService($this->keyProviderService, $this->repository, $this->userRepository);
|
||||
return new AuthenticateUsingPasswordService($this->keyProviderService, $this->repository, $this->subuserRepository, $this->userRepository);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,12 +42,11 @@ class PermissionCreationServiceTest extends TestCase
|
|||
*/
|
||||
public function testPermissionsAreAssignedCorrectly()
|
||||
{
|
||||
$permissions = ['reset-sftp', 'view-sftp'];
|
||||
$permissions = ['access-sftp'];
|
||||
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('insert')->with([
|
||||
['subuser_id' => 1, 'permission' => 'reset-sftp'],
|
||||
['subuser_id' => 1, 'permission' => 'view-sftp'],
|
||||
['subuser_id' => 1, 'permission' => 'access-sftp'],
|
||||
])->once()->andReturn(true);
|
||||
|
||||
$this->service->handle(1, $permissions);
|
||||
|
|
|
@ -121,7 +121,7 @@ class SubuserCreationServiceTest extends TestCase
|
|||
*/
|
||||
public function testExistingUserCanBeAddedAsASubuser()
|
||||
{
|
||||
$permissions = ['view-sftp', 'reset-sftp'];
|
||||
$permissions = ['access-sftp'];
|
||||
$server = factory(Server::class)->make();
|
||||
$user = factory(User::class)->make();
|
||||
$subuser = factory(Subuser::class)->make(['user_id' => $user->id, 'server_id' => $server->id]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue