From 240798329d17750dd39463a16ed106b923725fd8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 10:55:56 +0200 Subject: [PATCH 1/2] Set proper content type on OCS responses --- lib/private/AppFramework/OCS/BaseResponse.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/private/AppFramework/OCS/BaseResponse.php b/lib/private/AppFramework/OCS/BaseResponse.php index c9295a2677..fa22498ac0 100644 --- a/lib/private/AppFramework/OCS/BaseResponse.php +++ b/lib/private/AppFramework/OCS/BaseResponse.php @@ -68,6 +68,16 @@ abstract class BaseResponse extends Response { $this->setLastModified($dataResponse->getLastModified()); $this->setCookies($dataResponse->getCookies()); $this->setContentSecurityPolicy($dataResponse->getContentSecurityPolicy()); + + if ($format === 'json') { + $this->addHeader( + 'Content-Type', 'application/json; charset=utf-8' + ); + } else { + $this->addHeader( + 'Content-Type', 'application/xml; charset=utf-8' + ); + } } /** From 19ecacd57e9f99736657fb0296a589ed5681da6a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 7 Sep 2016 13:01:42 +0200 Subject: [PATCH 2/2] Add basic osc intergration tests --- .../features/bootstrap/BasicStructure.php | 8 +++++++ build/integration/features/ocs-v1.feature | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 build/integration/features/ocs-v1.feature diff --git a/build/integration/features/bootstrap/BasicStructure.php b/build/integration/features/bootstrap/BasicStructure.php index e6da74601b..df46d0b198 100644 --- a/build/integration/features/bootstrap/BasicStructure.php +++ b/build/integration/features/bootstrap/BasicStructure.php @@ -201,6 +201,14 @@ trait BasicStructure { PHPUnit_Framework_Assert::assertEquals($statusCode, $this->response->getStatusCode()); } + /** + * @Then /^the Content-Type should be "([^"]*)"$/ + * @param string $contentType + */ + public function theContentTypeShouldbe($contentType) { + PHPUnit_Framework_Assert::assertEquals($contentType, $this->response->getHeader('Content-Type')); + } + /** * @param ResponseInterface $response */ diff --git a/build/integration/features/ocs-v1.feature b/build/integration/features/ocs-v1.feature new file mode 100644 index 0000000000..6075189ddb --- /dev/null +++ b/build/integration/features/ocs-v1.feature @@ -0,0 +1,24 @@ +Feature: ocs + Background: + Given using api version "1" + + Scenario: Default output is xml + Given user "user0" exists + And As an "user0" + When sending "GET" to "/cloud/config" + And the HTTP status code should be "200" + And the Content-Type should be "text/xml; charset=UTF-8" + + Scenario: Get XML when requesting XML + Given user "user0" exists + And As an "user0" + When sending "GET" to "/cloud/config?format=xml" + And the HTTP status code should be "200" + And the Content-Type should be "text/xml; charset=UTF-8" + + Scenario: Get JSON when requesting JSON + Given user "user0" exists + And As an "user0" + When sending "GET" to "/cloud/config?format=json" + And the HTTP status code should be "200" + And the Content-Type should be "application/json; charset=utf-8"