From 67da62280746c79d6a2d5bb030a37cc061205b37 Mon Sep 17 00:00:00 2001 From: dakriy Date: Sat, 27 Jun 2020 17:40:24 -0700 Subject: [PATCH] Fix tests and change xdebug port Make xdebug port default 9000 Fix some door access tests to be a little more comprehensive --- docker-compose.yml.example | 1 - php/dev.ini | 2 +- .../Schedules/LocalSchedulesRepository.php | 3 ++ .../tests/Feature/Door/DoorAccessTest.php | 49 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 92ab32f4..2b02d27f 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -104,7 +104,6 @@ services: - ./simple-saml-idp/config:/var/simplesamlphp-idp/config - ./simple-saml-idp/metadata:/var/simplesamlphp-idp/metadata ports: - - "9000:9000" - "8000:8000" logging: options: diff --git a/php/dev.ini b/php/dev.ini index a1a02ec9..8d0917ab 100644 --- a/php/dev.ini +++ b/php/dev.ini @@ -4,7 +4,7 @@ display_errors = On xdebug.remote_enable=1 xdebug.remote_connect_back=1 xdebug.idekey="PHPSTORM" -xdebug.remote_port=9999 +xdebug.remote_port=9000 xdebug.remote_autostart=1 # DockerNAT gateway IP xdebug.remote.host=host.docker.internal diff --git a/src/backend/src/Gateways/Schedules/LocalSchedulesRepository.php b/src/backend/src/Gateways/Schedules/LocalSchedulesRepository.php index 5e4d3227..7dd72576 100644 --- a/src/backend/src/Gateways/Schedules/LocalSchedulesRepository.php +++ b/src/backend/src/Gateways/Schedules/LocalSchedulesRepository.php @@ -9,6 +9,9 @@ use Source\Gateways\Groups\LocalGroupsRepository; class LocalSchedulesRepository extends InMemorySchedulesRepository { + /** + * @throws \Source\Exceptions\EntityNotFoundException + */ public function __construct() { $this->create(new Schedule( diff --git a/src/backend/tests/Feature/Door/DoorAccessTest.php b/src/backend/tests/Feature/Door/DoorAccessTest.php index a3c9578c..42e70ab1 100644 --- a/src/backend/tests/Feature/Door/DoorAccessTest.php +++ b/src/backend/tests/Feature/Door/DoorAccessTest.php @@ -4,8 +4,10 @@ namespace Tests\Feature\Door; use Carbon\Carbon; +use Source\Entities\User; use Source\Entities\Schedule; use Illuminate\Testing\TestResponse; +use Source\Entities\HashedSearchable; use Tests\Feature\AuthenticatesWithApplicationTestCase; use Source\Gateways\DoorSchedule\DoorScheduleRepository; use Source\Gateways\DoorSchedule\InMemoryDoorScheduleRepository; @@ -84,4 +86,51 @@ RSET; $this->response->assertStatus(200); } + + /** + * @test + * @throws \Source\Exceptions\EntityExistsException + */ + public function it_denies_invalid_users(): void + { + $this->authenticateAsDoor(); + + $this->authorizer->setNext(true); + + $this->handleTest('asdf'); + + $this->response->assertStatus(403); + } + + /** + * @test + * @throws \Source\Exceptions\EntityExistsException + */ + public function it_denies_users_who_are_not_allowed(): void + { + $this->authenticateAsDoor(); + + $this->authorizer->setNext(false); + + $this->handleTest('asdf'); + + $this->response->assertStatus(403); + } + + /** + * @test + * @throws \Source\Exceptions\EntityExistsException + */ + public function it_allows_valid_users(): void + { + $this->authenticateAsDoor(); + + $this->usersRepository->create(new User(0, '', '', '', '', null, null, HashedSearchable::hash(config('app.key'), 'asdf'))); + + $this->authorizer->setNext(true); + + $this->handleTest('asdf'); + + $this->response->assertStatus(200); + } } -- GitLab