summaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework
diff options
context:
space:
mode:
authorStanimir Bozhilov <stanimir@audriga.com>2022-09-26 11:51:44 +0200
committerStanimir Bozhilov <stanimir@audriga.com>2022-09-26 11:51:44 +0200
commit46c10c77e1d5f1b46e665995f9030ccd74283af7 (patch)
tree70d83b76a71a868d216a8ef6167bcdc713dbc935 /tests/lib/AppFramework
parentd80f8f6c823c531d2c54110c7d66b802a54a86da (diff)
downloadnextcloud-server-46c10c77e1d5f1b46e665995f9030ccd74283af7.tar.gz
nextcloud-server-46c10c77e1d5f1b46e665995f9030ccd74283af7.zip
Fix the JSON content type regex to match all MIME types
Signed-off-by: Stanimir Bozhilov <stanimir@audriga.com>
Diffstat (limited to 'tests/lib/AppFramework')
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index bfee052e6a8..16875cfb0d8 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -232,6 +232,30 @@ class RequestTest extends \Test\TestCase {
$this->assertSame('Example User', $request['displayName']);
}
+ public function testCustomJsonPost() {
+ global $data;
+ $data = '{"propertyA":"sometestvalue", "propertyB":"someothertestvalue"}';
+
+ // Note: the content type used here is fictional and intended to check if the regex for JSON content types works fine
+ $vars = [
+ 'method' => 'POST',
+ 'server' => ['CONTENT_TYPE' => 'application/custom-type+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('sometestvalue', $result['propertyA']);
+ $this->assertSame('someothertestvalue', $result['propertyB']);
+ }
+
public function testNotJsonPost() {
global $data;
$data = 'this is not valid json';
@@ -274,6 +298,27 @@ class RequestTest extends \Test\TestCase {
// ensure there's no error attempting to decode the content
}
+ public function testNotCustomJsonPost() {
+ global $data;
+ $data = 'this is not valid json';
+ $vars = [
+ 'method' => 'POST',
+ 'server' => ['CONTENT_TYPE' => 'application/custom-type+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'], '', '&');
@@ -390,6 +435,52 @@ class RequestTest extends \Test\TestCase {
$this->assertSame(null, $result['displayName']);
}
+ public function testCustomJsonPatchAndPut() {
+ global $data;
+
+ // PUT content
+ $data = '{"propertyA": "sometestvalue", "propertyB": "someothertestvalue"}';
+ $vars = [
+ 'method' => 'PUT',
+ 'server' => ['CONTENT_TYPE' => 'application/custom-type+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('sometestvalue', $result['propertyA']);
+ $this->assertSame('someothertestvalue', $result['propertyB']);
+
+ // PATCH content
+ $data = '{"propertyA": "sometestvalue", "propertyB": null}';
+ $vars = [
+ 'method' => 'PATCH',
+ 'server' => ['CONTENT_TYPE' => 'application/custom-type+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('sometestvalue', $result['propertyA']);
+ $this->assertSame(null, $result['propertyB']);
+ }
+
public function testPutStream() {
global $data;
$data = file_get_contents(__DIR__ . '/../../../data/testimage.png');