mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 16:41:35 -04:00
Implement context for core
Signed-off-by: Parajuli Kiran <kiranparajuli589@gmail.com>
This commit is contained in:
@@ -32,16 +32,16 @@ class GraphHelper {
|
||||
return $fullUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param string|null $body
|
||||
* @param array|null $headers
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param string|null $body
|
||||
* @param array|null $headers
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
public static function createRequest(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
@@ -101,60 +101,59 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userId
|
||||
* @param string|null $userName
|
||||
* @param string|null $password
|
||||
* @param string|null $email
|
||||
* @param string|null $displayName
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public static function editUser(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $userId,
|
||||
?string $userName = null,
|
||||
?string $password = null,
|
||||
?string $email = null,
|
||||
?string $displayName = null
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userId
|
||||
* @param string|null $userName
|
||||
* @param string|null $password
|
||||
* @param string|null $email
|
||||
* @param string|null $displayName
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public static function editUser(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $userId,
|
||||
?string $userName = null,
|
||||
?string $password = null,
|
||||
?string $email = null,
|
||||
?string $displayName = null
|
||||
): ResponseInterface {
|
||||
$payload = self::preparePatchUserPayload(
|
||||
$userName,
|
||||
$password,
|
||||
$email,
|
||||
$displayName
|
||||
);
|
||||
$headers = ['Content-Type' => 'application/json'];
|
||||
$url = self::getFullUrl($baseUrl, 'users/' . $userId);
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$url,
|
||||
$xRequestId,
|
||||
"PATCH",
|
||||
$adminUser,
|
||||
$adminPassword,
|
||||
$headers,
|
||||
$payload
|
||||
);
|
||||
}
|
||||
|
||||
): ResponseInterface {
|
||||
$payload = self::preparePatchUserPayload(
|
||||
$userName,
|
||||
$password,
|
||||
$email,
|
||||
$displayName
|
||||
);
|
||||
$headers = ['Content-Type' => 'application/json'];
|
||||
$url = self::getFullUrl($baseUrl, 'users/' . $userId);
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$url,
|
||||
$xRequestId,
|
||||
"PATCH",
|
||||
$adminUser,
|
||||
$adminPassword,
|
||||
$headers,
|
||||
$payload
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userName
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userName
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getUser(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
@@ -386,6 +385,17 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userId
|
||||
* @param string $groupId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function addUserToGroup(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
@@ -408,6 +418,17 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userId
|
||||
* @param string $groupId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function removeUserFromGroup(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
@@ -425,42 +446,51 @@ class GraphHelper {
|
||||
);
|
||||
}
|
||||
|
||||
public static function getMembersList(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $userId,
|
||||
string $groupId
|
||||
): bool {
|
||||
$url = self::getFullUrl($baseUrl, 'groups/' . $groupId . '/members/' . $userId . '/$ref');
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$adminUser,
|
||||
$adminPassword
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $groupId
|
||||
*
|
||||
* @return bool
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getMembersList(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $groupId
|
||||
): bool {
|
||||
$url = self::getFullUrl($baseUrl, 'groups/' . $groupId . '/members');
|
||||
return HttpRequestHelper::get(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$adminUser,
|
||||
$adminPassword
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function getGroupListOfAUser(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $userId
|
||||
) {
|
||||
// TODO: endpoint not available https://github.com/owncloud/ocis/issues/3363
|
||||
// Not implemented yet
|
||||
}
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
* @param string $adminUser
|
||||
* @param string $adminPassword
|
||||
* @param string $userId
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function getGroupListOfAUser(
|
||||
string $baseUrl,
|
||||
string $xRequestId,
|
||||
string $adminUser,
|
||||
string $adminPassword,
|
||||
string $userId
|
||||
) {
|
||||
// TODO: endpoint not available https://github.com/owncloud/ocis/issues/3363
|
||||
// Not implemented yet
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $userName
|
||||
@@ -471,28 +501,36 @@ class GraphHelper {
|
||||
* @return string
|
||||
*/
|
||||
public static function prepareCreateUserPayload(
|
||||
string $userName,
|
||||
string $password,
|
||||
?string $email,
|
||||
?string $displayName
|
||||
): string {
|
||||
string $userName,
|
||||
string $password,
|
||||
?string $email,
|
||||
?string $displayName
|
||||
): string {
|
||||
$payload['onPremisesSamAccountName'] = $userName;
|
||||
$payload['passwordProfile'] = ['password' => $password];
|
||||
$payload['displayName'] = $displayName ?? $userName;
|
||||
$payload['mail'] = $email ?? $userName . '@example.com';
|
||||
return \json_encode($payload);
|
||||
}
|
||||
public static function preparePatchUserPayload(
|
||||
?string $userName,
|
||||
?string $password,
|
||||
?string $email,
|
||||
?string $displayName
|
||||
): string {
|
||||
$payload = [];
|
||||
if ($userName) $payload['onPremisesSamAccountName'] = $userName;
|
||||
if ($password) $payload['passwordProfile'] = ['password' => $password];
|
||||
if ($displayName) $payload['displayName'] = $displayName;
|
||||
if ($email) $payload['mail'] = $email;
|
||||
return \json_encode($payload);
|
||||
}
|
||||
public static function preparePatchUserPayload(
|
||||
?string $userName,
|
||||
?string $password,
|
||||
?string $email,
|
||||
?string $displayName
|
||||
): string {
|
||||
$payload = [];
|
||||
if ($userName) {
|
||||
$payload['onPremisesSamAccountName'] = $userName;
|
||||
}
|
||||
if ($password) {
|
||||
$payload['passwordProfile'] = ['password' => $password];
|
||||
}
|
||||
if ($displayName) {
|
||||
$payload['displayName'] = $displayName;
|
||||
}
|
||||
if ($email) {
|
||||
$payload['mail'] = $email;
|
||||
}
|
||||
return \json_encode($payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,19 +56,5 @@ default:
|
||||
- FilesVersionsContext:
|
||||
- PublicWebDavContext:
|
||||
|
||||
apiGraphUser:
|
||||
paths:
|
||||
- '%paths.base%/../features/apiGraphUser'
|
||||
contexts:
|
||||
- GraphContext:
|
||||
- FeatureContext: *common_feature_context_params
|
||||
|
||||
apiGraphGroup:
|
||||
paths:
|
||||
- '%paths.base%/../features/apiGraphGroup'
|
||||
contexts:
|
||||
- GraphContext:
|
||||
- FeatureContext: *common_feature_context_params
|
||||
|
||||
extensions:
|
||||
Cjm\Behat\StepThroughExtension: ~
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
@api
|
||||
Feature: add groups
|
||||
As an administrator
|
||||
I want to be able to create group using the Graph API
|
||||
So that I can more easily manage access to resources by groups rather than individual users
|
||||
|
||||
Scenario:
|
||||
When the administrator sends a group creation request for the following groups using the graph API
|
||||
| group_display_name |
|
||||
| simplegroup |
|
||||
| España§àôœ€ |
|
||||
| नेपाली |
|
||||
And the HTTP status code of responses on all endpoints should be "200"
|
||||
And these groups should exist:
|
||||
| groupname |
|
||||
| simplegroup |
|
||||
| España§àôœ€ |
|
||||
| नेपाली |
|
||||
|
||||
|
||||
Scenario: admin creates a group with special characters
|
||||
When the administrator sends a group creation request for the following groups using the graph API
|
||||
| group_display_name | comment |
|
||||
| brand-new-group | dash |
|
||||
| the.group | dot |
|
||||
| left,right | comma |
|
||||
| 0 | The "false" group |
|
||||
| Finance (NP) | Space and brackets |
|
||||
| Admin&Finance | Ampersand |
|
||||
| admin:Pokhara@Nepal | Colon and @ |
|
||||
| maint+eng | Plus sign |
|
||||
| $x<=>[y*z^2]! | Maths symbols |
|
||||
| Mgmt\Middle | Backslash |
|
||||
| 😅 😆 | emoji |
|
||||
| [group1] | brackets |
|
||||
| group [ 2 ] | bracketsAndSpace |
|
||||
And the HTTP status code of responses on all endpoints should be "200"
|
||||
And these groups should exist:
|
||||
| groupname |
|
||||
| brand-new-group |
|
||||
| the.group |
|
||||
| left,right |
|
||||
| 0 |
|
||||
| Finance (NP) |
|
||||
| Admin&Finance |
|
||||
| admin:Pokhara@Nepal |
|
||||
| maint+eng |
|
||||
| $x<=>[y*z^2]! |
|
||||
| Mgmt\Middle |
|
||||
| 😅 😆 |
|
||||
| [group1] |
|
||||
| group [ 2 ] |
|
||||
@@ -1,63 +0,0 @@
|
||||
@api
|
||||
Feature:
|
||||
As an administrator
|
||||
I want to be able to create user using the Graph API
|
||||
So that I can manage users more easily
|
||||
|
||||
|
||||
@smokeTest
|
||||
Scenario: admin creates a user
|
||||
Given user "brand-new-user" has been deleted
|
||||
When the administrator sends a user creation request for user "brand-new-user" password "%alt1%" using the graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And user "brand-new-user" should exist
|
||||
And user "brand-new-user" should be able to upload file "filesForUpload/textfile.txt" to "/textfile.txt"
|
||||
|
||||
|
||||
Scenario Outline: admin creates a user with special characters in the username
|
||||
Given user "<username>" has been deleted
|
||||
When the administrator sends a user creation request for user "<username>" password "%alt1%" using the graph API
|
||||
Then the HTTP status code of responses on all endpoints should be "400"
|
||||
And the graph API response should return the following error
|
||||
| code | invalidRequest |
|
||||
| message | username '<username>' must be at least the local part of an email |
|
||||
And user "<username>" should not exist
|
||||
Examples:
|
||||
| username |
|
||||
| a@-+_.b |
|
||||
| a space |
|
||||
|
||||
Scenario: admin creates a user and specifies a password with special characters
|
||||
When the administrator sends a user creation request for the following users with password using the graph API
|
||||
| username | password |
|
||||
| brand-new-user1 | !@#$%^&*()-_+=[]{}:;,.<>?~ |
|
||||
| brand-new-user2 | España§àôœ€ |
|
||||
| brand-new-user3 | नेपाली |
|
||||
And the HTTP status code of responses on all endpoints should be "200"
|
||||
And the following users should exist
|
||||
| username |
|
||||
| brand-new-user1 |
|
||||
| brand-new-user2 |
|
||||
| brand-new-user3 |
|
||||
And the following users should be able to upload file "filesForUpload/textfile.txt" to "/textfile.txt"
|
||||
| username |
|
||||
| brand-new-user1 |
|
||||
| brand-new-user2 |
|
||||
| brand-new-user3 |
|
||||
|
||||
Scenario: admin tries to create an existing user
|
||||
And user "brand-new-user" has been created with default attributes and without skeleton files
|
||||
When the administrator sends a user creation request for user "brand-new-user" password "%alt1%" using the graph API
|
||||
And the HTTP status code should be "500"
|
||||
Then the graph API response should return the following error
|
||||
| code | generalException |
|
||||
| message | LDAP Result Code 68 "Entry Already Exists":{space} |
|
||||
|
||||
|
||||
Scenario: admin creates a user and specifies password containing just space
|
||||
Given user "brand-new-user" has been deleted
|
||||
When the administrator sends a user creation request for user "brand-new-user" password " " using the graph API
|
||||
And the HTTP status code should be "200"
|
||||
And user "brand-new-user" should exist
|
||||
And user "brand-new-user" should be able to upload file "filesForUpload/textfile.txt" to "/textfile.txt"
|
||||
|
||||
@@ -8,13 +8,11 @@
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use TestHelpers\GraphHelper;
|
||||
use TestHelpers\HttpRequestHelper;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use TestHelpers\GraphHelper;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
require_once "bootstrap.php";
|
||||
require_once 'bootstrap.php';
|
||||
|
||||
/**
|
||||
* Context for the provisioning specific steps using the Graph API
|
||||
@@ -43,110 +41,423 @@ class GraphContext implements Context {
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a user creation request for user "([^"]*)" password "([^"]*)" using the graph API$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string|null $userName
|
||||
* @param string|null $password
|
||||
* @param string|null $email
|
||||
* @param string|null $displayName
|
||||
* @param string|null $requester
|
||||
* @param string|null $requesterPassword
|
||||
*
|
||||
* @return array
|
||||
* @throws JsonException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userHasBeenEditedUsingTheGraphApi(
|
||||
string $user,
|
||||
?string $userName = null,
|
||||
?string $password = null,
|
||||
?string $email = null,
|
||||
?string $displayName = null,
|
||||
?string $requester = null,
|
||||
?string $requesterPassword = null
|
||||
): array {
|
||||
if (!$requester) {
|
||||
$requester = $this->featureContext->getAdminUsername();
|
||||
$requesterPassword = $this->featureContext->getAdminPassword();
|
||||
}
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
|
||||
$response = GraphHelper::editUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$requester,
|
||||
$requesterPassword,
|
||||
$userId,
|
||||
$userName,
|
||||
$password,
|
||||
$email,
|
||||
$displayName
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
|
||||
$response = GraphHelper::getUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$requester,
|
||||
$requesterPassword,
|
||||
$userId
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
|
||||
return $this->featureContext->getJsonDecodedResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminHasRetrievedUserUsingTheGraphApi(string $user):void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
|
||||
$result = GraphHelper::getUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
($userId) ?: $user
|
||||
);
|
||||
$this->featureContext->setResponse($result);
|
||||
$this->featureContext->thenTheHTTPStatusCodeShouldBe(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $requestingUser
|
||||
* @param $targetUser
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function userHasRetrievedUserUsingTheGraphApi(
|
||||
$requestingUser,
|
||||
$targetUser
|
||||
):void {
|
||||
$requester = $this->featureContext->getActualUsername($requestingUser);
|
||||
$requesterPassword = $this->featureContext->getPasswordForUser($requestingUser);
|
||||
$user = $this->featureContext->getActualUsername($targetUser);
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
|
||||
$response = GraphHelper::getUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$requester,
|
||||
$requesterPassword,
|
||||
$userId
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->featureContext->thenTheHTTPStatusCodeShouldBe(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminDeletesGroupUsingTheGraphApi(
|
||||
string $group
|
||||
) {
|
||||
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
|
||||
if ($groupId) {
|
||||
$this->featureContext->setResponse(
|
||||
GraphHelper::deleteGroup(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$groupId
|
||||
)
|
||||
);
|
||||
} else {
|
||||
throw new Exception(
|
||||
"Group id does not exist for '$group' in the created list."
|
||||
. " Cannot delete group without id when using the Graph API."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminHasDeletedGroupUsingTheGraphApi(string $group):void {
|
||||
$this->adminDeletesGroupUsingTheGraphApi($group);
|
||||
$this->featureContext->thenTheHTTPStatusCodeShouldBe(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a request to delete a user using the Graph API
|
||||
*
|
||||
* @param string $user username is used as the id
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminSendsUserCreationRequestUsingTheGraphApi(string $user, string $password):void {
|
||||
public function adminDeletesUserUsingTheGraphApi(string $user) {
|
||||
$this->featureContext->setResponse(
|
||||
GraphHelper::deleteUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$user
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminHasRemovedUserFromGroupUsingTheGraphApi(string $user, string $group):void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getActualPassword($password);
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
|
||||
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
|
||||
$response = GraphHelper::removeUserFromGroup(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$userId,
|
||||
$groupId,
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->featureContext->thenTheHTTPStatusCodeShouldBe(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the provided user is present as a member in the provided group
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $group
|
||||
*
|
||||
* @return bool
|
||||
* @throws JsonException
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getUserPresenceInGroupUsingTheGraphApi(string $user, string $group): bool {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
|
||||
$members = $this->theAdminHasRetrievedMembersListOfGroupUsingTheGraphApi($group);
|
||||
$found = false;
|
||||
foreach ($members as $member) {
|
||||
if ($member["id"] === $userId) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userShouldNotBeMemberInGroupUsingTheGraphApi(string $user, string $group):void {
|
||||
$found = $this->getUserPresenceInGroupUsingTheGraphApi($user, $group);
|
||||
Assert::assertFalse($found, __METHOD__ . " User $user is member of group $group");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userShouldBeMemberInGroupUsingTheGraphApi(string $user, string $group):void {
|
||||
$found = $this->getUserPresenceInGroupUsingTheGraphApi($user, $group);
|
||||
Assert::assertTrue($found, __METHOD__ . "User $user is not member of group $group");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function adminChangesPasswordOfUserToUsingTheGraphApi(
|
||||
string $user,
|
||||
string $password
|
||||
):void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id');
|
||||
$response = GraphHelper::editUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$userId,
|
||||
null,
|
||||
$password
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function adminHasRetrievedGroupListUsingTheGraphApi():array {
|
||||
$response = GraphHelper::getGroups(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword()
|
||||
);
|
||||
$jsonBody = $this->featureContext->getJsonDecodedResponse($response);
|
||||
if ($response->getStatusCode() === 200) {
|
||||
return $jsonBody;
|
||||
} else {
|
||||
throw new Exception(
|
||||
__METHOD__
|
||||
. "\nCould not retrieve groups list."
|
||||
. "\nHTTP status code: " . $response->getStatusCode()
|
||||
. "\nError code: " . $jsonBody["error"]["code"]
|
||||
. "\nMessage: " . $jsonBody["error"]["message"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of members in group
|
||||
*
|
||||
* @param string $group
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theAdminHasRetrievedMembersListOfGroupUsingTheGraphApi(string $group):array {
|
||||
$response = GraphHelper::getMembersList(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$this->featureContext->getAttributeOfCreatedGroup($group, 'id')
|
||||
);
|
||||
$jsonBody = $this->featureContext->getJsonDecodedResponse($response);
|
||||
if ($response->getStatusCode() === 200) {
|
||||
return $jsonBody;
|
||||
} else {
|
||||
throw new Exception(
|
||||
__METHOD__
|
||||
. "\nCould not retrieve members list for group $group."
|
||||
. "\nHTTP status code: " . $response->getStatusCode()
|
||||
. "\nError code: " . $jsonBody["error"]["code"]
|
||||
. "\nMessage: " . $jsonBody["error"]["message"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a user with provided data
|
||||
* actor: the administrator
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $email
|
||||
* @param string $displayName
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theAdminHasCreatedUser(
|
||||
string $user,
|
||||
string $password,
|
||||
string $email,
|
||||
string $displayName
|
||||
): array {
|
||||
$response = GraphHelper::createUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$user,
|
||||
$password
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->featureContext->pushToLastStatusCodesArrays();
|
||||
$success = $this->featureContext->theHTTPStatusCodeWasSuccess();
|
||||
$this->featureContext->addUserToCreatedUsersList(
|
||||
$user,
|
||||
$password,
|
||||
null,
|
||||
null,
|
||||
$success
|
||||
$email,
|
||||
$displayName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a user creation request for the following users with password using the graph API$/
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theAdministratorSendsAUserCreationRequestForTheFollowingUsersWithPasswordUsingTheGraphAPI(TableNode $table) {
|
||||
$this->featureContext->verifyTableNodeColumns($table, ["username", "password"]);
|
||||
$users = $table->getHash();
|
||||
foreach ($users as $user) {
|
||||
$this->adminSendsUserCreationRequestUsingTheGraphApi($user["username"], $user["password"]);
|
||||
$jsonBody = $this->featureContext->getJsonDecodedResponse($response);
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new Exception(
|
||||
__METHOD__
|
||||
. "\nCould not create user $user"
|
||||
. "\nError code: {$jsonBody['error']['code']}"
|
||||
. "\nError message: {$jsonBody['error']['message']}"
|
||||
);
|
||||
} else {
|
||||
return $jsonBody;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the graph API response should return the following error$/
|
||||
*
|
||||
* @param TableNode $body
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theGraphApiResponseShouldReturnTheFollowingError(TableNode $body):void {
|
||||
$this->featureContext->verifyTableNodeRows($body, ['code', 'message']);
|
||||
$bodyRows = $body->getRowsHash();
|
||||
$responseData = $this->featureContext->getJsonDecodedResponse();
|
||||
// parse "{space}" to " " from the message
|
||||
$bodyRows['message'] = \str_replace('{space}', ' ', $bodyRows['message']);
|
||||
Assert::assertEquals(
|
||||
$bodyRows['code'],
|
||||
$responseData['error']['code'],
|
||||
"Status code is not as expected"
|
||||
);
|
||||
Assert::assertEquals(
|
||||
$bodyRows['message'],
|
||||
$responseData['error']['message'],
|
||||
"Status message is not as expected"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a group creation request for group "([^"]*)" using the graph API$/
|
||||
* adds a user to a group
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $user
|
||||
* @param bool $checkResult
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminSendsGroupCreationRequestUsingTheGraphAPI(string $group):void {
|
||||
$response = GraphHelper::createGroup(
|
||||
public function adminHasAddedUserToGroupUsingTheGraphApi(
|
||||
string $group,
|
||||
string $user,
|
||||
bool $checkResult = true
|
||||
) {
|
||||
$groupId = $this->featureContext->getAttributeOfCreatedGroup($group, "id");
|
||||
$userId = $this->featureContext->getAttributeOfCreatedUser($user, "id");
|
||||
$result = GraphHelper::addUserToGroup(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$group
|
||||
$userId,
|
||||
$groupId
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$justCreatedGroup = $this->featureContext->getJsonDecodedResponse();
|
||||
$this->featureContext->pushToLastStatusCodesArrays();
|
||||
$this->featureContext->addGroupToCreatedGroupsList($group, true, true, $justCreatedGroup['id']);
|
||||
if ($checkResult && ($result->getStatusCode() !== 204)) {
|
||||
throw new Exception(
|
||||
"could not add user to group. "
|
||||
. $result->getStatusCode() . " " . $result->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a group creation request for the following groups using the graph API$/
|
||||
* create group with provided data
|
||||
*
|
||||
* @return void
|
||||
* @param string $group
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theAdministratorSendsAGroupCreationRequestForTheFollowingGroupsUsingTheGraphAPI(TableNode $table) {
|
||||
$this->featureContext->verifyTableNodeColumns($table, ["group_display_name"], ['comment']);
|
||||
$groups = $table->getHash();
|
||||
foreach ($groups as $group) {
|
||||
$this->adminSendsGroupCreationRequestUsingTheGraphAPI($group["group_display_name"]);
|
||||
public function adminHasCreatedGroupUsingTheGraphApi(string $group):array {
|
||||
$result = GraphHelper::createGroup(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$group,
|
||||
);
|
||||
$jsonBody = $this->featureContext->getJsonDecodedResponse($result);
|
||||
if ($result->getStatusCode() === 200) {
|
||||
return $jsonBody;
|
||||
} else {
|
||||
throw new Exception(
|
||||
__METHOD__
|
||||
. "\nError: failed creating group '$group'"
|
||||
. "\nStatus code: " . $jsonBody['error']['code']
|
||||
. "\nMessage: " . $jsonBody['error']['message']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user