From c59d3a96aafcd45de1cd501bf833094586c77a29 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 18 Jan 2018 21:41:45 -0600 Subject: [PATCH] Add test for new middleware --- .../Api/Admin/AuthenticateUserTest.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/Unit/Http/Middleware/Api/Admin/AuthenticateUserTest.php diff --git a/tests/Unit/Http/Middleware/Api/Admin/AuthenticateUserTest.php b/tests/Unit/Http/Middleware/Api/Admin/AuthenticateUserTest.php new file mode 100644 index 000000000..fb243a78f --- /dev/null +++ b/tests/Unit/Http/Middleware/Api/Admin/AuthenticateUserTest.php @@ -0,0 +1,53 @@ +setRequestUserModel(null); + + $this->getMiddleware()->handle($this->request, $this->getClosureAssertions()); + } + + /** + * Test that a non-admin user results an an exception. + * + * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException + */ + public function testNonAdminUser() + { + $this->generateRequestUserModel(['root_admin' => false]); + + $this->getMiddleware()->handle($this->request, $this->getClosureAssertions()); + } + + /** + * Test that an admin user continues though the middleware. + */ + public function testAdminUser() + { + $this->generateRequestUserModel(['root_admin' => true]); + + $this->getMiddleware()->handle($this->request, $this->getClosureAssertions()); + } + + /** + * Return an instance of the middleware for testing. + * + * @return \Pterodactyl\Http\Middleware\Api\Admin\AuthenticateUser + */ + private function getMiddleware(): AuthenticateUser + { + return new AuthenticateUser; + } +}