2022-11-04 12:39:54 +01:00
<? php
declare ( strict_types = 1 );
2022-03-25 15:33:35 +05:45
/**
* ownCloud
*
* @author Kiran Parajuli <kiran@jankaritech.com>
* @copyright Copyright (c) 2021 Kiran Parajuli kiran@jankaritech.com
*/
use Behat\Behat\Context\Context ;
use Behat\Behat\Hook\Scope\BeforeScenarioScope ;
2023-04-05 14:05:34 +05:45
use Behat\Gherkin\Node\PyStringNode ;
2022-04-13 12:53:20 +05:45
use Behat\Gherkin\Node\TableNode ;
2022-03-25 15:33:35 +05:45
use GuzzleHttp\Exception\GuzzleException ;
2024-10-08 12:26:40 +05:45
use PHPUnit\Framework\Assert ;
2022-04-12 19:35:05 +05:45
use Psr\Http\Message\ResponseInterface ;
2022-04-06 20:16:33 +05:45
use TestHelpers\GraphHelper ;
2022-11-11 09:31:13 +05:45
use TestHelpers\WebDavHelper ;
2023-03-27 10:41:21 +05:45
use TestHelpers\HttpRequestHelper ;
2024-10-08 12:26:40 +05:45
use TestHelpers\BehatHelper ;
2022-03-25 15:33:35 +05:45
2022-04-06 20:16:33 +05:45
require_once 'bootstrap.php' ;
2022-03-25 15:33:35 +05:45
/**
* Context for the provisioning specific steps using the Graph API
*/
class GraphContext implements Context {
private FeatureContext $featureContext ;
2024-09-25 16:26:13 +05:45
private SpacesContext $spacesContext ;
2022-03-25 15:33:35 +05:45
2023-02-20 09:49:05 +05:45
/**
* application Entity
*/
2023-05-02 17:25:56 +05:45
private array $appEntity = [];
2023-02-20 09:49:05 +05:45
2022-03-25 15:33:35 +05:45
/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
2022-04-19 10:21:05 +05:45
public function before ( BeforeScenarioScope $scope ) : void {
2022-03-25 15:33:35 +05:45
// Get the environment
$environment = $scope -> getEnvironment ();
// Get all the contexts you need in this context from here
2024-10-08 12:26:40 +05:45
$this -> featureContext = BehatHelper :: getContext ( $scope , $environment , 'FeatureContext' );
$this -> spacesContext = BehatHelper :: getContext ( $scope , $environment , 'SpacesContext' );
2022-03-25 15:33:35 +05:45
}
2022-12-14 14:15:18 +05:45
/**
* @When /^the user "([^"]*)" changes the email of user "([^"]*)" to "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to change the email of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $email
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserChangesTheEmailOfUserToUsingTheGraphApi ( string $byUser , string $user , string $email ) : void {
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , $email );
$this -> featureContext -> setResponse ( $response );
}
/**
* @When /^the user "([^"]*)" changes the display name of user "([^"]*)" to "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to change the display name of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $displayName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserChangesTheDisplayNameOfUserToUsingTheGraphApi (
string $byUser ,
string $user ,
string $displayName
) : void {
2022-12-14 14:15:18 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , null , $displayName );
$this -> featureContext -> setResponse ( $response );
}
2023-03-10 09:02:33 +01:00
/**
* @When /^the user "([^"]*)" changes the user name of user "([^"]*)" to "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to change the user name of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $userName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theUserChangesTheUserNameOfUserToUsingTheGraphApi (
string $byUser ,
string $user ,
string $userName
) : void {
2023-03-10 09:02:33 +01:00
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , $userName );
$this -> featureContext -> setResponse ( $response );
2024-04-26 15:27:00 +05:45
// need to add user to list to delete him after test
2024-07-18 16:17:52 +05:45
if ( ! empty ( $userName ) && $this -> featureContext -> getAttributeOfCreatedUser ( $userName , 'id' )) {
2023-03-10 09:02:33 +01:00
$this -> featureContext -> addUserToCreatedUsersList ( $userName , $this -> featureContext -> getUserPassword ( $user ));
}
}
2023-03-06 12:07:55 +01:00
/**
* @When /^the user "([^"]*)" disables user "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to disable user "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserDisablesUserToUsingTheGraphApi ( string $byUser , string $user ) : void {
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , null , null , false );
$this -> featureContext -> setResponse ( $response );
}
/**
2024-01-11 11:31:55 +05:45
* @Given /^the user "([^"]*)" has disabled user "([^"]*)"$/
2023-03-06 12:07:55 +01:00
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-01-11 11:31:55 +05:45
public function theUserHasDisabledUser ( string $byUser , string $user ) : void {
2024-05-06 09:36:35 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user , null , null , null , null , false );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , '' , $response );
2023-03-06 12:07:55 +01:00
}
/**
* @When /^the user "([^"]*)" enables user "([^"]*)" using the Graph API$/
* @When /^the user "([^"]*)" tries to enable user "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserEnablesUserToUsingTheGraphApi ( string $byUser , string $user ) : void {
2023-05-02 17:25:56 +05:45
$response = $this -> editUserUsingTheGraphApi ( $byUser , $user );
2023-03-06 12:07:55 +01:00
$this -> featureContext -> setResponse ( $response );
}
2022-12-14 14:15:18 +05:45
/**
2023-04-05 14:05:34 +05:45
* @Then /^the user information of "([^"]*)" should match this JSON schema$/
2022-12-14 14:15:18 +05:45
*
* @param string $user
2023-04-05 14:05:34 +05:45
* @param PyStringNode $schemaString
2022-12-14 14:15:18 +05:45
*
* @return void
* @throws Exception
* @throws GuzzleException
* @throws JsonException
*/
2023-04-05 14:05:34 +05:45
public function theUserInformationShouldMatchTheJSON ( string $user , PyStringNode $schemaString ) : void {
2023-10-31 12:17:50 +05:45
$response = $this -> adminHasRetrievedUserUsingTheGraphApi ( $user );
2024-02-23 16:24:22 +05:45
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
$this -> featureContext -> assertJsonDocumentMatchesSchema (
$responseBody ,
$this -> featureContext -> getJSONSchema ( $schemaString )
);
2022-12-14 14:15:18 +05:45
}
/**
* Edits the user information
*
* @param string $byUser
* @param string $user
* @param string|null $userName
* @param string|null $password
* @param string|null $email
* @param string|null $displayName
2023-03-06 12:07:55 +01:00
* @param bool|true $accountEnabled
2023-10-31 12:17:50 +05:45
* @param string $method
2022-12-14 14:15:18 +05:45
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function editUserUsingTheGraphApi (
string $byUser ,
string $user ,
string $userName = null ,
string $password = null ,
string $email = null ,
string $displayName = null ,
bool $accountEnabled = true ,
string $method = "PATCH"
) : ResponseInterface {
2022-12-14 14:15:18 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' ) ?: $user ;
2022-12-14 14:15:18 +05:45
return GraphHelper :: editUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$byUser ,
$this -> featureContext -> getPasswordForUser ( $byUser ),
$userId ,
2023-10-31 12:17:50 +05:45
$method ,
2022-12-14 14:15:18 +05:45
$userName ,
$password ,
$email ,
2023-03-06 12:07:55 +01:00
$displayName ,
$accountEnabled
2022-12-14 14:15:18 +05:45
);
}
2022-04-06 20:16:33 +05:45
/**
2022-03-25 15:33:35 +05:45
* @param string $user
*
2023-10-31 12:17:50 +05:45
* @return ResponseInterface
2022-04-06 20:16:33 +05:45
* @throws JsonException
2022-03-25 15:33:35 +05:45
* @throws GuzzleException
*/
2023-10-31 12:17:50 +05:45
public function adminHasRetrievedUserUsingTheGraphApi ( string $user ) : ResponseInterface {
2022-03-25 15:33:35 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2023-03-09 16:21:50 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
2023-05-02 17:25:56 +05:45
$userId = $userId ?: $user ;
2023-10-31 12:17:50 +05:45
return GraphHelper :: getUser (
2022-03-25 15:33:35 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
2022-04-06 20:48:29 +05:45
$userId
2022-04-06 20:16:33 +05:45
);
}
2022-11-23 17:20:37 +05:45
/**
* @param string $groupId
* @param string|null $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
2024-04-18 17:28:38 +05:45
public function deleteGroupWithId (
2022-11-23 17:20:37 +05:45
string $groupId ,
? string $user = null
) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: deleteGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$groupId
);
}
2022-04-06 20:16:33 +05:45
/**
* @param string $group
*
2024-04-18 17:28:38 +05:45
* @return ResponseInterface
2022-04-06 20:16:33 +05:45
* @throws Exception
* @throws GuzzleException
*/
2024-04-18 17:28:38 +05:45
public function deleteGroupWithName (
2022-04-06 20:16:33 +05:45
string $group
2024-04-18 17:28:38 +05:45
) : ResponseInterface {
2022-04-06 20:16:33 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
2024-04-18 17:28:38 +05:45
return $this -> deleteGroupWithId ( $groupId );
2022-04-06 20:16:33 +05:45
}
/**
* sends a request to delete a user using the Graph API
*
* @param string $user username is used as the id
2022-11-30 18:54:09 +05:45
* @param string|null $byUser
2022-04-06 20:16:33 +05:45
*
2023-12-01 14:02:39 +05:45
* @return ResponseInterface
2022-04-06 20:16:33 +05:45
* @throws GuzzleException
*/
2023-10-31 12:01:36 +05:45
public function adminDeletesUserUsingTheGraphApi ( string $user , ? string $byUser = null ) : ResponseInterface {
2022-11-30 18:54:09 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2023-10-31 12:01:36 +05:45
return GraphHelper :: deleteUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$user
2022-03-25 15:33:35 +05:45
);
}
2022-11-28 14:13:52 +05:45
/**
2024-04-26 15:27:00 +05:45
* remove user from a group
2022-11-28 14:13:52 +05:45
*
2023-11-29 10:35:55 +05:45
* @param string $group
* @param string $user
2022-11-28 14:13:52 +05:45
* @param string|null $byUser
*
* @return ResponseInterface
* @throws GuzzleException
*/
2023-11-29 10:35:55 +05:45
public function removeUserFromGroup ( string $group , string $user , ? string $byUser = null ) : ResponseInterface {
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" ) ?: WebDavHelper :: generateUUIDv4 ();
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
2022-11-28 14:13:52 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
return GraphHelper :: removeUserFromGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
$groupId ,
);
}
2023-03-21 10:03:51 +05:45
/**
* sends a request to delete a user with the help of userID using the Graph API
*
* @param string $userId
* @param string $byUser
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function deleteUserByUserIdUsingTheGraphApi ( string $userId , string $byUser ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
return GraphHelper :: deleteUserByUserId (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$userId
);
}
2022-11-30 18:54:09 +05:45
/**
* @When /^the user "([^"]*)" deletes a user "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theUserDeletesAUserUsingTheGraphAPI ( string $byUser , string $user ) : void {
2023-03-21 10:03:51 +05:45
$userId = $this -> featureContext -> getUserIdByUserName ( $user );
$this -> featureContext -> setResponse ( $this -> deleteUserByUserIdUsingTheGraphApi ( $userId , $byUser ));
}
/**
* @When /^the user "([^"]*)" tries to delete a nonexistent user using the Graph API$/
*
* @param string $byUser
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function theUserTriesToDeleteNonExistingUser ( string $byUser ) : void {
$userId = WebDavHelper :: generateUUIDv4 ();
$this -> featureContext -> setResponse ( $this -> deleteUserByUserIdUsingTheGraphApi ( $userId , $byUser ));
2022-11-30 18:54:09 +05:45
}
2023-03-06 12:07:55 +01:00
/**
2024-01-11 14:21:28 +05:45
* @Given /^the user "([^"]*)" has deleted a user "([^"]*)"$/
2023-03-06 12:07:55 +01:00
*
* @param string $byUser
* @param string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-01-11 14:21:28 +05:45
public function theUserHasDeletedAUser ( string $byUser , string $user ) : void {
2023-10-31 12:01:36 +05:45
$response = $this -> adminDeletesUserUsingTheGraphApi ( $user , $byUser );
$this -> featureContext -> theHttpStatusCodeShouldBe ( 204 , "" , $response );
2023-03-06 12:07:55 +01:00
}
2022-03-25 15:33:35 +05:45
/**
2022-04-06 20:16:33 +05:45
* @param string $user
* @param string $group
2022-03-25 15:33:35 +05:45
*
* @return void
2022-04-06 20:16:33 +05:45
* @throws JsonException
* @throws GuzzleException
*/
2022-04-19 10:21:05 +05:45
public function adminHasRemovedUserFromGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-04-06 20:16:33 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2023-11-29 10:35:55 +05:45
$response = $this -> removeUserFromGroup ( $group , $user );
$this -> featureContext -> TheHTTPStatusCodeShouldBe ( 204 , '' , $response );
2022-04-06 20:16:33 +05:45
}
/**
* 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
2022-03-25 15:33:35 +05:45
* @throws GuzzleException
*/
2022-04-06 20:16:33 +05:45
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 ;
}
2022-03-25 15:33:35 +05:45
}
2022-04-06 20:16:33 +05:45
return $found ;
2022-03-25 15:33:35 +05:45
}
2022-04-12 19:35:05 +05:45
/**
* @param string $user
* @param string $group
*
* @return void
* @throws JsonException
* @throws GuzzleException
*/
2022-04-19 10:21:05 +05:45
public function userShouldNotBeMemberInGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-04-06 20:16:33 +05:45
$found = $this -> getUserPresenceInGroupUsingTheGraphApi ( $user , $group );
Assert :: assertFalse ( $found , __METHOD__ . " User $user is member of group $group " );
}
/**
* @param string $user
* @param string $group
2022-03-25 15:33:35 +05:45
*
* @return void
2022-04-06 20:16:33 +05:45
* @throws JsonException
2022-04-06 20:48:29 +05:45
* @throws GuzzleException
2022-04-06 20:16:33 +05:45
*/
2022-04-19 10:21:05 +05:45
public function userShouldBeMemberInGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-04-06 20:16:33 +05:45
$found = $this -> getUserPresenceInGroupUsingTheGraphApi ( $user , $group );
Assert :: assertTrue ( $found , __METHOD__ . "User $user is not member of group $group " );
}
/**
* @param string $user
* @param string $password
2022-12-14 14:15:18 +05:45
* @param string|null $byUser
2022-04-06 20:16:33 +05:45
*
* @return void
* @throws JsonException
*/
public function adminChangesPasswordOfUserToUsingTheGraphApi (
string $user ,
2022-12-14 14:15:18 +05:45
string $password ,
? string $byUser = null
2023-10-31 12:17:50 +05:45
) : ResponseInterface {
2022-12-14 14:15:18 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2022-04-06 20:16:33 +05:45
$user = $this -> featureContext -> getActualUsername ( $user );
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" ) ?: $user ;
2023-10-31 12:17:50 +05:45
return GraphHelper :: editUser (
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
2022-12-14 14:15:18 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2022-04-06 20:16:33 +05:45
$userId ,
2023-10-31 12:17:50 +05:45
"PATCH" ,
$user ,
2022-04-06 20:16:33 +05:45
$password
);
}
2022-12-14 14:15:18 +05:45
/**
* @When /^the user "([^"]*)" resets the password of user "([^"]*)" to "([^"]*)" using the Graph API$/
*
* @param string $byUser
* @param string $user
* @param string $password
*
* @return void
* @throws Exception
*/
public function theUserResetsThePasswordOfUserToUsingTheGraphApi ( string $byUser , string $user , string $password ) {
2023-10-31 12:17:50 +05:45
$response = $this -> adminChangesPasswordOfUserToUsingTheGraphApi ( $user , $password , $byUser );
$this -> featureContext -> setResponse ( $response );
2022-12-14 14:15:18 +05:45
}
2022-04-06 20:16:33 +05:45
/**
2022-04-12 19:35:05 +05:45
*
2022-11-15 20:56:43 +05:45
* @param array $groups
*
* @return void
* @throws Exception
*/
public function theseGroupsShouldBeInTheResponse ( array $groups ) : void {
$respondedGroups = $this -> getArrayOfGroupsResponded ( $this -> featureContext -> getResponse ());
foreach ( $groups as $group ) {
$found = false ;
foreach ( $respondedGroups as $respondedGroup ) {
if ( $respondedGroup [ "displayName" ] === $group ) {
$found = true ;
break ;
}
}
Assert :: assertTrue ( $found , "Group ' $group ' not found in the list" );
}
}
/**
*
* @param array $users
*
* @return void
2022-03-25 15:33:35 +05:45
* @throws Exception
2022-11-15 20:56:43 +05:45
*/
public function theseUsersShouldBeInTheResponse ( array $users ) : void {
$respondedUsers = $this -> getArrayOfUsersResponded ( $this -> featureContext -> getResponse ());
foreach ( $users as $user ) {
$found = false ;
foreach ( $respondedUsers as $respondedUser ) {
if ( $respondedUser [ "onPremisesSamAccountName" ] === $user ) {
$found = true ;
break ;
}
}
Assert :: assertTrue ( $found , "User ' $user ' not found in the list" );
}
}
/**
*
* @param string|null $user
*
* @return array
*/
public function getAdminOrUserCredentials ( ? string $user ) : array {
2024-12-24 09:30:42 +05:45
$credentials [ "username" ] = $user ? $this -> featureContext -> getActualUsername ( $user )
: $this -> featureContext -> getAdminUsername ();
$credentials [ "password" ] = $user ? $this -> featureContext -> getPasswordForUser ( $user )
: $this -> featureContext -> getAdminPassword ();
2022-11-15 20:56:43 +05:45
return $credentials ;
}
/**
*
* @param string|null $user
*
* @return ResponseInterface
2022-04-12 19:35:05 +05:45
* @throws GuzzleException
2022-03-25 15:33:35 +05:45
*/
2022-11-15 20:56:43 +05:45
public function listGroups ( ? string $user = null ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getGroups (
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
2022-11-15 20:56:43 +05:45
$credentials [ "username" ],
$credentials [ "password" ]
2022-03-25 15:33:35 +05:45
);
2022-11-15 20:56:43 +05:45
}
/**
* returns list of groups
*
* @param ResponseInterface $response
*
* @return array
* @throws Exception
*/
public function getArrayOfGroupsResponded ( ResponseInterface $response ) : array {
2022-04-06 20:16:33 +05:45
if ( $response -> getStatusCode () === 200 ) {
2022-04-12 19:35:05 +05:45
$jsonResponseBody = $this -> featureContext -> getJsonDecodedResponse ( $response );
return $jsonResponseBody [ "value" ];
2022-04-06 20:16:33 +05:45
} else {
2022-04-12 19:35:05 +05:45
$this -> throwHttpException ( $response , "Could not retrieve groups list." );
2022-04-06 20:16:33 +05:45
}
}
/**
*
* @return array
* @throws Exception
* @throws GuzzleException
*/
2022-11-15 20:56:43 +05:45
public function adminHasRetrievedGroupListUsingTheGraphApi () : array {
2024-12-24 09:30:42 +05:45
return $this -> getArrayOfGroupsResponded ( $this -> listGroups ());
2022-11-15 20:56:43 +05:45
}
/**
*
* @param string $group
* @param string|null $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function listGroupMembers ( string $group , ? string $user = null ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getMembersList (
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
2022-11-15 20:56:43 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2022-04-06 20:16:33 +05:45
$this -> featureContext -> getAttributeOfCreatedGroup ( $group , 'id' )
);
2022-11-15 20:56:43 +05:45
}
2023-02-27 11:16:50 +05:45
/**
*
* @param string $user
* @param string|null $group
*
* @return ResponseInterface
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function listSingleOrAllGroupsAlongWithAllMemberInformation (
string $user ,
? string $group = null
) : ResponseInterface {
2023-02-27 11:16:50 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getSingleOrAllGroupsAlongWithMembers (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
( $group ) ? $this -> featureContext -> getAttributeOfCreatedGroup ( $group , 'id' ) : null
);
}
2022-11-15 20:56:43 +05:45
/**
* returns list of users of a group
*
* @param ResponseInterface $response
*
* @return array
* @throws Exception
*/
public function getArrayOfUsersResponded ( ResponseInterface $response ) : array {
2022-04-06 20:16:33 +05:45
if ( $response -> getStatusCode () === 200 ) {
2022-04-06 20:48:29 +05:45
return $this -> featureContext -> getJsonDecodedResponse ( $response );
2022-04-06 20:16:33 +05:45
} else {
2022-11-15 20:56:43 +05:45
$this -> throwHttpException ( $response , "Could not retrieve group members list." );
2022-04-06 20:16:33 +05:45
}
}
2022-11-15 20:56:43 +05:45
/**
2024-04-26 15:27:00 +05:45
* returns a list of members in a group
2022-11-15 20:56:43 +05:45
*
* @param string $group
*
* @return array
* @throws Exception
* @throws GuzzleException
*/
public function theAdminHasRetrievedMembersListOfGroupUsingTheGraphApi ( string $group ) : array {
return $this -> getArrayOfUsersResponded ( $this -> listGroupMembers ( $group ));
}
2022-11-04 12:39:54 +01:00
/**
2023-10-11 15:55:26 +05:45
* @When /^the user "([^"]*)" creates a new user with the following attributes using the Graph API:$/
2022-11-04 12:39:54 +01:00
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws Exception|GuzzleException
*/
public function theUserCreatesNewUser ( string $user , TableNode $table ) : void {
$rows = $table -> getRowsHash ();
$response = GraphHelper :: createUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$rows [ "userName" ],
$rows [ "password" ],
$rows [ "email" ],
$rows [ "displayName" ]
);
// add created user to list except for the user with an empty name
// because request /graph/v1.0/users/emptyUserName exits with 200
// and we cannot check that the user with empty name doesn't exist
if ( ! empty ( $rows [ "userName" ])) {
$this -> featureContext -> addUserToCreatedUsersList (
$rows [ "userName" ],
$rows [ "password" ],
$rows [ "displayName" ],
$rows [ "email" ]
);
}
$this -> featureContext -> setResponse ( $response );
}
2022-03-25 15:33:35 +05:45
/**
2022-04-06 20:16:33 +05:45
* adds a user to a group
2023-10-17 11:34:53 +05:45
* NOTE: If you want to make a request with non-existing user or group,provide "nonexistent" as their name
2022-03-25 15:33:35 +05:45
*
2022-11-23 16:18:04 +05:45
* @param string $group
* @param string $user
* @param string|null $byUser
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function addUserToGroup ( string $group , string $user , ? string $byUser = null ) : ResponseInterface {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2023-10-17 11:34:53 +05:45
if ( $group === "nonexistent" ) {
$groupId = WebDavHelper :: generateUUIDv4 ();
} else {
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
}
if ( $user === "nonexistent" ) {
$userId = WebDavHelper :: generateUUIDv4 ();
} else {
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
}
2022-11-23 16:18:04 +05:45
return GraphHelper :: addUserToGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
$groupId
);
}
/**
2023-10-30 17:57:42 +05:45
* @Given /^the administrator has added a user "([^"]*)" to the group "([^"]*)" using the Graph API$/
2022-07-08 05:18:40 +02:00
*
2022-04-06 20:16:33 +05:45
* @param string $user
2022-04-06 20:48:29 +05:45
* @param string $group
2022-03-25 15:33:35 +05:45
*
* @return void
2022-04-06 20:16:33 +05:45
* @throws Exception
2022-03-25 15:33:35 +05:45
* @throws GuzzleException
*/
2022-04-06 20:16:33 +05:45
public function adminHasAddedUserToGroupUsingTheGraphApi (
string $user ,
2024-04-26 15:27:00 +05:45
string $group
2022-04-19 10:21:05 +05:45
) : void {
2023-10-17 11:34:53 +05:45
$response = $this -> addUserToGroup ( $group , $user );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , '' , $response );
2022-03-25 15:33:35 +05:45
}
2022-11-23 16:18:04 +05:45
/**
* @When the administrator adds the following users to the following groups using the Graph API
*
* @param TableNode $table
*
* @return void
*/
public function theAdministratorAddsTheFollowingUsersToTheFollowingGroupsUsingTheGraphAPI ( TableNode $table ) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' , 'groupname' ]);
$userGroupList = $table -> getColumnsHash ();
foreach ( $userGroupList as $userGroup ) {
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $userGroup [ 'groupname' ], $userGroup [ 'username' ]));
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
}
}
/**
2023-10-17 11:34:53 +05:45
* @When the administrator tries to add nonexistent user to group :group using the Graph API
2024-07-18 16:17:52 +05:45
* @When user :byUser tries to add nonexistent user to group :group using the Graph API
2022-11-23 16:18:04 +05:45
*
* @param string $group
2024-07-18 16:17:52 +05:45
* @param string|null $byUser
2022-11-23 16:18:04 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddNonExistentUserToGroupUsingTheGraphAPI (
string $group ,
? string $byUser = null
) : void {
2024-07-18 16:17:52 +05:45
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $group , "nonexistent" , $byUser ));
2022-11-23 16:18:04 +05:45
}
2022-11-22 13:03:56 +05:45
2023-03-09 16:21:50 +05:45
/**
* @When the administrator tries to add user :user to a nonexistent group using the Graph API
2024-07-18 16:17:52 +05:45
* @When user :byUser tries to add user :user to a nonexistent group using the Graph API
2023-03-09 16:21:50 +05:45
*
* @param string $user
* @param string|null $byUser
*
* @return void
*
* @throws GuzzleException | Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddUserToNonExistentGroupUsingTheGraphAPI (
string $user ,
? string $byUser = null
) : void {
2023-10-17 11:34:53 +05:45
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( "nonexistent" , $user , $byUser ));
2023-03-09 16:21:50 +05:45
}
2022-11-23 16:18:04 +05:45
/**
* @When user :user tries to add himself/herself to group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
*/
public function theUserTriesToAddHimselfToGroupUsingTheGraphAPI ( string $user , string $group ) : void {
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $group , $user , $user ));
}
/**
* @When user :byUser tries to add user :user to group :group using the Graph API
*
* @param string $byUser
* @param string $user
* @param string $group
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theUserTriesToAddAnotherUserToGroupUsingTheGraphAPI (
string $byUser ,
string $user ,
string $group
) : void {
2024-11-25 16:59:11 +05:45
$this -> featureContext -> setResponse ( $this -> addUserToGroup ( $group , $user , $byUser ));
2022-11-23 16:18:04 +05:45
}
2022-08-19 17:16:12 +05:45
/**
*
* @param string $group
2022-11-11 09:31:13 +05:45
* @param ?string $user
2022-08-19 17:16:12 +05:45
*
2022-11-11 09:31:13 +05:45
* @return ResponseInterface
2022-08-19 17:16:12 +05:45
* @throws GuzzleException
*/
2022-11-11 09:31:13 +05:45
public function createGroup ( string $group , ? string $user = null ) : ResponseInterface {
2022-11-15 20:56:43 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2022-11-11 09:31:13 +05:45
return GraphHelper :: createGroup (
2022-08-19 17:16:12 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
2022-11-15 20:56:43 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2022-08-19 17:16:12 +05:45
$group ,
);
2022-11-11 09:31:13 +05:45
}
/**
* @When /^the administrator creates a group "([^"]*)" using the Graph API$/
* @When user :user creates a group :group using the Graph API
* @When user :user tries to create a group :group using the Graph API
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userCreatesGroupUsingTheGraphApi ( string $group , ? string $user = null ) : void {
$response = $this -> createGroup ( $group , $user );
2022-08-19 17:16:12 +05:45
$this -> featureContext -> setResponse ( $response );
$this -> featureContext -> pushToLastHttpStatusCodesArray (( string ) $response -> getStatusCode ());
2023-11-15 17:45:23 +01:00
if ( $response -> getStatusCode () === 201 ) {
2022-08-19 17:16:12 +05:45
$groupId = $this -> featureContext -> getJsonDecodedResponse ( $response )[ "id" ];
$this -> featureContext -> addGroupToCreatedGroupsList ( $group , true , true , $groupId );
}
}
2023-03-07 14:36:04 +05:45
/**
* @Given /^the administrator has created a group "([^"]*)" using the Graph API$/
* @Given user :user has created a group :group using the Graph API
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function userHasCreatedGroupUsingTheGraphApi ( string $group , ? string $user = null ) : void {
$response = $this -> createGroup ( $group , $user );
2023-11-15 17:45:23 +01:00
if ( $response -> getStatusCode () === 201 ) {
2023-03-07 14:36:04 +05:45
$groupId = $this -> featureContext -> getJsonDecodedResponse ( $response )[ "id" ];
$this -> featureContext -> addGroupToCreatedGroupsList ( $group , true , true , $groupId );
} else {
$this -> throwHttpException ( $response , "Could not create group ' $group '." );
}
}
2022-04-12 19:35:05 +05:45
/**
* @param ResponseInterface $response
* @param string $errorMsg
*
* @return void
* @throws Exception
*/
2022-04-19 10:21:05 +05:45
private function throwHttpException ( ResponseInterface $response , string $errorMsg ) : void {
2022-04-12 19:35:05 +05:45
try {
$jsonBody = $this -> featureContext -> getJsonDecodedResponse ( $response );
throw new Exception (
__METHOD__
. " \n $errorMsg "
. " \n HTTP status code: " . $response -> getStatusCode ()
. " \n Error code: " . $jsonBody [ "error" ][ "code" ]
. " \n Message: " . $jsonBody [ "error" ][ "message" ]
);
} catch ( TypeError $e ) {
throw new Exception (
__METHOD__
. " \n $errorMsg "
. " \n HTTP status code: " . $response -> getStatusCode ()
. " \n Response body: " . $response -> getBody ()
);
2022-03-25 15:33:35 +05:45
}
}
2022-04-13 12:53:20 +05:45
2022-04-19 10:21:05 +05:45
/**
* @param string $shouldOrNot (not|)
* @param TableNode $table
*
2022-09-06 12:32:56 +05:45
* @return void
2022-04-19 10:21:05 +05:45
* @throws GuzzleException
* @throws Exception
*/
public function theseGroupsShouldNotExist ( string $shouldOrNot , TableNode $table ) : void {
$should = ( $shouldOrNot !== "not" );
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'groupname' ]);
$actualGroupsList = $this -> adminHasRetrievedGroupListUsingTheGraphApi ();
$expectedGroups = $table -> getColumnsHash ();
// check if every expected group is(not) in the actual groups list
foreach ( $expectedGroups as $expectedGroup ) {
$groupName = $expectedGroup [ 'groupname' ];
$groupExists = false ;
foreach ( $actualGroupsList as $actualGroup ) {
if ( $actualGroup [ 'displayName' ] === $groupName ) {
$groupExists = true ;
break ;
}
}
if ( $groupExists !== $should ) {
throw new Exception (
__METHOD__
. " \n Group ' $groupName ' is expected " . ( $should ? "" : "not " )
. "to exist, but it does" . ( $should ? " not" : "" ) . " exist."
);
}
}
}
2022-08-31 13:02:33 +02:00
/**
* @When /^the user "([^"]*)" changes its own password "([^"]*)" to "([^"]*)" using the Graph API$/
2022-09-06 12:32:56 +05:45
*
2022-08-31 13:02:33 +02:00
* @param string $user
* @param string $currentPassword
* @param string $newPassword
*
2022-09-06 12:32:56 +05:45
* @return void
2022-08-31 13:02:33 +02:00
* @throws GuzzleException
* @throws Exception
*/
2022-11-04 12:39:54 +01:00
public function userChangesOwnPassword ( string $user , string $currentPassword , string $newPassword ) : void {
2022-08-31 13:02:33 +02:00
$response = GraphHelper :: changeOwnPassword (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$currentPassword ,
$newPassword
);
$this -> featureContext -> setResponse ( $response );
}
2022-11-15 20:56:43 +05:45
/**
* @When user :user gets all the groups using the Graph API
*
* @param string $user
*
* @return void
*/
public function userGetsAllTheGroupsUsingTheGraphApi ( string $user ) : void {
$this -> featureContext -> setResponse ( $this -> listGroups ( $user ));
}
/**
* @When user :user gets all the members of group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
*/
2023-05-02 17:25:56 +05:45
public function userGetsAllTheMembersOfGroupUsingTheGraphApi ( string $user , string $group ) : void {
2022-11-15 20:56:43 +05:45
$this -> featureContext -> setResponse ( $this -> listGroupMembers ( $group , $user ));
}
2023-02-27 11:16:50 +05:45
/**
* @When user :user retrieves all groups along with their members using the Graph API
* @When user :user gets all the members information of group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
* @throws GuzzleException
*/
public function userRetrievesAllMemberInformationOfSingleOrAllGroups ( string $user , string $group = '' ) : void {
$this -> featureContext -> setResponse ( $this -> listSingleOrAllGroupsAlongWithAllMemberInformation ( $user , $group ));
}
2022-11-23 17:20:37 +05:45
/**
* @When user :user deletes group :group using the Graph API
* @When the administrator deletes group :group using the Graph API
* @When user :user tries to delete group :group using the Graph API
*
* @param string $group
* @param string|null $user
*
* @return void
*/
2023-01-10 12:03:52 +01:00
public function userDeletesGroupUsingTheGraphApi ( string $group , ? string $user = null ) : void {
2024-07-18 16:17:52 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" ) ?: $group ;
2024-04-18 17:28:38 +05:45
$response = $this -> deleteGroupWithId ( $groupId , $user );
if ( $response -> getStatusCode () === 204 ) {
$this -> featureContext -> rememberThatGroupIsNotExpectedToExist ( $group );
}
2022-11-23 17:20:37 +05:45
$this -> featureContext -> setResponse ( $response );
}
2022-11-22 13:03:56 +05:45
2022-11-23 16:18:04 +05:45
/**
* @Then the following users should be listed in the following groups
*
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function theFollowingUsersShouldBeListedInFollowingGroups ( TableNode $table ) : void {
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' , 'groupname' ]);
$usersGroups = $table -> getColumnsHash ();
foreach ( $usersGroups as $userGroup ) {
$members = $this -> listGroupMembers ( $userGroup [ 'groupname' ]);
$members = $this -> featureContext -> getJsonDecodedResponse ( $members );
$exists = false ;
foreach ( $members as $member ) {
if ( $member [ 'onPremisesSamAccountName' ] === $userGroup [ 'username' ]) {
$exists = true ;
break ;
}
}
Assert :: assertTrue (
$exists ,
__METHOD__
2024-12-24 09:30:42 +05:45
. " \n Expected user '" . $userGroup [ 'username' ] . "' to be in group '"
. $userGroup [ 'groupname' ] . "'. But not found."
2022-11-23 16:18:04 +05:45
);
}
}
2022-11-24 15:13:27 +05:45
/**
* rename group name
*
2023-03-28 09:09:37 +05:45
* @param string $oldGroupId
2022-11-24 15:13:27 +05:45
* @param string $newGroup
2023-05-02 17:25:56 +05:45
* @param string|null $user
2022-11-24 15:13:27 +05:45
*
* @return ResponseInterface
* @throws GuzzleException
*/
2023-03-28 09:09:37 +05:45
public function renameGroup ( string $oldGroupId , string $newGroup , ? string $user = null ) : ResponseInterface {
2022-11-24 15:13:27 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: updateGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2023-03-28 09:09:37 +05:45
$oldGroupId ,
2022-11-24 15:13:27 +05:45
$newGroup
);
}
/**
* @When user :user renames group :oldGroup to :newGroup using the Graph API
2023-03-28 09:09:37 +05:45
* @When user :user tries to rename group :oldGroup to :newGroup using the Graph API
2022-11-24 15:13:27 +05:45
*
* @param string $user
* @param string $oldGroup
* @param string $newGroup
*
* @return void
2023-03-28 09:09:37 +05:45
* @throws GuzzleException
2022-11-24 15:13:27 +05:45
*/
public function userRenamesGroupUsingTheGraphApi ( string $user , string $oldGroup , string $newGroup ) : void {
2023-03-28 09:09:37 +05:45
$oldGroupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $oldGroup , "id" );
$this -> featureContext -> setResponse ( $this -> renameGroup ( $oldGroupId , $newGroup , $user ));
}
/**
* @When user :user tries to rename a nonexistent group to :newGroup using the Graph API
*
* @param string $user
* @param string $newGroup
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userTriesToRenameNonExistentGroupToNewGroupName ( string $user , string $newGroup ) : void {
$oldGroupId = WebDavHelper :: generateUUIDv4 ();
$this -> featureContext -> setResponse ( $this -> renameGroup ( $oldGroupId , $newGroup , $user ));
2022-11-24 15:13:27 +05:45
}
2022-11-28 14:13:52 +05:45
/**
* @When the administrator removes the following users from the following groups using the Graph API
*
* @param TableNode $table
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorRemovesTheFollowingUsersFromTheFollowingGroupsUsingTheGraphApi (
TableNode $table
) : void {
2022-11-28 14:13:52 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' , 'groupname' ]);
$usersGroups = $table -> getColumnsHash ();
foreach ( $usersGroups as $userGroup ) {
2024-12-24 09:30:42 +05:45
$this -> featureContext -> setResponse (
$this -> removeUserFromGroup ( $userGroup [ 'groupname' ], $userGroup [ 'username' ])
);
2022-11-28 14:13:52 +05:45
$this -> featureContext -> pushToLastHttpStatusCodesArray ();
}
}
/**
* @When user :byUser tries to remove user :user from group :group using the Graph API
*
* @param string $user
* @param string $group
* @param string|null $byUser
*
* @return void
2023-03-09 16:21:50 +05:45
* @throws Exception | GuzzleException
2022-11-28 14:13:52 +05:45
*/
2024-12-24 09:30:42 +05:45
public function theUserTriesToRemoveAnotherUserFromGroupUsingTheGraphAPI (
string $user ,
string $group ,
? string $byUser = null
) : void {
2023-11-29 10:35:55 +05:45
$this -> featureContext -> setResponse ( $this -> removeUserFromGroup ( $group , $user , $byUser ));
2023-03-09 16:21:50 +05:45
}
/**
* @When the administrator tries to remove user :user from a nonexistent group using the Graph API
* @When user :byUser tries to remove user :user from a nonexistent group using the Graph API
*
* @param string $user
* @param string|null $byUser
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function theUserTriesToRemoveAnotherUserFromNonExistentGroupUsingTheGraphAPI (
string $user ,
? string $byUser = null
) : void {
2023-11-29 10:35:55 +05:45
$this -> featureContext -> setResponse ( $this -> removeUserFromGroup ( '' , $user , $byUser ));
2022-11-28 14:13:52 +05:45
}
2022-11-22 13:03:56 +05:45
/**
* @param string $user
*
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function retrieveUserInformationUsingGraphApi (
string $user
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-11-22 13:03:56 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2022-11-24 14:12:26 +05:45
return GraphHelper :: getOwnInformationAndGroupMemberships (
2022-11-22 13:03:56 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
);
}
/**
2022-11-24 14:12:26 +05:45
* @When /^the user "([^"]*)" retrieves (her|his) information using the Graph API$/
2022-11-22 13:03:56 +05:45
*
* @param string $user
*
* @return void
* @throws JsonException
*/
2023-04-21 14:59:50 +05:45
public function userRetrievesHisOrHerInformationOfUserUsingGraphApi (
2022-11-22 13:03:56 +05:45
string $user
2024-12-24 09:30:42 +05:45
) : void {
2022-11-22 13:03:56 +05:45
$response = $this -> retrieveUserInformationUsingGraphApi ( $user );
$this -> featureContext -> setResponse ( $response );
}
2022-11-29 16:39:10 +05:45
/**
2022-12-19 11:34:25 +05:45
* @When user :byUser tries to get information of user :user using Graph API
* @When user :byUser gets information of user :user using Graph API
2022-11-29 16:39:10 +05:45
*
2022-12-19 11:34:25 +05:45
* @param string $byUser
2022-11-29 16:39:10 +05:45
* @param string $user
*
* @return void
2022-12-19 11:34:25 +05:45
* @throws GuzzleException
2022-11-29 16:39:10 +05:45
*/
2022-12-19 11:34:25 +05:45
public function userTriesToGetInformationOfUser ( string $byUser , string $user ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
2022-11-29 16:39:10 +05:45
$response = GraphHelper :: getUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
2022-12-19 11:34:25 +05:45
$user
2022-11-29 16:39:10 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-01-18 15:14:10 +05:45
/**
* @When user :byUser tries to search for user :searchTerm using Graph API
* @When user :byUser searches for user :searchTerm using Graph API
*
* @param string $byUser
* @param string $searchTerm
*
* @return void
* @throws GuzzleException
*/
public function userSearchesForUserUsingGraphApi ( string $byUser , string $searchTerm ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
$response = GraphHelper :: searchUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
2024-08-13 12:09:09 +02:00
$credentials [ 'username' ],
$credentials [ 'password' ],
$searchTerm ,
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When user :byUser searches for federated user :searchTerm using Graph API
*
* @param string $byUser
* @param string $searchTerm
*
* @return void
* @throws GuzzleException
*/
public function userSearchesForFederatedUserUsingGraphApi ( string $byUser , string $searchTerm ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
$response = GraphHelper :: searchFederatedUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
2024-01-18 15:14:10 +05:45
$credentials [ 'username' ],
$credentials [ 'password' ],
$searchTerm ,
);
$this -> featureContext -> setResponse ( $response );
}
2022-11-29 16:39:10 +05:45
/**
2022-12-19 11:34:25 +05:45
* @When user :user tries to get all users using the Graph API
* @When user :user gets all users using the Graph API
2022-11-29 16:39:10 +05:45
*
* @param string $user
*
* @return void
2022-12-19 11:34:25 +05:45
* @throws GuzzleException
2022-11-29 16:39:10 +05:45
*/
public function userGetsAllUserUsingTheGraphApi ( string $user ) {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$response = GraphHelper :: getUsers (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
);
$this -> featureContext -> setResponse ( $response );
}
/**
2022-12-19 11:34:25 +05:45
* @param string $byUser
* @param string|null $user
2022-11-29 16:39:10 +05:45
*
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function retrieveUserInformationAlongWithDriveUsingGraphApi (
2022-12-19 11:34:25 +05:45
string $byUser ,
? string $user = null
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-19 11:34:25 +05:45
$user = $user ?? $byUser ;
2022-11-29 16:39:10 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getUserWithDriveInformation (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
2022-12-19 11:34:25 +05:45
$user
2022-11-29 16:39:10 +05:45
);
}
2023-02-01 08:41:16 +01:00
/**
* @param string $byUser
* @param string|null $user
*
* @return ResponseInterface
* @throws JsonException
* @throws GuzzleException
*/
public function retrieveUserInformationAlongWithGroupUsingGraphApi (
string $byUser ,
? string $user = null
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2023-02-01 08:41:16 +01:00
$user = $user ?? $byUser ;
$credentials = $this -> getAdminOrUserCredentials ( $user );
return GraphHelper :: getUserWithGroupInformation (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$user
);
}
2022-11-29 16:39:10 +05:45
/**
2022-12-19 11:34:25 +05:45
* @When /^the user "([^"]*)" gets user "([^"]*)" along with (his|her) drive information using Graph API$/
2022-11-29 16:39:10 +05:45
*
2022-12-19 11:34:25 +05:45
* @param string $byUser
2022-11-29 16:39:10 +05:45
* @param string $user
*
* @return void
*/
2022-12-19 11:34:25 +05:45
public function userTriesToGetInformationOfUserAlongWithHisDriveData ( string $byUser , string $user ) {
$response = $this -> retrieveUserInformationAlongWithDriveUsingGraphApi ( $byUser , $user );
2022-11-29 16:39:10 +05:45
$this -> featureContext -> setResponse ( $response );
}
2023-02-01 08:41:16 +01:00
/**
* @When /^the user "([^"]*)" gets user "([^"]*)" along with (his|her) group information using Graph API$/
*
* @param string $byUser
* @param string $user
*
* @return void
*/
public function userTriesToGetInformationOfUserAlongWithHisGroup ( string $byUser , string $user ) {
$response = $this -> retrieveUserInformationAlongWithGroupUsingGraphApi ( $byUser , $user );
$this -> featureContext -> setResponse ( $response );
}
2022-11-29 16:39:10 +05:45
/**
*
2022-12-19 11:34:25 +05:45
* @When /^the user "([^"]*)" gets (his|her) drive information using Graph API$/
2022-11-29 16:39:10 +05:45
*
* @param string $user
*
* @return void
*/
public function userTriesToGetOwnDriveInformation ( string $user ) {
$response = $this -> retrieveUserInformationAlongWithDriveUsingGraphApi ( $user );
$this -> featureContext -> setResponse ( $response );
}
2022-11-30 16:50:58 +05:45
2023-03-07 14:36:04 +05:45
/**
* add multiple users in a group at once
*
* @param string $user
* @param array $userIds
* @param string $groupId
*
2023-10-31 12:17:50 +05:45
* @return ResponseInterface
2023-03-07 14:36:04 +05:45
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function addMultipleUsersToGroup (
string $user ,
array $userIds ,
string $groupId
) : ResponseInterface {
2023-03-07 14:36:04 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2023-10-17 11:34:53 +05:45
return GraphHelper :: addUsersToGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$groupId ,
$userIds
2023-03-07 14:36:04 +05:45
);
}
/**
* @When /^the administrator "([^"]*)" adds the following users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorAddsTheFollowingUsersToAGroupInASingleRequestUsingTheGraphApi (
string $user ,
string $group ,
TableNode $table
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
2023-03-27 15:47:55 +05:45
/**
* @When /^user "([^"]*)" tries to add the following users to a group "([^"]*)" at once with an invalid host using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddTheFollowingUsersToAGroupAtOnceWithInvalidHostUsingTheGraphApi (
string $user ,
string $group ,
TableNode $table
) : void {
2023-03-27 15:47:55 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
2023-03-31 08:59:25 +05:45
2023-03-27 15:47:55 +05:45
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
$payload = [ "members@odata.bind" => [] ];
foreach ( $userIds as $userId ) {
$payload [ "members@odata.bind" ][] = GraphHelper :: getFullUrl ( 'https://invalid/' , 'users/' . $userId );
}
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId ),
$this -> featureContext -> getStepLineRef (),
'PATCH' ,
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
\json_encode ( $payload )
)
);
}
/**
* @When /^user "([^"]*)" tries to add user "([^"]*)" to group "([^"]*)" with an invalid host using the Graph API$/
*
* @param string $adminUser
* @param string $user
* @param string $group
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddUserToGroupWithInvalidHostUsingTheGraphApi (
string $adminUser ,
string $user ,
string $group
) : void {
2023-03-27 15:47:55 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $adminUser );
$body = [
"@odata.id" => GraphHelper :: getFullUrl ( 'https://invalid/' , 'users/' . $userId )
];
$this -> featureContext -> setResponse (
HttpRequestHelper :: post (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId . '/members/$ref' ),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
\json_encode ( $body )
)
);
}
2023-03-07 14:36:04 +05:45
/**
2023-03-09 16:21:50 +05:45
* @When /^the administrator "([^"]*)" tries to add the following users to a nonexistent group at once using the Graph API$/
2023-03-07 14:36:04 +05:45
*
* @param string $user
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddsTheFollowingUsersToANonExistingGroupAtOnceUsingTheGraphApi (
string $user ,
TableNode $table
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = WebDavHelper :: generateUUIDv4 ();
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
/**
2023-03-09 16:21:50 +05:45
* @When /^the administrator "([^"]*)" tries to add the following nonexistent users to a group "([^"]*)" at once using the Graph API$/
2023-03-07 14:36:04 +05:45
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddTheFollowingNonExistingUsersToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $group ,
TableNode $table
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = WebDavHelper :: generateUUIDv4 ();
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
/**
* @When /^the administrator "([^"]*)" tries to add the following users to a group "([^"]*)" at once using the Graph API$/
2023-03-09 16:21:50 +05:45
* @When /^the administrator "([^"]*)" tries to add the following existent and nonexistent users to a group "([^"]*)" at once using the Graph API$/
2023-03-07 14:36:04 +05:45
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddTheFollowingUsersToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $group ,
TableNode $table
) : void {
2023-03-07 14:36:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
2023-03-09 16:21:50 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
2023-05-02 17:25:56 +05:45
$userIds [] = $userId ?: WebDavHelper :: generateUUIDv4 ();
2023-03-07 14:36:04 +05:45
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> setResponse ( $response );
2023-03-07 14:36:04 +05:45
}
2023-02-13 04:53:04 +01:00
/**
* @When user :user gets all applications using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userGetsAllApplicationsUsingTheGraphApi ( string $user ) {
$response = GraphHelper :: getApplications (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
);
$this -> featureContext -> setResponse ( $response );
}
/**
2023-04-24 10:58:05 +05:45
* @Then the user API response should contain the following application information:
2023-02-13 04:53:04 +01:00
*
* @param TableNode $table
*
* @return void
*/
2023-04-24 10:58:05 +05:45
public function theResponseShouldContainTheFollowingApplicationInformation ( TableNode $table ) : void {
2024-12-24 09:30:42 +05:45
Assert :: assertIsArray (
$responseArray = (
$this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())
)[ 'value' ][ 0 ]
);
2023-02-13 04:53:04 +01:00
foreach ( $table -> getHash () as $row ) {
$key = $row [ "key" ];
if ( $key === 'id' ) {
Assert :: assertTrue (
GraphHelper :: isUUIDv4 ( $responseArray [ $key ]),
__METHOD__ . ' Expected id to have UUIDv4 pattern but found: ' . $row [ "value" ]
);
} else {
Assert :: assertEquals ( $responseArray [ $key ], $row [ "value" ]);
}
}
}
/**
2023-04-24 10:58:05 +05:45
* @Then the user API response should contain the following app roles:
2023-02-13 04:53:04 +01:00
*
* @param TableNode $table
*
* @return void
*/
public function theResponseShouldContainTheFollowingAppRolesInformation ( TableNode $table ) : void {
2024-12-24 09:30:42 +05:45
Assert :: assertIsArray (
$responseArray = (
$this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())
)[ 'value' ][ 0 ]
);
2023-02-13 04:53:04 +01:00
foreach ( $table -> getRows () as $row ) {
$foundRoleInResponse = false ;
foreach ( $responseArray [ 'appRoles' ] as $role ) {
if ( $role [ 'displayName' ] === $row [ 0 ]) {
$foundRoleInResponse = true ;
break ;
}
}
Assert :: assertTrue ( $foundRoleInResponse , "the response does not contain the role $row[0] " );
}
}
2023-02-16 16:34:13 +01:00
/**
* @When the user :user gets all users of the group :group using the Graph API
*
* @param string $user
* @param string $group
*
* @return void
* @throws GuzzleException
*/
public function userGetsAllUsersOfTheGroupUsingTheGraphApi ( string $user , string $group ) {
$groupId = $this -> featureContext -> getGroupIdByGroupName ( $group );
$response = GraphHelper :: getUsersWithFilterMemberOf (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$groupId
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When the user :user gets all users of two groups :groups using the Graph API
*
* @param string $user
* @param string $groups
*
* @return void
* @throws GuzzleException
*/
public function userGetsAllUsersOfTwoGroupsUsingTheGraphApi ( string $user , string $groups ) {
$groupsIdArray = [];
foreach ( explode ( ',' , $groups ) as $group ) {
2023-05-02 17:25:56 +05:45
$groupsIdArray [] = $this -> featureContext -> getGroupIdByGroupName ( $group );
2023-02-16 16:34:13 +01:00
}
$response = GraphHelper :: getUsersOfTwoGroups (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$groupsIdArray
);
$this -> featureContext -> setResponse ( $response );
}
2023-02-23 09:53:12 +01:00
2023-03-10 09:05:00 +01:00
/**
2023-04-17 17:05:12 +05:45
* @When the user :user gets all users that are members in the group :firstGroup or the group :secondGroup using the Graph API
2023-03-10 09:05:00 +01:00
*
* @param string $user
* @param string $firstGroup
* @param string $secondGroup
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllUsersOfFirstGroupOderSecondGroupUsingTheGraphApi (
string $user ,
string $firstGroup ,
string $secondGroup
) {
2023-03-10 09:05:00 +01:00
$response = GraphHelper :: getUsersFromOneOrOtherGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$firstGroup ,
$secondGroup
);
$this -> featureContext -> setResponse ( $response );
}
2023-02-23 09:53:12 +01:00
/**
* Get roleId by role name
*
* @param string $role
*
* @return string
* @throws GuzzleException
*/
public function getRoleIdByRoleName ( string $role ) : string {
$response = GraphHelper :: getApplications (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword ()
);
$responseData = \json_decode ( $response -> getBody () -> getContents (), true , 512 , JSON_THROW_ON_ERROR );
if ( isset ( $responseData [ "value" ][ 0 ][ "appRoles" ])) {
foreach ( $responseData [ "value" ][ 0 ][ "appRoles" ] as $value ) {
if ( $value [ "displayName" ] === $role ) {
return $value [ "id" ];
}
}
throw new Exception ( __METHOD__ . " role with name $role not found" );
}
}
/**
* @When the user :user gets all users with role :role using the Graph API
*
* @param string $user
* @param string $role
*
* @return void
* @throws GuzzleException
*/
public function userGetsAllUsersWithRoleUsingTheGraphApi ( string $user , string $role ) {
$response = GraphHelper :: getUsersWithFilterRoleAssignment (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$this -> getRoleIdByRoleName ( $role )
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When the user :user gets all users with role :role and member of the group :group using the Graph API
*
* @param string $user
* @param string $role
* @param string $group
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userGetsAllUsersWithRoleAndMemberOfGroupUsingTheGraphApi (
string $user ,
string $role ,
string $group
) {
2023-02-23 09:53:12 +01:00
$response = GraphHelper :: getUsersWithFilterRolesAssignmentAndMemberOf (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$this -> getRoleIdByRoleName ( $role ),
$this -> featureContext -> getGroupIdByGroupName ( $group )
);
$this -> featureContext -> setResponse ( $response );
}
2023-02-20 09:49:05 +05:45
/**
* @Given /^the administrator has assigned the role "([^"]*)" to user "([^"]*)" using the Graph API$/
*
* @param string $role
* @param string $user
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theAdministratorHasGivenTheRoleUsingTheGraphApi ( string $role , string $user ) : void {
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' ) ?: $user ;
2023-02-20 09:49:05 +05:45
if ( empty ( $this -> appEntity )) {
2023-03-03 09:17:34 +05:45
$this -> setApplicationEntity ();
2023-02-20 09:49:05 +05:45
}
$response = GraphHelper :: assignRole (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
$this -> appEntity [ "appRoles" ][ $role ],
$this -> appEntity [ "id" ],
$userId
);
Assert :: assertEquals (
201 ,
$response -> getStatusCode (),
__METHOD__
. " \n Expected status code '200' but got '" . $response -> getStatusCode () . "'"
);
}
/**
* @When /^the administrator retrieves the assigned role of user "([^"]*)" using the Graph API$/
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userRetrievesAssignedRoleUsingTheGraphApi ( string $user ) : void {
$admin = $this -> featureContext -> getAdminUserName ();
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' ) ?: $user ;
2023-02-20 09:49:05 +05:45
$this -> featureContext -> setResponse (
GraphHelper :: getAssignedRole (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$admin ,
$this -> featureContext -> getPasswordForUser ( $admin ),
$userId
)
);
}
2024-07-18 16:17:52 +05:45
/**
* @When /^user "([^"]*)" tries to get the assigned role of user "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $ofUser
*
* @return void
* @throws GuzzleException
*/
public function userTriesToGetAssignedRoleOfUserUsingTheGraphApi ( string $user , string $ofUser ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' ) ?: $user ;
$this -> featureContext -> setResponse (
GraphHelper :: getAssignedRole (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId
)
);
}
2023-03-03 09:17:34 +05:45
/**
* set application Entity in global variable
*
* @return void
* @throws GuzzleException
*/
public function setApplicationEntity () : void {
$applicationEntity = (
$this -> featureContext -> getJsonDecodedResponse (
GraphHelper :: getApplications (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
)
)
)[ 'value' ][ 0 ];
$this -> appEntity [ "id" ] = $applicationEntity [ "id" ];
foreach ( $applicationEntity [ "appRoles" ] as $value ) {
$this -> appEntity [ "appRoles" ][ $value [ 'displayName' ]] = $value [ 'id' ];
}
}
2023-02-20 09:49:05 +05:45
/**
* @Then /^the Graph API response should have the role "([^"]*)"$/
*
* @param string $role
*
* @return void
* @throws Exception
2023-03-03 09:17:34 +05:45
* @throws GuzzleException
2023-02-20 09:49:05 +05:45
*/
public function theGraphApiResponseShouldHaveTheRole ( string $role ) : void {
$response = $this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())[ 'value' ][ 0 ];
2023-03-03 09:17:34 +05:45
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
2023-02-20 09:49:05 +05:45
Assert :: assertEquals (
$this -> appEntity [ "appRoles" ][ $role ],
$response [ 'appRoleId' ],
__METHOD__
2024-12-24 09:30:42 +05:45
. " \n Expected rolId for role ' $role '' to be '" . $this -> appEntity [ "appRoles" ][ $role ]
. "' but got '" . $response [ 'appRoleId' ] . "'"
2023-02-20 09:49:05 +05:45
);
}
2023-03-15 12:10:59 +05:45
2023-06-29 18:10:49 +02:00
/**
* @Then /^the Graph API response should have no role$/
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function theGraphApiResponseShouldHaveNoRole () : void {
Assert :: assertEmpty (
$this -> featureContext -> getJsonDecodedResponse ( $this -> featureContext -> getResponse ())[ 'value' ],
"the user has a role, but should not"
);
}
2023-03-15 12:10:59 +05:45
/**
* @When user :user gets details of the group :groupName using the Graph API
*
* @param string $user
* @param string $groupName
*
* @return void
*/
public function userGetsDetailsOfTheGroupUsingTheGraphApi ( string $user , string $groupName ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: getGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$groupName
)
);
}
2023-03-15 13:58:04 +05:45
2024-01-18 15:14:10 +05:45
/**
* @When user :user tries to search for group :searchTerm using Graph API
* @When user :user searches for group :searchTerm using Graph API
*
* @param string $user
* @param string $searchTerm
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userSearchesForGroupUsingGraphApi ( string $user , string $searchTerm ) : void {
2024-01-18 15:14:10 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: searchGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$searchTerm
)
);
}
2023-04-05 14:05:34 +05:45
/**
* @Then /^the JSON data of the response should (not )?contain the user "([^"]*)" in the item 'value'(?:, the user-details should match)?$/
* @Then /^the JSON data of the response should (not )?contain the group "([^"]*)" in the item 'value'(?:, the group-details should match)?$/
*
* @param string $shouldOrNot (not| )
* @param string $userOrGroup
* @param PyStringNode|null $schemaString
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldOrNotContainUserOrGroupAndMatch (
string $shouldOrNot ,
string $userOrGroup ,
? PyStringNode $schemaString = null
) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
$userOrGroupFound = false ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> displayName ) && $value -> displayName === $userOrGroup ) {
$responseBody = $value ;
$userOrGroupFound = true ;
break ;
}
}
$shouldContain = \trim ( $shouldOrNot ) !== 'not' ;
if ( ! $shouldContain && ! $userOrGroupFound ) {
return ;
}
Assert :: assertFalse (
! $shouldContain && $userOrGroupFound ,
'Response contains user or group "' . $userOrGroup . '" but should not have.'
);
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-04-05 14:05:34 +05:45
$responseBody ,
$this -> featureContext -> getJSONSchema ( $schemaString )
);
}
2023-03-15 13:58:04 +05:45
/**
* @Given /^the administrator "([^"]*)" has added the following users to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorHasAddedTheFollowingUsersToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $group ,
TableNode $table
) {
2023-03-15 13:58:04 +05:45
$userIds = [];
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = $this -> featureContext -> getAttributeOfCreatedUser ( $row [ 'username' ], "id" );
}
2023-10-17 11:34:53 +05:45
$this -> featureContext -> verifyTableNodeColumns ( $table , [ 'username' ]);
$response = $this -> addMultipleUsersToGroup ( $user , $userIds , $groupId );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 204 , '' , $response );
2023-03-15 13:58:04 +05:45
}
/**
2023-04-17 16:05:35 +05:45
* @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to another group "([^"]*)" with PATCH request using the Graph API$/
2023-03-15 13:58:04 +05:45
*
* @param string $user
* @param string $groupToAdd
* @param string $group
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddGroupToAGroupAtOnceUsingTheGraphApi (
string $user ,
string $groupToAdd ,
string $group
) {
2023-03-15 13:58:04 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$groupIdToAdd = $this -> featureContext -> getAttributeOfCreatedGroup ( $groupToAdd , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
2023-04-17 16:05:35 +05:45
$payload = [
2024-12-24 09:30:42 +05:45
"members@odata.bind" => [
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupIdToAdd )]
2023-04-17 16:05:35 +05:45
];
2023-03-15 13:58:04 +05:45
$this -> featureContext -> setResponse (
2023-04-17 16:05:35 +05:45
HttpRequestHelper :: sendRequest (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId ),
2023-03-15 13:58:04 +05:45
$this -> featureContext -> getStepLineRef (),
2023-04-17 16:05:35 +05:45
'PATCH' ,
2023-03-15 13:58:04 +05:45
$credentials [ "username" ],
$credentials [ "password" ],
2023-04-17 16:05:35 +05:45
[ 'Content-Type' => 'application/json' ],
\json_encode ( $payload )
)
);
}
/**
* @When /^the administrator "([^"]*)" tries to add a group "([^"]*)" to another group "([^"]*)" with POST request using the Graph API$/
*
* @param string $user
* @param string $groupToAdd
* @param string $group
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddAGroupToAGroupThroughPostRequestUsingTheGraphApi (
string $user ,
string $groupToAdd ,
string $group
) {
2023-04-17 16:05:35 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$groupIdToAdd = $this -> featureContext -> getAttributeOfCreatedGroup ( $groupToAdd , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
$payload = [
"@odata.id" => GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupIdToAdd )
];
$this -> featureContext -> setResponse (
HttpRequestHelper :: post (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId . '/members/$ref' ),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
\json_encode ( $payload )
2023-03-15 13:58:04 +05:45
)
);
}
2023-03-27 10:41:21 +05:45
/**
* @When /^user "([^"]*)" tries to add user "([^"]*)" to group "([^"]*)" with invalid JSON "([^"]*)" using the Graph API$/
*
* @param string $adminUser
* @param string $user
* @param string $group
* @param string $invalidJSON
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddUserToGroupWithInvalidJsonUsingTheGraphApi (
string $adminUser ,
string $user ,
string $group ,
string $invalidJSON
) : void {
2023-03-27 10:41:21 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $adminUser );
$invalidJSON = $this -> featureContext -> substituteInLineCodes (
$invalidJSON ,
null ,
[],
[],
null ,
$user
);
$this -> featureContext -> setResponse (
HttpRequestHelper :: post (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId . '/members/$ref' ),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
\json_encode ( $invalidJSON )
)
);
}
/**
* @When /^user "([^"]*)" tries to add the following users to a group "([^"]*)" at once with invalid JSON "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $group
* @param string $invalidJSON
* @param TableNode $table
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userTriesToAddTheFollowingUsersToAGroupAtOnceWithInvalidJsonUsingTheGraphApi (
string $user ,
string $group ,
string $invalidJSON ,
TableNode $table
) : void {
2023-03-27 10:41:21 +05:45
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$credentials = $this -> getAdminOrUserCredentials ( $user );
foreach ( $table -> getHash () as $row ) {
$invalidJSON = $this -> featureContext -> substituteInLineCodes (
$invalidJSON ,
null ,
[],
[],
null ,
$row [ 'username' ]
);
}
$this -> featureContext -> setResponse (
HttpRequestHelper :: sendRequest (
GraphHelper :: getFullUrl ( $this -> featureContext -> getBaseUrl (), 'groups/' . $groupId ),
$this -> featureContext -> getStepLineRef (),
'PATCH' ,
$credentials [ "username" ],
$credentials [ "password" ],
[ 'Content-Type' => 'application/json' ],
\json_encode ( $invalidJSON )
)
);
}
2023-03-31 08:59:25 +05:45
/**
* @When /^the administrator "([^"]*)" tries to add the following invalid user ids to a group "([^"]*)" at once using the Graph API$/
*
* @param string $user
* @param string $group
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddTheFollowingUserIdWithInvalidCharacterToAGroup (
string $user ,
string $group ,
TableNode $table
) {
2023-03-31 08:59:25 +05:45
$userIds = [];
$credentials = $this -> getAdminOrUserCredentials ( $user );
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
foreach ( $table -> getHash () as $row ) {
$userIds [] = \implode ( " " , $row );
}
$this -> featureContext -> setResponse (
GraphHelper :: addUsersToGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$groupId ,
$userIds
)
);
}
/**
* @When /^the administrator "([^"]*)" tries to add an invalid user id "([^"]*)" to a group "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $userId
* @param string $group
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function theAdministratorTriesToAddUserIdWithInvalidCharactersToAGroup (
string $user ,
string $userId ,
string $group
) : void {
2023-03-31 08:59:25 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$groupId = $this -> featureContext -> getAttributeOfCreatedGroup ( $group , "id" );
$this -> featureContext -> setResponse (
GraphHelper :: addUserToGroup (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
$groupId
)
);
}
/**
* @Then the user :user should be listed once in the group :group
*
* @param string $user
* @param string $group
*
* @return void
* @throws GuzzleException
*/
public function theUsersShouldBeListedOnceToAGroup ( string $user , string $group ) : void {
$count = 0 ;
$members = $this -> listGroupMembers ( $group );
$members = $this -> featureContext -> getJsonDecodedResponse ( $members );
foreach ( $members as $member ) {
if ( $member [ 'onPremisesSamAccountName' ] === $user ) {
$count ++ ;
}
}
Assert :: assertEquals (
1 ,
$count ,
2024-12-24 09:30:42 +05:45
"Expected user '" . $user . "' to be added once to group '"
. $group . "' but the user is listed '" . $count . "' times"
2023-03-31 08:59:25 +05:45
);
}
2023-04-21 16:59:16 +05:45
/**
* @When /^user "([^"]*)" gets the personal drive information of user "([^"]*)" using Graph API$/
* @When /^user "([^"]*)" gets own personal drive information using Graph API$/
*
* @param string $byUser
* @param string|null $user
*
* @return void
*/
public function userGetsThePersonalDriveInformationOfUserUsingGraphApi ( string $byUser , ? string $user = null ) : void {
$user = $user ?? $byUser ;
$credentials = $this -> getAdminOrUserCredentials ( $byUser );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' );
$this -> featureContext -> setResponse (
GraphHelper :: getPersonalDriveInformationByUserId (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ "username" ],
$credentials [ "password" ],
$userId
)
);
}
2023-04-27 16:04:17 +05:45
/**
* @When /^user "([^"]*)" exports (?:her|his) GDPR report to "([^"]*)" using the Graph API$/
*
* @param string $user
* @param string $path
*
* @return void
* @throws GuzzleException
*/
public function userGeneratesGDPRReportOfOwnDataToPath ( string $user , string $path ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' );
$this -> featureContext -> setResponse (
GraphHelper :: generateGDPRReport (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$userId ,
$path
)
);
$this -> featureContext -> pushToLastStatusCodesArrays ();
}
/**
* @Then the downloaded JSON content should contain event type :eventType in item 'events' and should match
2023-05-28 22:27:39 -07:00
* @Then the downloaded JSON content should contain event type :eventType for :spaceType space and should match
2023-04-27 16:04:17 +05:45
*
* @param string $eventType
2023-05-28 22:27:39 -07:00
* @param string|null $spaceType
* @param PyStringNode|null $schemaString
2023-04-27 16:04:17 +05:45
*
* @return void
2024-04-26 15:27:00 +05:45
* @throws Exception
2023-04-27 16:04:17 +05:45
*
*/
2024-12-24 09:30:42 +05:45
public function downloadedJsonContentShouldContainEventTypeInItemAndShouldMatch (
string $eventType ,
? string $spaceType = null ,
PyStringNode $schemaString = null
) : void {
2023-04-27 16:04:17 +05:45
$actualResponseToAssert = null ;
$events = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> events ;
foreach ( $events as $event ) {
if ( $event -> type === $eventType ) {
2023-05-28 22:27:39 -07:00
if ( $spaceType !== null ) {
if ( $event -> event -> Type === $spaceType ) {
$actualResponseToAssert = $event ;
break ;
}
continue ;
}
2023-04-27 16:04:17 +05:45
$actualResponseToAssert = $event ;
break ;
}
}
if ( $actualResponseToAssert === null ) {
throw new Error (
"Response does not contain event type '" . $eventType . "'."
);
}
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-04-27 16:04:17 +05:45
$actualResponseToAssert ,
$this -> featureContext -> getJSONSchema ( $schemaString )
);
}
/**
* @Then the downloaded JSON content should contain key 'user' and match
*
* @param PyStringNode $schemaString
*
* @return void
* @throws GuzzleException
*
*/
public function downloadedJsonContentShouldContainKeyUserAndMatch ( PyStringNode $schemaString ) : void {
$actualResponseToAssert = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
if ( ! isset ( $actualResponseToAssert -> user )) {
throw new Error (
"Response does not contain key 'user'"
);
}
2023-06-02 14:36:05 +05:45
$this -> featureContext -> assertJsonDocumentMatchesSchema (
2023-04-27 16:04:17 +05:45
$actualResponseToAssert -> user ,
$this -> featureContext -> getJSONSchema ( $schemaString )
);
}
2023-05-10 11:37:13 +05:45
/**
* @When user :user tries to export GDPR report of user :ofUser to :path using Graph API
*
* @param string $user
* @param string $ofUser
* @param string $path
*
* @return void
*
*/
2024-12-24 09:30:42 +05:45
public function userTriesToExportGdprReportOfAnotherUserUsingGraphApi (
string $user ,
string $ofUser ,
string $path
) : void {
2023-05-10 11:37:13 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: generateGDPRReport (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' ),
$path
)
);
}
2023-05-15 14:30:24 +05:45
/**
2023-06-28 10:56:08 +05:45
* @param string $user
*
* @return ResponseInterface
* @throws GuzzleException
*/
2024-04-26 15:27:00 +05:45
public function getAssignedRole ( string $user ) : ResponseInterface {
2024-12-24 09:30:42 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $user , 'id' )
?: $this -> featureContext -> getUserIdByUserName ( $user );
2023-06-28 10:56:08 +05:45
return (
GraphHelper :: getAssignedRole (
$this -> featureContext -> getBAseUrl (),
$this -> featureContext -> getStepLineRef (),
$this -> featureContext -> getAdminUsername (),
$this -> featureContext -> getAdminPassword (),
$userId
)
);
}
/**
* @When /^user "([^"]*)" (?:unassigns|tries to unassign) the role of user "([^"]*)" using the Graph API$/
2023-05-15 14:30:24 +05:45
*
* @param string $user
* @param string $ofUser
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserUnassignsTheRoleOfUserUsingTheGraphApi ( string $user , string $ofUser ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' );
// get 'User' role id for nonexistent user
if ( ! $userId && $ofUser !== $this -> featureContext -> getAdminUsername ()) {
$appRoleAssignmentId = $this -> getRoleIdByRoleName ( "User" );
} else {
2024-12-24 09:30:42 +05:45
$appRoleAssignmentId = $this -> featureContext -> getJsonDecodedResponse (
$this -> getAssignedRole ( $ofUser )
)[ "value" ][ 0 ][ "id" ];
2024-07-18 16:17:52 +05:45
}
$userId = $userId ?: $ofUser ;
2023-05-15 14:30:24 +05:45
$this -> featureContext -> setResponse (
GraphHelper :: unassignRole (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$appRoleAssignmentId ,
$userId
)
);
}
/**
* @Then user :user should have the role :role assigned
*
* @param string $user
* @param string $role
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userShouldHaveTheRoleAssigned ( string $user , string $role ) : void {
2023-06-28 10:56:08 +05:45
$jsonDecodedResponse = $this -> featureContext -> getJsonDecodedResponse ( $this -> getAssignedRole ( $user ))[ 'value' ][ 0 ];
2023-05-15 14:30:24 +05:45
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
Assert :: assertEquals (
$this -> appEntity [ "appRoles" ][ $role ],
$jsonDecodedResponse [ 'appRoleId' ],
__METHOD__
. " \n Expected user ' $user ' to have role ' $role ' with role id '" . $this -> appEntity [ "appRoles" ][ $role ] .
"' but got the role id is '" . $jsonDecodedResponse [ 'appRoleId' ] . "'"
);
}
/**
* @Then user :user should not have any role assigned
*
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function userShouldNotHaveAnyRoleAssigned ( string $user ) : void {
2023-06-28 10:56:08 +05:45
$jsonDecodedResponse = $this -> featureContext -> getJsonDecodedResponse ( $this -> getAssignedRole ( $user ))[ 'value' ];
2023-05-15 14:30:24 +05:45
Assert :: assertEmpty (
$jsonDecodedResponse ,
__METHOD__
. " \n Expected user ' $user ' to have no roles assigned but got '" . json_encode ( $jsonDecodedResponse ) . "'"
);
}
2023-05-22 16:05:54 +05:45
/**
* @When user :user changes the role of user :ofUser to role :role using the Graph API
* @When user :user tries to change the role of user :ofUser to role :role using the Graph API
*
* @param string $user
* @param string $ofUser
* @param string $role
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function userChangesTheRoleOfUserToRoleUsingTheGraphApi ( string $user , string $ofUser , string $role ) : void {
2024-07-18 16:17:52 +05:45
$userId = $this -> featureContext -> getAttributeOfCreatedUser ( $ofUser , 'id' ) ?: $ofUser ;
2023-05-22 16:05:54 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
if ( empty ( $this -> appEntity )) {
$this -> setApplicationEntity ();
}
$this -> featureContext -> setResponse (
GraphHelper :: assignRole (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$this -> appEntity [ "appRoles" ][ $role ],
$this -> appEntity [ "id" ],
$userId
)
);
}
2023-11-28 15:33:17 +05:45
/**
* @Given user :user has switched the system language to :language using the Graph API
*
* @param string $user
* @param string $language
*
* @return void
* @throws GuzzleException
*/
public function userHasSwitchedTheSystemLanguageUsingGraphApi ( string $user , string $language ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$response = GraphHelper :: switchSystemLanguage (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$language
);
$this -> featureContext -> theHTTPStatusCodeShouldBe (
200 ,
"Expected response status code should be 200" ,
$response
);
}
/**
* @When user :user switches the system language to :language using the Graph API
*
* @param string $user
* @param string $language
*
* @return void
* @throws GuzzleException
*/
public function userSwitchesTheSystemLanguageUsingGraphApi ( string $user , string $language ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: switchSystemLanguage (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
$language
)
);
}
2024-01-25 09:47:56 +05:45
/**
2024-09-24 15:59:10 +02:00
* @When /^user "([^"]*)" lists the shares shared with (?:him|her)(| after clearing user cache)(| without retry) using the Graph API$/
2024-01-25 09:47:56 +05:45
*
* @param string $user
2024-03-01 15:36:51 +05:45
* @param string $cacheStepString
2024-09-24 15:59:10 +02:00
* @param string $retryOption
2024-01-25 09:47:56 +05:45
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function userListsTheResourcesSharedWithThemUsingGraphApi (
string $user ,
string $cacheStepString ,
string $retryOption
) : void {
2024-03-01 15:36:51 +05:45
if ( $cacheStepString !== '' ) {
// ENV (GRAPH_SPACES_GROUPS_CACHE_TTL | GRAPH_SPACES_USERS_CACHE_TTL) is set default to 60 sec
// which means 60 sec is required to clean up all the user|group cache once they are deleted
// for tests we have set the above ENV's to minimum which is 1 sec as we check the details for the deleted users
sleep ( 1 );
}
2024-01-25 09:47:56 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-04-25 12:15:08 +05:45
// Sometimes listing shares might not return the updated shares list
// so try again until @client.synchronize is true for the max. number of retries (i.e. 10)
// and do not retry when the share is expected to be not synced
2024-09-24 15:59:10 +02:00
$retryEnabled = ( $retryOption === '' );
2024-04-25 12:15:08 +05:45
$tryAgain = false ;
$retried = 0 ;
do {
$response = GraphHelper :: getSharesSharedWithMe (
2024-01-25 09:47:56 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ]
2024-04-25 12:15:08 +05:45
);
2024-07-03 12:16:06 +05:45
$jsonBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ( $response );
2024-04-25 12:15:08 +05:45
2024-09-24 15:59:10 +02:00
if ( $retryEnabled ) {
foreach ( $jsonBody -> value as $share ) {
$autoSync = $this -> featureContext -> getUserAutoSyncSetting ( $credentials [ 'username' ]);
2024-12-24 09:30:42 +05:45
$tryAgain = ! $share -> { '@client.synchronize' }
&& $autoSync
&& $retried < HttpRequestHelper :: numRetriesOnHttpTooEarly ();
2024-09-24 15:59:10 +02:00
if ( $tryAgain ) {
$retried += 1 ;
echo "auto-sync share for user ' $user ' is enabled \n " ;
echo "but share ' $share->name ' was not auto-synced, retrying ( $retried )... \n " ;
// wait 500ms and try again
\usleep ( 500 * 1000 );
break ;
}
2024-04-25 12:15:08 +05:45
}
}
} while ( $tryAgain );
$this -> featureContext -> setResponse ( $response );
2024-03-21 14:03:09 +05:45
$this -> featureContext -> pushToLastStatusCodesArrays ();
2024-01-25 09:47:56 +05:45
}
2024-02-01 13:54:44 +05:45
2024-02-16 15:16:29 +05:45
/**
*
* @param string $user
* @param bool $waitForCacheExpiry
*
2024-05-17 14:19:53 +05:45
* @return ResponseInterface
2024-02-16 15:16:29 +05:45
*/
2024-05-17 14:19:53 +05:45
public function listSharesSharedByMe ( string $user , bool $waitForCacheExpiry = false ) : ResponseInterface {
2024-02-16 15:16:29 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
if ( $waitForCacheExpiry ) {
// ENV (GRAPH_SPACES_GROUPS_CACHE_TTL | GRAPH_SPACES_USERS_CACHE_TTL) is set default to 60 sec
// which means 60 sec is required to clean up all the user|group cache once they are deleted
// for tests we have set the above ENV's to minimum which is 1 sec as we check the details for the deleted users
sleep ( 1 );
}
2024-05-17 14:19:53 +05:45
return GraphHelper :: getSharesSharedByMe (
2024-02-16 15:16:29 +05:45
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ]
);
}
2024-02-01 13:54:44 +05:45
/**
2024-02-01 16:40:29 +05:45
* @When user :user lists the shares shared by him/her using the Graph API
2024-02-01 13:54:44 +05:45
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userListsTheResourcesSharedByAUserUsingGraphApi ( string $user ) : void {
2024-05-17 14:19:53 +05:45
$response = $this -> listSharesSharedByMe ( $user );
$this -> featureContext -> setResponse ( $response );
2024-02-16 15:16:29 +05:45
}
/**
* @When user :user lists the shares shared by him/her after clearing user/group cache using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function userListsTheResourcesSharedByAUserAfterClearingUserOrGroupSpaceUsingGraphApi ( string $user ) : void {
2024-05-17 14:19:53 +05:45
$response = $this -> listSharesSharedByMe ( $user , true );
$this -> featureContext -> setResponse ( $response );
2024-02-01 13:54:44 +05:45
}
/**
2024-02-01 16:40:29 +05:45
* @Then /^the JSON data of the response should (not )?contain resource "([^"]*)" with the following data:?$/
2024-02-01 13:54:44 +05:45
*
* @param string $shouldOrNot (not| )
* @param string $fileName
* @param PyStringNode $schemaString
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldOrNotContainSharedByMeDetails (
string $shouldOrNot ,
string $fileName ,
PyStringNode $schemaString
) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
$fileOrFolderFound = false ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> name ) && $value -> name === $fileName ) {
$responseBody = $value ;
$fileOrFolderFound = true ;
break ;
}
}
$shouldContain = \trim ( $shouldOrNot ) !== 'not' ;
if ( ! $shouldContain && ! $fileOrFolderFound ) {
return ;
}
Assert :: assertFalse (
! $shouldContain && $fileOrFolderFound ,
'Response contains file "' . $fileName . '" but should.'
);
$this -> featureContext -> assertJsonDocumentMatchesSchema (
$responseBody ,
$this -> featureContext -> getJSONSchema ( $schemaString )
);
}
2024-04-17 11:42:09 +02:00
/**
* @Then the JSON data of the search response should not contain user(s) email
*
* @return void
* @throws Exception
*/
public function theJsonDataResponseShouldNotContainUserEmail () : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent () -> value ;
$mailValueExist = false ;
$email = "" ;
foreach ( $responseBody as $value ) {
if ( isset ( $value -> mail )) {
$mailValueExist = true ;
$email = $value -> mail ;
break ;
}
}
Assert :: assertFalse (
$mailValueExist ,
"Response contains email ' $email ' but should not."
);
}
2024-07-12 13:27:34 +05:45
/**
* @Then user :byUser using password :password should be able to create a new user :user with default attributes
*
* @param string $byUser
* @param string $password
* @param string $user
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
2024-12-24 09:30:42 +05:45
public function userUsingPasswordShouldBeAbleToCreateANewUserWithDefaultAttributes (
string $byUser ,
string $password ,
string $user
) : void {
2024-07-12 13:27:34 +05:45
$response = GraphHelper :: createUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$byUser ,
$password ,
$user ,
$this -> featureContext -> getPasswordForUser ( $user )
);
Assert :: assertEquals (
201 ,
$response -> getStatusCode (),
__METHOD__ . " cannot create new user ' $user ' by user ' $byUser '. \n Response:" .
json_encode ( $this -> featureContext -> getJsonDecodedResponse ( $response ))
);
$this -> featureContext -> addUserToCreatedUsersList ( $user , $this -> featureContext -> getPasswordForUser ( $user ));
}
/**
* @Given user :byUser has changed the username to :userName
*
* @param string $byUser
* @param string $userName
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function theUserHasChangedItsOwnUsernameTo ( string $byUser , string $userName ) : void {
$userId = $this -> featureContext -> getUserIdByUserName ( $byUser );
$response = GraphHelper :: editUser (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$byUser ,
$this -> featureContext -> getPasswordForUser ( $byUser ),
$userId ,
'PATCH' ,
$userName ,
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , '' , $response );
$this -> featureContext -> updateUsernameInCreatedUserList ( $byUser , $userName );
}
2024-07-18 15:59:32 +05:45
/**
* @When user :user gets a list of permissions role definitions using the Graph API
*
* @param string $user
*
* @return void
* @throws GuzzleException
*/
public function getListOfPermissionRoleDefinitionsUsingTheGraphAPI ( string $user ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: getPermissionsRoleDefinitions (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
)
);
}
/**
* @When user :user gets the :permissionRole role definition using the Graph API
*
* @param string $user
* @param string $permissionRole
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function getPermissionRoleDefinitionUsingGraphAPI ( string $user , string $permissionRole ) : void {
2024-07-18 15:59:32 +05:45
$credentials = $this -> getAdminOrUserCredentials ( $user );
$this -> featureContext -> setResponse (
GraphHelper :: getPermissionRoleDefinition (
$permissionRole ,
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ],
)
);
}
2024-07-23 16:57:58 +05:45
/**
2024-10-04 11:59:32 +05:45
* @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" using the Graph API$/
2024-07-23 16:57:58 +05:45
*
* @param string $user
* @param string $resource
* @param string $spaceName
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function userListsTheActivitiesForResourceOfSpaceUsingTheGraphAPI (
string $user ,
string $resource ,
string $spaceName
) : void {
2024-07-23 16:57:58 +05:45
$resourceId = $this -> featureContext -> spacesContext -> getResourceId ( $user , $spaceName , $resource );
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId
);
$this -> featureContext -> setResponse ( $response );
}
2024-07-29 17:13:01 +05:45
2024-08-19 09:55:19 +05:45
/**
* @When user :user tries to list the activities of folder :folder with share mount-point id using the Graph API
*
* @param string $user
* @param string $folder
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userTriesToListTheActivitiesOfFolderWithShareMountIdPointIdUsingTheGraphApi (
string $user ,
string $folder
) : void {
2024-08-19 09:55:19 +05:45
$resourceId = GraphHelper :: getShareMountId (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$folder
);
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When user :user tries to list the activities of file :file from space :spaceName owned by user :owner using the Graph API
*
* @param string $user
* @param string $file
* @param string $owner
* @param string $spaceName
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userTriesToListActivitiesOfFileFromSpaceOwnedByUserUsingTheGraphApi (
string $user ,
string $file ,
string $owner ,
string $spaceName
) : void {
2024-08-19 09:55:19 +05:45
$resourceId = $this -> featureContext -> spacesContext -> getResourceId ( $owner , $spaceName , $file );
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId
);
$this -> featureContext -> setResponse ( $response );
}
2024-07-29 17:13:01 +05:45
/**
* @When user :user lists the activities of space :spaceName using the Graph API
*
* @param string $user
* @param string $spaceName
*
* @return void
*/
2024-08-12 16:10:51 +05:45
public function userListsTheActivitiesOfSpaceUsingTheGraphApi ( string $user , string $spaceName ) : void {
2024-07-29 17:13:01 +05:45
$spaceId = ( $this -> featureContext -> spacesContext -> getSpaceByName ( $user , $spaceName ))[ "id" ];
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$spaceId
);
$this -> featureContext -> setResponse ( $response );
}
2024-08-14 16:38:42 +02:00
2024-09-25 16:26:13 +05:45
/**
* @When the public tries to check the activities of space :spaceName owned by user :user with password :password using the Graph API
*
* @param string $spaceName
* @param string $user
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicTriesToCheckTheActivitiesOfSpaceOwnedByUserWithPasswordUsingGraphApi (
string $spaceName ,
string $user ,
string $password
) : void {
2024-09-25 16:26:13 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
"public" ,
$this -> featureContext -> getActualPassword ( $password ),
$this -> spacesContext -> getSpaceIdByName ( $user , $spaceName )
);
$this -> featureContext -> setResponse ( $response );
}
/**
* @When /^the public tries to check the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" owned by user "([^"]*)" with password "([^"]*)" using the Graph API$/
*
* @param string $resource
* @param string $space
* @param string $owner
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicTriesToCheckTheActivitiesOfResourceFromSpaceOwnedByUserWithPasswordUsingGraphApi (
string $resource ,
string $space ,
string $owner ,
string $password
) : void {
2024-09-25 16:26:13 +05:45
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
"public" ,
$this -> featureContext -> getPasswordForUser ( $owner ),
$this -> spacesContext -> getResourceId ( $owner , $space , $resource )
);
$this -> featureContext -> setResponse ( $response );
}
2024-08-20 17:13:37 +05:45
/**
2024-10-04 11:59:32 +05:45
* @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" with (depth|limit|sort) "([^"]*)" using the Graph API$/
2024-08-20 17:13:37 +05:45
*
* @param string $user
* @param string $resource
* @param string $spaceName
2024-08-21 16:22:59 +05:45
* @param string $filterType
* @param string $filterValue
2024-08-20 17:13:37 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userListsTheActivitiesForFolderOfSpaceWithDepthOrLimitUsingTheGraphApi (
string $user ,
string $resource ,
string $spaceName ,
string $filterType ,
string $filterValue
) : void {
2024-08-20 17:13:37 +05:45
$resourceId = $this -> featureContext -> spacesContext -> getResourceId ( $user , $spaceName , $resource );
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId ,
2024-08-21 16:22:59 +05:45
[ $filterType => $filterValue ]
2024-08-20 17:13:37 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2024-10-04 12:07:40 +05:45
/**
* @Then the activities should be in the following order:
*
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function theActivitiesShouldBeInTheFollowingOrder ( TableNode $table ) : void {
$responseBody = $this -> featureContext -> getJsonDecodedResponseBodyContent ();
$activities = $responseBody -> value ;
foreach ( $table -> getHash () as $index => $expectedValue ) {
$actualActivity = $activities [ $index ];
$expectedActivity = $expectedValue [ 'resource' ] . ":" . $expectedValue [ 'message' ];
2024-12-24 09:30:42 +05:45
$actualActivity = $actualActivity -> template -> variables -> resource -> name
. ":" . $actualActivity -> template -> message ;
2024-10-04 12:07:40 +05:45
Assert :: assertEquals ( $expectedActivity , $actualActivity , "Activity didn't match" );
}
}
2024-10-04 11:59:32 +05:45
/**
* @When /^user "([^"]*)" lists the activities of (?:folder|file) "([^"]*)" from space "([^"]*)" with (depth|limit) "([^"]*)" and sort "(asc|desc)" using the Graph API$/
*
* @param string $user
* @param string $resource
* @param string $spaceName
* @param string $filterType
* @param string $filterValue
* @param string $sortType
*
* @return void
* @throws GuzzleException
*/
public function userListsTheActivitiesOfResourceFromSpaceWithDepthOrLimitAndSortUsingTheGraphApi (
string $user ,
string $resource ,
string $spaceName ,
string $filterType ,
string $filterValue ,
string $sortType
) : void {
$resourceId = $this -> spacesContext -> getResourceId ( $user , $spaceName , $resource );
$response = GraphHelper :: getActivities (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$user ,
$this -> featureContext -> getPasswordForUser ( $user ),
$resourceId ,
[ $filterType => $filterValue , 'sort' => $sortType ],
);
$this -> featureContext -> setResponse ( $response );
}
2024-08-14 16:38:42 +02:00
/**
* @When the administrator gets federated users using the Graph API
* @When user :user tries to get federated users using the Graph API
*
* @param ?string $user
*
* @return void
*/
public function theUserGetsFederatedUsersUsingTheGraphApi ( ? string $user = null ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-08-21 16:22:59 +05:45
2024-08-14 16:38:42 +02:00
$response = GraphHelper :: getFederatedUsers (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ]
);
$this -> featureContext -> setResponse ( $response );
}
/**
2024-08-19 11:11:17 +02:00
* @When the administrator gets federated and local users using the Graph API
* @When user :user tries to get federated and local users using the Graph API
2024-08-14 16:38:42 +02:00
*
* @param ?string $user
*
* @return void
*/
public function theUserGetsAllUsersUsingTheGraphApi ( ? string $user = null ) : void {
$credentials = $this -> getAdminOrUserCredentials ( $user );
2024-08-21 16:22:59 +05:45
2024-08-14 16:38:42 +02:00
$response = GraphHelper :: getAllUsers (
$this -> featureContext -> getBaseUrl (),
$this -> featureContext -> getStepLineRef (),
$credentials [ 'username' ],
$credentials [ 'password' ]
);
$this -> featureContext -> setResponse ( $response );
}
2022-03-25 15:33:35 +05:45
}