diff options
author | Mario <mario@mariovavti.com> | 2025-02-01 10:53:12 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2025-02-01 10:53:12 +0000 |
commit | 0edf761499124809eb90228f46f63b484fb38c72 (patch) | |
tree | 3dfa63218ac4ff796b88bf9316ae226714d20214 /tests | |
parent | bf76d5981f5e191e85a1d04c185c432dff7050fd (diff) | |
parent | a550c7c85354950b981bb49dbc519f83f89026a7 (diff) | |
download | volse-hubzilla-0edf761499124809eb90228f46f63b484fb38c72.tar.gz volse-hubzilla-0edf761499124809eb90228f46f63b484fb38c72.tar.bz2 volse-hubzilla-0edf761499124809eb90228f46f63b484fb38c72.zip |
Merge branch 'owa-error-messages' into 'dev'
Add error message on missing owa auth headers
See merge request hubzilla/core!2183
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/Module/OwaTest.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/unit/Module/OwaTest.php b/tests/unit/Module/OwaTest.php new file mode 100644 index 000000000..dbb25c0b5 --- /dev/null +++ b/tests/unit/Module/OwaTest.php @@ -0,0 +1,64 @@ +<?php +/* + * SPDX-FileCopyrightText: 2025 Hubzilla Community + * SPDX-FileContributor: Harald Eilertsen + * + * SPDX-License-Identifier: MIT + */ + +namespace Zotlabs\Tests\Unit\Module; + +class OwaTest extends TestCase +{ + public function testShouldReturnErrorIfNoAuthorizationHeader(): void + { + // Expect the call to return error + $this->expectJsonResponse([ + 'success' => false, + 'message' => 'Missing or invalid authorization header.' + ]); + + $this->get('owa'); + } + + public function testShouldReturnErrorIfWrongAuthorizationHeader(): void + { + // Expect the call to return error + $this->expectJsonResponse([ + 'success' => false, + 'message' => 'Missing or invalid authorization header.' + ]); + + $_SERVER['HTTP_AUTHORIZATION'] = 'Bearer kjkjhkjhkjh'; + $this->get('owa'); + } + + public function testShouldReturnErrorIfInvalidAuthorizationHeader(): void + { + // Expect the call to return error + $this->expectJsonResponse(['success' => false]); + + $_SERVER['HTTP_AUTHORIZATION'] = 'Signature kjkjhkjhkjh'; + $this->get('owa'); + } + + /** + * Expect the request to be terminated and return a json response. + */ + private function expectJsonResponse(array $data): void + { + $this->getFunctionMock('Zotlabs\Module', 'json_return_and_die') + ->expects($this->once()) + ->with( + $this->identicalTo($data), + $this->identicalTo('application/x-zot+json') + ) + ->willReturnCallback( + function() { + throw new KillmeException(); + } + ); + + $this->expectException(KillmeException::class); + } +} |