Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagolizardo committed Jan 26, 2024
1 parent 8869ae0 commit 64c2a1e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ services:

keycloak:
image: quay.io/reconmap/keycloak-custom:latest
command:
- "start --auto-build --http-enabled=true --hostname=localhost --proxy=edge --hostname-strict-https=false --import-realm"
command: "start --http-enabled=true --hostname=localhost --proxy=edge --hostname-strict-https=false --import-realm"
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/Commands/UpdateCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __invoke(ServerRequestInterface $request, array $args): array
$success = $this->repository->updateById($commandId, $newColumnValues);

$loggedInUserId = $request->getAttribute('userId');

$this->auditAction($loggedInUserId, $commandId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/SecureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(private readonly AuthorisationService $authorisation
{
}

public function __invoke(ServerRequestInterface $request, array $args): array|ResponseInterface
public function __invoke(ServerRequestInterface $request, ?array $args = []): array|ResponseInterface
{
$role = $request->getAttribute('role');
if (!$this->authorisationService->isRoleAllowed($role, $this->getPermissionRequired())) {
Expand Down
3 changes: 2 additions & 1 deletion src/Repositories/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ protected function getBaseSelectQueryBuilder(): SelectQueryBuilder
p.name AS project_name, p.is_template AS project_is_template,
t.creator_uid, creator.full_name AS creator_full_name,
t.assignee_uid, assignee.full_name AS assignee_full_name,
c.id AS command_id, c.name AS command_name, c.output_parser, c.docker_image AS command_docker_image, c.arguments AS command_container_args
c.id AS command_id, c.name AS command_name, cu.output_parser, cu.docker_image AS command_docker_image, cu.arguments AS command_container_args
');
$queryBuilder->addJoin('INNER JOIN user creator ON (creator.id = t.creator_uid)');
$queryBuilder->addJoin('LEFT JOIN user assignee ON (assignee.id = t.assignee_uid)');
$queryBuilder->addJoin('LEFT JOIN project p ON (p.id = t.project_id)');
$queryBuilder->addJoin('LEFT JOIN command c ON (c.id = t.command_id)');
$queryBuilder->addJoin('LEFT JOIN command_usage cu ON (cu.command_id = t.command_id)');
$queryBuilder->setOrderBy('t.insert_ts DESC');
return $queryBuilder;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Controllers/Commands/UpdateCommandControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testHappyPath()
$mockRequest = $this->createMock(ServerRequestInterface::class);
$mockRequest->expects($this->once())
->method('getBody')
->willReturn('{"executable_path": "nmap"}');
->willReturn('{"name": "nmap"}');
$mockRequest->expects($this->once())
->method('getAttribute')
->with('userId')
Expand All @@ -26,7 +26,7 @@ public function testHappyPath()
$mockTaskRepository = $this->createMock(CommandRepository::class);
$mockTaskRepository->expects($this->once())
->method('updateById')
->with($fakeCommandId, ['executable_path' => 'nmap'])
->with($fakeCommandId, ['name' => 'nmap'])
->willReturn(true);

$mockPublisherService = $this->createMock(ActivityPublisherService::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/Repositories/CommandRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function testInsert()
public function testFindAll()
{
$commands = $this->subject->findAll();
$this->assertCount(5, $commands);
$this->assertCount(6, $commands);
}


public function testFindById()
{
$command = $this->subject->findById(1);
$this->assertEquals('Goohost', $command['name']);
$this->assertEquals('nmap', $command['name']);
}

public function testFindByIdNotFound()
Expand Down
4 changes: 2 additions & 2 deletions tests/Repositories/TaskRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setUp(): void
public function testFindAllReturnsProjectInformation()
{
$tasks = $this->subject->findAll();
$this->assertCount(17, $tasks);
$this->assertCount(19, $tasks);
$task = $tasks[0];
$this->assertArrayHasKey('project_id', $task);
$this->assertArrayHasKey('project_name', $task);
Expand All @@ -26,7 +26,7 @@ public function testFindAllReturnsProjectInformation()
public function testFindByKeywords()
{
$tasks = $this->subject->findByKeywords('scanner');
$this->assertCount(6, $tasks);
$this->assertCount(8, $tasks);
$this->assertEquals('Run port scanner', $tasks[0]['summary']);
}

Expand Down

0 comments on commit 64c2a1e

Please sign in to comment.