diff options
author | Stanimir Bozhilov <stanimir@audriga.com> | 2022-09-20 14:19:11 +0200 |
---|---|---|
committer | Stanimir Bozhilov <stanimir@audriga.com> | 2022-09-20 16:19:05 +0200 |
commit | f7d51a39cfed94f90f5a526cb22e791a6fdc33d8 (patch) | |
tree | cb6c30f484ec16c5b163c677ff03a817d1fe83d7 /tests/lib/AppFramework/Http | |
parent | f0dbe1148aa6d4099c445e4c6bd3a625acf300e5 (diff) | |
download | nextcloud-server-f7d51a39cfed94f90f5a526cb22e791a6fdc33d8.tar.gz nextcloud-server-f7d51a39cfed94f90f5a526cb22e791a6fdc33d8.zip |
Add unit tests for application/scim+json content type
Signed-off-by: Stanimir Bozhilov <stanimir@audriga.com>
Diffstat (limited to 'tests/lib/AppFramework/Http')
-rw-r--r-- | tests/lib/AppFramework/Http/RequestTest.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php index cf5ebdca2f0..bfee052e6a8 100644 --- a/tests/lib/AppFramework/Http/RequestTest.php +++ b/tests/lib/AppFramework/Http/RequestTest.php @@ -2,6 +2,7 @@ /** * @copyright 2013 Thomas Tanghus (thomas@tanghus.net) * @copyright 2016 Lukas Reschke lukas@owncloud.com + * @copyright 2022 Stanimir Bozhilov (stanimir@audriga.com) * * This file is licensed under the Affero General Public License version 3 or * later. @@ -207,6 +208,30 @@ class RequestTest extends \Test\TestCase { $this->assertSame('Joey', $request['nickname']); } + public function testScimJsonPost() { + global $data; + $data = '{"userName":"testusername", "displayName":"Example User"}'; + $vars = [ + 'method' => 'POST', + 'server' => ['CONTENT_TYPE' => 'application/scim+json; utf-8'] + ]; + + $request = new Request( + $vars, + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('POST', $request->method); + $result = $request->post; + $this->assertSame('testusername', $result['userName']); + $this->assertSame('Example User', $result['displayName']); + $this->assertSame('Example User', $request->params['displayName']); + $this->assertSame('Example User', $request['displayName']); + } + public function testNotJsonPost() { global $data; $data = 'this is not valid json'; @@ -228,6 +253,27 @@ class RequestTest extends \Test\TestCase { // ensure there's no error attempting to decode the content } + public function testNotScimJsonPost() { + global $data; + $data = 'this is not valid scim json'; + $vars = [ + 'method' => 'POST', + 'server' => ['CONTENT_TYPE' => 'application/scim+json; utf-8'] + ]; + + $request = new Request( + $vars, + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertEquals('POST', $request->method); + $result = $request->post; + // ensure there's no error attempting to decode the content + } + public function testPatch() { global $data; $data = http_build_query(['name' => 'John Q. Public', 'nickname' => 'Joey'], '', '&'); @@ -298,6 +344,52 @@ class RequestTest extends \Test\TestCase { $this->assertSame(null, $result['nickname']); } + public function testScimJsonPatchAndPut() { + global $data; + + // PUT content + $data = '{"userName": "sometestusername", "displayName": "Example User"}'; + $vars = [ + 'method' => 'PUT', + 'server' => ['CONTENT_TYPE' => 'application/scim+json; utf-8'], + ]; + + $request = new Request( + $vars, + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('PUT', $request->method); + $result = $request->put; + + $this->assertSame('sometestusername', $result['userName']); + $this->assertSame('Example User', $result['displayName']); + + // PATCH content + $data = '{"userName": "sometestusername", "displayName": null}'; + $vars = [ + 'method' => 'PATCH', + 'server' => ['CONTENT_TYPE' => 'application/scim+json; utf-8'], + ]; + + $request = new Request( + $vars, + $this->requestId, + $this->config, + $this->csrfTokenManager, + $this->stream + ); + + $this->assertSame('PATCH', $request->method); + $result = $request->patch; + + $this->assertSame('sometestusername', $result['userName']); + $this->assertSame(null, $result['displayName']); + } + public function testPutStream() { global $data; $data = file_get_contents(__DIR__ . '/../../../data/testimage.png'); |