[test-only] Cors test for settings api (#8286)

* add cors tests for settings api

* fix
This commit is contained in:
Viktor Scharf
2024-01-25 14:17:13 +01:00
committed by GitHub
parent 6cf5d8fb13
commit a9bf0f9bd5
3 changed files with 37 additions and 2 deletions
+1
View File
@@ -149,6 +149,7 @@ default:
- OCSContext:
- GraphContext:
- OcisConfigContext:
- SettingsContext:
apiDepthInfinity:
paths:
@@ -90,3 +90,13 @@ Feature: CORS headers
And the following headers should be set
| header | value |
| Access-Control-Allow-Origin | https://aphno.badal |
Scenario: CORS headers should be returned when setting CORS domain sending origin header in the settings api
When user "Alice" lists values-list with headers using the Settings API
| header | value |
| Origin | https://aphno.badal |
Then the HTTP status code should be "201"
And the following headers should be set
| header | value |
| Access-Control-Allow-Origin | https://aphno.badal |
@@ -15,6 +15,7 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\HttpRequestHelper;
use Behat\Gherkin\Node\TableNode;
require_once 'bootstrap.php';
@@ -339,13 +340,14 @@ class SettingsContext implements Context {
/**
* @param string $user
* @param array $headers
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws Exception
*/
public function sendRequestGetSettingsValuesList(string $user): ResponseInterface {
public function sendRequestGetSettingsValuesList(string $user, array $headers = null): ResponseInterface {
$fullUrl = $this->baseUrl . $this->settingsUrl . "values-list";
$body = json_encode(["account_uuid" => "me"], JSON_THROW_ON_ERROR);
return HttpRequestHelper::post(
@@ -353,11 +355,33 @@ class SettingsContext implements Context {
$this->featureContext->getStepLineRef(),
$user,
$this->featureContext->getPasswordForUser($user),
null,
$headers,
$body
);
}
/**
* @When /^user "([^"]*)" lists values-list with headers using the Settings API$/
*
* @param string $user
* @param TableNode $headersTable
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserListsAllValuesListWithHeadersUsingSettingsApi(string $user, TableNode $headersTable): void {
$this->featureContext->verifyTableNodeColumns(
$headersTable,
['header', 'value']
);
foreach ($headersTable as $row) {
$headers[$row['header']] = $row ['value'];
}
$this->featureContext->setResponse($this->sendRequestGetSettingsValuesList($user, $headers));
}
/**
* @param string $user
*