Add unit tests for application/scim+json content type

Signed-off-by: Stanimir Bozhilov <stanimir@audriga.com>
pull/34172/head
Stanimir Bozhilov 2022-09-20 14:19:11 +07:00
parent f0dbe1148a
commit f7d51a39cf
1 changed files with 92 additions and 0 deletions

@ -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');