Skip to content

Commit 64c2a1e

Browse files
Fix unit tests
1 parent 8869ae0 commit 64c2a1e

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

docker-compose.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ services:
3434

3535
keycloak:
3636
image: quay.io/reconmap/keycloak-custom:latest
37-
command:
38-
- "start --auto-build --http-enabled=true --hostname=localhost --proxy=edge --hostname-strict-https=false --import-realm"
37+
command: "start --http-enabled=true --hostname=localhost --proxy=edge --hostname-strict-https=false --import-realm"
3938
environment:
4039
KEYCLOAK_ADMIN: admin
4140
KEYCLOAK_ADMIN_PASSWORD: admin

src/Controllers/Commands/UpdateCommandController.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __invoke(ServerRequestInterface $request, array $args): array
3131
$success = $this->repository->updateById($commandId, $newColumnValues);
3232

3333
$loggedInUserId = $request->getAttribute('userId');
34+
3435
$this->auditAction($loggedInUserId, $commandId);
3536
}
3637

src/Controllers/SecureController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function __construct(private readonly AuthorisationService $authorisation
1212
{
1313
}
1414

15-
public function __invoke(ServerRequestInterface $request, array $args): array|ResponseInterface
15+
public function __invoke(ServerRequestInterface $request, ?array $args = []): array|ResponseInterface
1616
{
1717
$role = $request->getAttribute('role');
1818
if (!$this->authorisationService->isRoleAllowed($role, $this->getPermissionRequired())) {

src/Repositories/TaskRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ protected function getBaseSelectQueryBuilder(): SelectQueryBuilder
8686
p.name AS project_name, p.is_template AS project_is_template,
8787
t.creator_uid, creator.full_name AS creator_full_name,
8888
t.assignee_uid, assignee.full_name AS assignee_full_name,
89-
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
89+
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
9090
');
9191
$queryBuilder->addJoin('INNER JOIN user creator ON (creator.id = t.creator_uid)');
9292
$queryBuilder->addJoin('LEFT JOIN user assignee ON (assignee.id = t.assignee_uid)');
9393
$queryBuilder->addJoin('LEFT JOIN project p ON (p.id = t.project_id)');
9494
$queryBuilder->addJoin('LEFT JOIN command c ON (c.id = t.command_id)');
95+
$queryBuilder->addJoin('LEFT JOIN command_usage cu ON (cu.command_id = t.command_id)');
9596
$queryBuilder->setOrderBy('t.insert_ts DESC');
9697
return $queryBuilder;
9798
}

tests/Controllers/Commands/UpdateCommandControllerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testHappyPath()
1717
$mockRequest = $this->createMock(ServerRequestInterface::class);
1818
$mockRequest->expects($this->once())
1919
->method('getBody')
20-
->willReturn('{"executable_path": "nmap"}');
20+
->willReturn('{"name": "nmap"}');
2121
$mockRequest->expects($this->once())
2222
->method('getAttribute')
2323
->with('userId')
@@ -26,7 +26,7 @@ public function testHappyPath()
2626
$mockTaskRepository = $this->createMock(CommandRepository::class);
2727
$mockTaskRepository->expects($this->once())
2828
->method('updateById')
29-
->with($fakeCommandId, ['executable_path' => 'nmap'])
29+
->with($fakeCommandId, ['name' => 'nmap'])
3030
->willReturn(true);
3131

3232
$mockPublisherService = $this->createMock(ActivityPublisherService::class);

tests/Repositories/CommandRepositoryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public function testInsert()
2929
public function testFindAll()
3030
{
3131
$commands = $this->subject->findAll();
32-
$this->assertCount(5, $commands);
32+
$this->assertCount(6, $commands);
3333
}
3434

3535

3636
public function testFindById()
3737
{
3838
$command = $this->subject->findById(1);
39-
$this->assertEquals('Goohost', $command['name']);
39+
$this->assertEquals('nmap', $command['name']);
4040
}
4141

4242
public function testFindByIdNotFound()

tests/Repositories/TaskRepositoryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function setUp(): void
1717
public function testFindAllReturnsProjectInformation()
1818
{
1919
$tasks = $this->subject->findAll();
20-
$this->assertCount(17, $tasks);
20+
$this->assertCount(19, $tasks);
2121
$task = $tasks[0];
2222
$this->assertArrayHasKey('project_id', $task);
2323
$this->assertArrayHasKey('project_name', $task);
@@ -26,7 +26,7 @@ public function testFindAllReturnsProjectInformation()
2626
public function testFindByKeywords()
2727
{
2828
$tasks = $this->subject->findByKeywords('scanner');
29-
$this->assertCount(6, $tasks);
29+
$this->assertCount(8, $tasks);
3030
$this->assertEquals('Run port scanner', $tasks[0]['summary']);
3131
}
3232

0 commit comments

Comments
 (0)