added graph helper
Signed-off-by: Kiran Parajuli <kiranparajuli589@gmail.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
@api
|
||||
Feature: add groups
|
||||
As an administrator
|
||||
I want to be able to create group using the Graph API
|
||||
So that I can more easily manage access to resources by groups rather than individual users
|
||||
|
||||
Scenario:
|
||||
When the administrator sends a group creation request for the following groups using the graph API
|
||||
| group_display_name |
|
||||
| simplegroup |
|
||||
| España§àôœ€ |
|
||||
| नेपाली |
|
||||
And the HTTP status code of responses on all endpoints should be "200"
|
||||
And these groups should exist:
|
||||
| groupname |
|
||||
| simplegroup |
|
||||
| España§àôœ€ |
|
||||
| नेपाली |
|
||||
|
||||
|
||||
Scenario: admin creates a group with special characters
|
||||
When the administrator sends a group creation request for the following groups using the graph API
|
||||
| group_display_name | comment |
|
||||
| brand-new-group | dash |
|
||||
| the.group | dot |
|
||||
| left,right | comma |
|
||||
| 0 | The "false" group |
|
||||
| Finance (NP) | Space and brackets |
|
||||
| Admin&Finance | Ampersand |
|
||||
| admin:Pokhara@Nepal | Colon and @ |
|
||||
| maint+eng | Plus sign |
|
||||
| $x<=>[y*z^2]! | Maths symbols |
|
||||
| Mgmt\Middle | Backslash |
|
||||
| 😅 😆 | emoji |
|
||||
| [group1] | brackets |
|
||||
| group [ 2 ] | bracketsAndSpace |
|
||||
And the HTTP status code of responses on all endpoints should be "200"
|
||||
And these groups should exist:
|
||||
| groupname |
|
||||
| brand-new-group |
|
||||
| the.group |
|
||||
| left,right |
|
||||
| 0 |
|
||||
| Finance (NP) |
|
||||
| Admin&Finance |
|
||||
| admin:Pokhara@Nepal |
|
||||
| maint+eng |
|
||||
| $x<=>[y*z^2]! |
|
||||
| Mgmt\Middle |
|
||||
| 😅 😆 |
|
||||
| [group1] |
|
||||
| group [ 2 ] |
|
||||
@@ -0,0 +1,63 @@
|
||||
@api
|
||||
Feature:
|
||||
As an administrator
|
||||
I want to be able to create user using the Graph API
|
||||
So that I can manage users more easily
|
||||
|
||||
|
||||
@smokeTest
|
||||
Scenario: admin creates a user
|
||||
Given user "brand-new-user" has been deleted
|
||||
When the administrator sends a user creation request for user "brand-new-user" password "%alt1%" using the graph API
|
||||
Then the HTTP status code should be "200"
|
||||
And user "brand-new-user" should exist
|
||||
And user "brand-new-user" should be able to upload file "filesForUpload/textfile.txt" to "/textfile.txt"
|
||||
|
||||
|
||||
Scenario Outline: admin creates a user with special characters in the username
|
||||
Given user "<username>" has been deleted
|
||||
When the administrator sends a user creation request for user "<username>" password "%alt1%" using the graph API
|
||||
Then the HTTP status code of responses on all endpoints should be "400"
|
||||
And the graph API response should return the following error
|
||||
| code | invalidRequest |
|
||||
| message | username '<username>' must be at least the local part of an email |
|
||||
And user "<username>" should not exist
|
||||
Examples:
|
||||
| username |
|
||||
| a@-+_.b |
|
||||
| a space |
|
||||
|
||||
Scenario: admin creates a user and specifies a password with special characters
|
||||
When the administrator sends a user creation request for the following users with password using the graph API
|
||||
| username | password |
|
||||
| brand-new-user1 | !@#$%^&*()-_+=[]{}:;,.<>?~ |
|
||||
| brand-new-user2 | España§àôœ€ |
|
||||
| brand-new-user3 | नेपाली |
|
||||
And the HTTP status code of responses on all endpoints should be "200"
|
||||
And the following users should exist
|
||||
| username |
|
||||
| brand-new-user1 |
|
||||
| brand-new-user2 |
|
||||
| brand-new-user3 |
|
||||
And the following users should be able to upload file "filesForUpload/textfile.txt" to "/textfile.txt"
|
||||
| username |
|
||||
| brand-new-user1 |
|
||||
| brand-new-user2 |
|
||||
| brand-new-user3 |
|
||||
|
||||
Scenario: admin tries to create an existing user
|
||||
And user "brand-new-user" has been created with default attributes and without skeleton files
|
||||
When the administrator sends a user creation request for user "brand-new-user" password "%alt1%" using the graph API
|
||||
And the HTTP status code should be "500"
|
||||
Then the graph API response should return the following error
|
||||
| code | generalException |
|
||||
| message | LDAP Result Code 68 "Entry Already Exists":{space} |
|
||||
|
||||
|
||||
Scenario: admin creates a user and specifies password containing just space
|
||||
Given user "brand-new-user" has been deleted
|
||||
When the administrator sends a user creation request for user "brand-new-user" password " " using the graph API
|
||||
And the HTTP status code should be "200"
|
||||
And user "brand-new-user" should exist
|
||||
And user "brand-new-user" should be able to upload file "filesForUpload/textfile.txt" to "/textfile.txt"
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* 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;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use TestHelpers\GraphHelper;
|
||||
use TestHelpers\HttpRequestHelper;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use PHPUnit\Framework\Assert;
|
||||
|
||||
require_once "bootstrap.php";
|
||||
|
||||
/**
|
||||
* Context for the provisioning specific steps using the Graph API
|
||||
*/
|
||||
class GraphContext implements Context {
|
||||
/**
|
||||
* @var FeatureContext
|
||||
*/
|
||||
private FeatureContext $featureContext;
|
||||
|
||||
/**
|
||||
* This will run before EVERY scenario.
|
||||
* It will set the properties for this object.
|
||||
*
|
||||
* @BeforeScenario
|
||||
*
|
||||
* @param BeforeScenarioScope $scope
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before(BeforeScenarioScope $scope):void {
|
||||
// Get the environment
|
||||
$environment = $scope->getEnvironment();
|
||||
// Get all the contexts you need in this context from here
|
||||
$this->featureContext = $environment->getContext('FeatureContext');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a user creation request for user "([^"]*)" password "([^"]*)" using the graph API$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminSendsUserCreationRequestUsingTheGraphApi(string $user, string $password):void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getActualPassword($password);
|
||||
$response = GraphHelper::createUser(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$user,
|
||||
$password
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$this->featureContext->pushToLastStatusCodesArrays();
|
||||
$success = $this->featureContext->theHTTPStatusCodeWasSuccess();
|
||||
$this->featureContext->addUserToCreatedUsersList(
|
||||
$user,
|
||||
$password,
|
||||
null,
|
||||
null,
|
||||
$success
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a user creation request for the following users with password using the graph API$/
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theAdministratorSendsAUserCreationRequestForTheFollowingUsersWithPasswordUsingTheGraphAPI(TableNode $table) {
|
||||
$this->featureContext->verifyTableNodeColumns($table, ["username", "password"]);
|
||||
$users = $table->getHash();
|
||||
foreach ($users as $user) {
|
||||
$this->adminSendsUserCreationRequestUsingTheGraphApi($user["username"], $user["password"]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the graph API response should return the following error$/
|
||||
*
|
||||
* @param TableNode $body
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theGraphApiResponseShouldReturnTheFollowingError(TableNode $body):void {
|
||||
$this->featureContext->verifyTableNodeRows($body, ['code', 'message']);
|
||||
$bodyRows = $body->getRowsHash();
|
||||
$responseData = $this->featureContext->getJsonDecodedResponse();
|
||||
// parse "{space}" to " " from the message
|
||||
$bodyRows['message'] = \str_replace('{space}', ' ', $bodyRows['message']);
|
||||
Assert::assertEquals(
|
||||
$bodyRows['code'],
|
||||
$responseData['error']['code'],
|
||||
"Status code is not as expected"
|
||||
);
|
||||
Assert::assertEquals(
|
||||
$bodyRows['message'],
|
||||
$responseData['error']['message'],
|
||||
"Status message is not as expected"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a group creation request for group "([^"]*)" using the graph API$/
|
||||
*
|
||||
* @param string $group
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function adminSendsGroupCreationRequestUsingTheGraphAPI(string $group):void {
|
||||
$response = GraphHelper::createGroup(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$group
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
$justCreatedGroup = $this->featureContext->getJsonDecodedResponse();
|
||||
$this->featureContext->pushToLastStatusCodesArrays();
|
||||
$this->featureContext->addGroupToCreatedGroupsList($group, true, true, $justCreatedGroup['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends a group creation request for the following groups using the graph API$/
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theAdministratorSendsAGroupCreationRequestForTheFollowingGroupsUsingTheGraphAPI(TableNode $table) {
|
||||
$this->featureContext->verifyTableNodeColumns($table, ["group_display_name"], ['comment']);
|
||||
$groups = $table->getHash();
|
||||
foreach ($groups as $group) {
|
||||
$this->adminSendsGroupCreationRequestUsingTheGraphAPI($group["group_display_name"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ $pathToCore = \getenv('PATH_TO_CORE');
|
||||
if ($pathToCore === false) {
|
||||
$pathToCore = "../core";
|
||||
}
|
||||
|
||||
require_once $pathToCore . '/tests/acceptance/features/bootstrap/bootstrap.php';
|
||||
|
||||
$classLoader = new \Composer\Autoload\ClassLoader();
|
||||
@@ -33,5 +32,6 @@ $classLoader->addPsr4(
|
||||
$pathToCore . "/tests/acceptance/features/bootstrap",
|
||||
true
|
||||
);
|
||||
$classLoader->addPsr4("TestHelpers\\", __DIR__ . "/../../../TestHelpers", true);
|
||||
|
||||
$classLoader->register();
|
||||
|
||||
Reference in New Issue
Block a user