mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-24 10:21:46 -04:00
test: allow items check for multiple array items
This commit is contained in:
@@ -247,6 +247,7 @@ config = {
|
||||
"apiAuthApp",
|
||||
],
|
||||
"skip": False,
|
||||
"withRemotePhp": [True],
|
||||
"extraServerEnvironment": {
|
||||
"OCIS_ADD_RUN_SERVICES": "auth-app",
|
||||
"PROXY_ENABLE_APP_AUTH": True,
|
||||
|
||||
@@ -28,11 +28,10 @@ use Psr\Http\Message\ResponseInterface;
|
||||
* A helper class for managing Auth App API requests
|
||||
*/
|
||||
class AuthAppHelper {
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getAuthAppEndpoint():string {
|
||||
public static function getAuthAppEndpoint(): string {
|
||||
return "/auth-app/tokens";
|
||||
}
|
||||
|
||||
@@ -43,7 +42,7 @@ class AuthAppHelper {
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public static function listAllAppAuthToken(string $baseUrl, string $user, string $password) : ResponseInterface {
|
||||
public static function listAllAppAuthTokensForUser(string $baseUrl, string $user, string $password): ResponseInterface {
|
||||
$url = $baseUrl . self::getAuthAppEndpoint();
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$url,
|
||||
@@ -62,7 +61,7 @@ class AuthAppHelper {
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public static function createAppAuthToken(string $baseUrl, string $user, string $password, string $expiration) : ResponseInterface {
|
||||
public static function createAppAuthToken(string $baseUrl, string $user, string $password, string $expiration): ResponseInterface {
|
||||
$url = $baseUrl . self::getAuthAppEndpoint() . "?expiry=$expiration";
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$url,
|
||||
@@ -81,7 +80,7 @@ class AuthAppHelper {
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public static function deleteAppAuthToken(string $baseUrl, string $user, string $password, string $token) : ResponseInterface {
|
||||
public static function deleteAppAuthToken(string $baseUrl, string $user, string $password, string $token): ResponseInterface {
|
||||
$url = $baseUrl . self::getAuthAppEndpoint() . "?token=$token";
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$url,
|
||||
|
||||
@@ -33,7 +33,6 @@ require_once 'bootstrap.php';
|
||||
*/
|
||||
class AuthAppContext implements Context {
|
||||
private FeatureContext $featureContext;
|
||||
private array $allCreatedTokens = [];
|
||||
|
||||
/**
|
||||
* @BeforeScenario
|
||||
@@ -50,89 +49,56 @@ class AuthAppContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator creates app token with expiration time :expiration using the API
|
||||
* @When user :user creates app token with expiration time :expiration using the auth-app API
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $expiration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorCreatesAppTokenForUserWithExpirationTimeUsingTheApi(string $expiration): void {
|
||||
public function userCreatesAppTokenWithExpirationTimeUsingTheAuthAppApi(string $user, string $expiration): void {
|
||||
$this->featureContext->setResponse(
|
||||
AuthAppHelper::createAppAuthToken(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$this->featureContext->getActualUsername($user),
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$expiration,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the administrator has created app token with expiration time :expiration using the API
|
||||
* @Given user :user has created app token with expiration time :expiration
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $expiration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorHasCreatedAppTokenWithExpirationTimeUsingTheApi(string $expiration): void {
|
||||
public function userHasCreatedAppTokenWithExpirationTime(string $user, string $expiration): void {
|
||||
$response = AuthAppHelper::createAppAuthToken(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$this->featureContext->getActualUsername($user),
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$expiration,
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When admin lists all created tokens
|
||||
* @When user :user lists all created tokens using the auth-app API
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function adminListsAllCreatedTokens(): void {
|
||||
public function userListsAllCreatedTokensUsingTheAuthAppApi(string $user): void {
|
||||
$this->featureContext->setResponse(
|
||||
AuthAppHelper::listAllAppAuthToken(
|
||||
AuthAppHelper::listAllAppAuthTokensForUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$this->featureContext->getActualUsername($user),
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAllToken() : void {
|
||||
$response = AuthAppHelper::listAllAppAuthToken(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
||||
$rawBody = $response->getBody()->getContents();
|
||||
$tokens = json_decode($rawBody);
|
||||
foreach ($tokens as $token) {
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(
|
||||
200,
|
||||
"",
|
||||
AuthAppHelper::deleteAppAuthToken(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$token->token
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @AfterScenario
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception|GuzzleException
|
||||
*/
|
||||
public function cleanDataAfterTests(): void {
|
||||
$this->deleteAllToken();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1132,9 +1132,11 @@ class FeatureContext extends BehatVariablesContext {
|
||||
Assert::fail("'$validator' should be an object not an array");
|
||||
}
|
||||
Assert::assertFalse($value->allOf || $value->anyOf, "'allOf' and 'anyOf' are not allowed in array");
|
||||
Assert::assertNotNull($value->oneOf, "'oneOf' is required to assert more than one elements");
|
||||
Assert::assertTrue(\is_array($value->oneOf), "'oneOf' should be an array");
|
||||
Assert::assertEquals($schemaObj->maxItems, \count($value->oneOf), "Expected " . $schemaObj->maxItems . " 'oneOf' items but got " . \count($value->oneOf));
|
||||
if ($value->oneOf) {
|
||||
Assert::assertNotNull($value->oneOf, "'oneOf' is required to assert more than one elements");
|
||||
Assert::assertTrue(\is_array($value->oneOf), "'oneOf' should be an array");
|
||||
Assert::assertEquals($schemaObj->maxItems, \count($value->oneOf), "Expected " . $schemaObj->maxItems . " 'oneOf' items but got " . \count($value->oneOf));
|
||||
}
|
||||
}
|
||||
Assert::assertTrue(\is_object($value), "'$validator' should be an object when expecting 1 element");
|
||||
break;
|
||||
@@ -1226,7 +1228,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$errors = $this->getJsonSchemaErrors($e);
|
||||
$messages = ["JSON Schema validation failed:"];
|
||||
|
||||
$previousPointer = '';
|
||||
$previousPointer = null;
|
||||
$errorCount = 0;
|
||||
foreach ($errors as $error) {
|
||||
$expected = $error->constraint;
|
||||
@@ -1236,6 +1238,9 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$dataPointer = \str_replace("/", ".", \trim($error->getDataPointer(), "/"));
|
||||
|
||||
$pointer = \str_contains($schemaPointer, "additionalProperties") ? $dataPointer : $schemaPointer;
|
||||
if ($pointer === '') {
|
||||
$pointer = "{root}";
|
||||
}
|
||||
if ($pointer === $previousPointer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
Feature: create auth token
|
||||
As a admin
|
||||
As a user
|
||||
I want to create App Tokens
|
||||
So that I can use 3rd party apps
|
||||
|
||||
Background:
|
||||
Given user "Alice" has been created with default attributes
|
||||
|
||||
Scenario: admin creates app token
|
||||
When the administrator creates app token with expiration time "72h" using the API
|
||||
|
||||
Scenario: user creates app token
|
||||
When user "Alice" creates app token with expiration time "72h" using the auth-app API
|
||||
Then the HTTP status code should be "200"
|
||||
And the JSON data of the response should match
|
||||
"""
|
||||
@@ -30,16 +33,18 @@ Feature: create auth token
|
||||
"""
|
||||
|
||||
|
||||
Scenario: admin lists app token
|
||||
Given the administrator has created app token with expiration time "72h" using the API
|
||||
When admin lists all created tokens
|
||||
Scenario: user lists app tokens
|
||||
Given user "Alice" has created app token with expiration time "72h"
|
||||
And user "Alice" has created app token with expiration time "2h"
|
||||
When user "Alice" lists all created tokens using the auth-app API
|
||||
Then the HTTP status code should be "200"
|
||||
And the JSON data of the response should match
|
||||
"""
|
||||
{
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"maxItems": 1,
|
||||
"minItems": 2,
|
||||
"maxItems": 2,
|
||||
"uniqueItems": true,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
Reference in New Issue
Block a user