diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2025-01-29 18:32:56 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2025-01-29 18:41:40 +0100 |
commit | a550c7c85354950b981bb49dbc519f83f89026a7 (patch) | |
tree | c3a71b5e2d4e385278531ea451f8f9cc73516c78 /tests | |
parent | 03d1f3383ed56ddcdaee844f435a39c4b987cd74 (diff) | |
download | volse-hubzilla-a550c7c85354950b981bb49dbc519f83f89026a7.tar.gz volse-hubzilla-a550c7c85354950b981bb49dbc519f83f89026a7.tar.bz2 volse-hubzilla-a550c7c85354950b981bb49dbc519f83f89026a7.zip |
Add error message on missing owa auth headers
If the /owa endpoint received a request with a missing or invalid
Authorization header, it would return an error to the requester, but
without any message describing why it failes.
This patch adds a message to the error response, so that it will be a
bit easier to debug these issues in the future.
The owa spec includes a 'message' field in the error response, but makes
it optional. Any conforming implementations should accept a response
that includes the 'message' field.
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); + } +} |