Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] Add API tests for creating groups (graph API) #4992

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The test runner source for API tests
CORE_COMMITID=1eed08f1229136ac5cd7ef3ae2ccd2821a113129
CORE_COMMITID=93344602834833fa01d90975e3c955c3b90266fe
CORE_BRANCH=master

# The test runner source for UI tests
Expand Down
38 changes: 38 additions & 0 deletions tests/acceptance/features/apiGraph/createGroup.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@api @skipOnOcV10
Feature: create group
Only user with admin permissions can create new groups

Background:
Given user "Alice" has been created with default attributes and without skeleton files
And the administrator has given "Alice" the role "Admin" using the settings api


Scenario Outline: admin user creates a group
When user "Alice" creates a group "<groupname>" using the Graph API
And the administrator creates a group "grp1" using the Graph API
saw-jan marked this conversation as resolved.
Show resolved Hide resolved
Then the HTTP status code should be "200"
And group "<groupname>" should exist
Examples:
| groupname |
| simplegroup |
| España§àôœ€ |
| नेपाली |
| $x<=>[y*z^2+1]! |
| 😅 😆 |
| comma,grp1 |
| Finance (NP) |
| slash\Middle |


Scenario: admin user tries to create a group that already exists
Given group "mygroup" has been created
When user "Alice" tries to create a group "mygroup" using the Graph API
SagarGi marked this conversation as resolved.
Show resolved Hide resolved
And the HTTP status code should be "500"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@butonic do we really expect 500 when a group cannot be created, or is this a bug?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have an open issue: #3516

good that user cannot see 500 because web checks same groups name:

image

And group "mygroup" should exist


Scenario: normal user tries to create a group
Given user "Brian" has been created with default attributes and without skeleton files
When user "Brian" tries to create a group "mygroup" using the Graph API
SagarGi marked this conversation as resolved.
Show resolved Hide resolved
And the HTTP status code should be "401"
And group "mygroup" should not exist
45 changes: 31 additions & 14 deletions tests/acceptance/features/bootstrap/GraphContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use TestHelpers\GraphHelper;
use TestHelpers\WebDavHelper;
use PHPUnit\Framework\Assert;

require_once 'bootstrap.php';
Expand Down Expand Up @@ -467,22 +468,44 @@ public function adminHasAddedUserToGroupUsingTheGraphApi(
}

/**
* @When /^the administrator creates a group "([^"]*)" using the Graph API$/
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @return ResponseInterface
* @throws GuzzleException
*/
public function adminCreatesGroupUsingTheGraphApi(string $group): void {
$response = GraphHelper::createGroup(
public function createGroup(string $group, ?string $user = null): ResponseInterface {
if ($user) {
$username = $user;
$password = $this->featureContext->getPasswordForUser($user);
} else {
$username = $this->featureContext->getAdminUsername();
$password = $this->featureContext->getAdminPassword();
}
return GraphHelper::createGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$username,
$password,
$group,
);
}

/**
* @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
SagarGi marked this conversation as resolved.
Show resolved Hide resolved
kiranparajuli589 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param string $group
* @param ?string $user
*
* @return void
* @throws Exception
* @throws GuzzleException
*/
public function adminCreatesGroupUsingTheGraphApi(string $group, ?string $user = null): void {
saw-jan marked this conversation as resolved.
Show resolved Hide resolved
$response = $this->createGroup($group, $user);
$this->featureContext->setResponse($response);
$this->featureContext->pushToLastHttpStatusCodesArray((string) $response->getStatusCode());

Expand All @@ -502,13 +525,7 @@ public function adminCreatesGroupUsingTheGraphApi(string $group): void {
* @throws GuzzleException
*/
public function adminHasCreatedGroupUsingTheGraphApi(string $group): array {
$result = GraphHelper::createGroup(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$this->featureContext->getAdminUsername(),
$this->featureContext->getAdminPassword(),
$group,
);
$result = $this->createGroup($group);
if ($result->getStatusCode() === 200) {
return $this->featureContext->getJsonDecodedResponse($result);
} else {
Expand Down