Skip to content

Commit

Permalink
Test for speeding up CI
Browse files Browse the repository at this point in the history
  • Loading branch information
bhawanaprasain committed Jun 14, 2019
1 parent 828a56d commit 652b105
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 84 deletions.
47 changes: 21 additions & 26 deletions tests/acceptance/features/apiAuthOcs/ocsDELETEAuth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@
Feature: auth

@issue-32068
Scenario Outline: send DELETE requests to OCS endpoints as admin with wrong password
Given using OCS API version "<ocs_api_version>"
And group "group1" has been created
When the administrator sends HTTP method "DELETE" to OCS API endpoint "<endpoint>" using password "invalid"
Then the OCS status code should be "<ocs-code>"
And the HTTP status code should be "<http-code>"
Examples:
| ocs_api_version |endpoint | ocs-code | http-code |
| 1 |/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 |
| 1 |/apps/files_sharing/api/v1/remote_shares/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/remote_shares/123 | 997 | 401 |
| 1 |/apps/files_sharing/api/v1/shares/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/shares/123 | 997 | 401 |
| 1 |/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 |
| 1 |/cloud/apps/testing | 997 | 401 |
| 2 |/cloud/apps/testing | 997 | 401 |
| 1 |/cloud/groups/group1 | 997 | 401 |
| 2 |/cloud/groups/group1 | 997 | 401 |
| 1 |/cloud/users/user0 | 997 | 401 |
| 2 |/cloud/users/user0 | 997 | 401 |
| 1 |/cloud/users/user0/groups | 997 | 401 |
| 2 |/cloud/users/user0/groups | 997 | 401 |
| 1 |/cloud/users/user0/subadmins | 997 | 401 |
| 2 |/cloud/users/user0/subadmins | 997 | 401 |
Scenario: send DELETE requests to OCS endpoints as admin with wrong password
When the administrator requests these endpoints of specified API version with "DELETE" using password "invalid" then the status codes should be as listed
| endpoint | ocs-code | http-code | group |
| /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 | group1 |
| /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 | group1 |
| /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/123 | 997 | 401 | group1 |
| /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/123 | 997 | 401 | group1 |
| /ocs/v1.php/apps/files_sharing/api/v1/shares/123 | 997 | 401 | group1 |
| /ocs/v2.php/apps/files_sharing/api/v1/shares/123 | 997 | 401 | group1 |
| /ocs/v1.php/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 | group1 |
| /ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 | group1 |
| /ocs/v1.php/cloud/apps/testing | 997 | 401 | group1 |
| /ocs/v2.php/cloud/apps/testing | 997 | 401 | group1 |
| /ocs/v1.php/cloud/groups/group1 | 997 | 401 | group1 |
| /ocs/v2.php/cloud/groups/group1 | 997 | 401 | group1 |
| /ocs/v1.php/cloud/users/user0 | 997 | 401 | group1 |
| /ocs/v2.php/cloud/users/user0 | 997 | 401 | group1 |
| /ocs/v1.php/cloud/users/user0/groups | 997 | 401 | group1 |
| /ocs/v2.php/cloud/users/user0/groups | 997 | 401 | group1 |
| /ocs/v1.php/cloud/users/user0/subadmins | 997 | 401 | group1 |
| /ocs/v2.php/cloud/users/user0/subadmins | 997 | 401 | group1 |
58 changes: 25 additions & 33 deletions tests/acceptance/features/apiAuthOcs/ocsPOSTAuth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,28 @@ Feature: auth
Background:
Given user "user0" has been created with default attributes and skeleton files

@issue-32068
Scenario Outline: send POST requests to OCS endpoints as normal user with wrong password
Given using OCS API version "<ocs_api_version>"
And user "user1" has been created with default attributes and skeleton files
When user "user0" sends HTTP method "POST" to OCS API endpoint "<endpoint>" with body using password "invalid"
| data | doesnotmatter |
Then the OCS status code should be "<ocs-code>"
And the HTTP status code should be "<http-code>"
Examples:
| ocs_api_version |endpoint | ocs-code | http-code |
| 1 |/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 |
| 1 |/apps/files_sharing/api/v1/shares | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/shares | 997 | 401 |
| 1 |/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 |
| 1 |/cloud/apps/testing | 997 | 401 |
| 2 |/cloud/apps/testing | 997 | 401 |
| 1 |/cloud/groups | 997 | 401 |
| 2 |/cloud/groups | 997 | 401 |
| 1 |/cloud/users | 997 | 401 |
| 2 |/cloud/users | 997 | 401 |
| 1 |/cloud/users/user0/groups | 997 | 401 |
| 2 |/cloud/users/user0/groups | 997 | 401 |
| 1 |/cloud/users/user0/subadmins | 997 | 401 |
| 2 |/cloud/users/user0/subadmins | 997 | 401 |
| 1 |/person/check | 101 | 200 |
| 2 |/person/check | 400 | 400 |
| 1 |/privatedata/deleteattribute/testing/test | 997 | 401 |
| 2 |/privatedata/deleteattribute/testing/test | 997 | 401 |
| 1 |/privatedata/setattribute/testing/test | 997 | 401 |
| 2 |/privatedata/setattribute/testing/test | 997 | 401 |

Scenario: send POST requests to OCS endpoints as normal user with wrong password
When user "user0" requests these endpoints with "POST" including body using password "invalid" then the status codes should be as listed
| endpoint | ocs-code | http-code | body |
| /ocs/v1.php/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 | doesnotmatter |
| /ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123 | 997 | 401 | doesnotmatter |
| /ocs/v1.php/apps/files_sharing/api/v1/shares | 997 | 401 | doesnotmatter |
| /ocs/v2.php/apps/files_sharing/api/v1/shares | 997 | 401 | doesnotmatter |
| /ocs/v1.php/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 | doesnotmatter |
| /ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123 | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/apps/testing | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/apps/testing | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/groups | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/groups | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/users | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/users | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/users/user0/groups | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/users/user0/groups | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/users/user0/subadmins | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/users/user0/subadmins | 997 | 401 | doesnotmatter |
| /ocs/v1.php/person/check | 101 | 200 | doesnotmatter |
| /ocs/v2.php/person/check | 400 | 400 | doesnotmatter |
| /ocs/v1.php/privatedata/deleteattribute/testing/test | 997 | 401 | doesnotmatter |
| /ocs/v2.php/privatedata/deleteattribute/testing/test | 997 | 401 | doesnotmatter |
| /ocs/v1.php/privatedata/setattribute/testing/test | 997 | 401 | doesnotmatter |
| /ocs/v2.php/privatedata/setattribute/testing/test | 997 | 401 | doesnotmatter |
31 changes: 12 additions & 19 deletions tests/acceptance/features/apiAuthOcs/ocsPUTAuth.feature
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
@api @TestAlsoOnExternalUserBackend
Feature: auth

@issue-32068
Scenario Outline: send PUT requests to OCS endpoints as admin with wrong password
Given using OCS API version "<ocs_api_version>"
When the administrator sends HTTP method "PUT" to OCS API endpoint "<endpoint>" with body using password "invalid"
| data | doesnotmatter |
Then the OCS status code should be "<ocs-code>"
And the HTTP status code should be "<http-code>"
Examples:
| ocs_api_version |endpoint | ocs-code | http-code |
| 1 |/cloud/users/user0 | 997 | 401 |
| 2 |/cloud/users/user0 | 997 | 401 |
| 1 |/cloud/users/user0/disable | 997 | 401 |
| 2 |/cloud/users/user0/disable | 997 | 401 |
| 1 |/cloud/users/user0/enable | 997 | 401 |
| 2 |/cloud/users/user0/enable | 997 | 401 |
| 1 |/apps/files_sharing/api/v1/shares/123 | 997 | 401 |
| 2 |/apps/files_sharing/api/v1/shares/123 | 997 | 401 |


Scenario: send PUT request to OCS endpoints as admin with wrong password
When administrator sends request these endpoints with "PUT" with body using password "invalid" then the status codes should be as listed
| endpoint | ocs-code | http-code | body |
| /ocs/v1.php/cloud/users/user0 | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/users/user0 | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/users/user0/disable | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/users/user0/disable | 997 | 401 | doesnotmatter |
| /ocs/v1.php/cloud/users/user0/enable | 997 | 401 | doesnotmatter |
| /ocs/v2.php/cloud/users/user0/enable | 997 | 401 | doesnotmatter |
| /ocs/v1.php/apps/files_sharing/api/v1/shares/123 | 997 | 401 | doesnotmatter |
| /ocs/v2.php/apps/files_sharing/api/v1/shares/123 | 997 | 401 | doesnotmatter |
10 changes: 6 additions & 4 deletions tests/acceptance/features/bootstrap/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ public function userRequestsEndpointsUsingTheGeneratedAppPassword($method, Table
* @param string $method
* @param string|null $authHeader
* @param bool $useCookies
* @param string $body
*
* @return void
*/
public function sendRequest(
$url, $method, $authHeader = null, $useCookies = false
$url, $method, $authHeader = null, $useCookies = false, $body = null
) {
// reset responseXml
$this->responseXml = '';
Expand All @@ -266,7 +267,7 @@ public function sendRequest(
$headers['requesttoken'] = $this->requestToken;
}
$this->response = HttpRequestHelper::sendRequest(
$fullUrl, $method, null, null, $headers, null, null, $cookies
$fullUrl, $method, null, null, $headers, $body, null, $cookies
);
}

Expand Down Expand Up @@ -346,17 +347,18 @@ public function aNewClientTokenForTheAdministratorHasBeenGenerated() {
* @param string $url
* @param string $method
* @param string $password
* @param string $body
*
* @return void
*/
public function userRequestsURLWithUsingBasicAuth($user, $url, $method, $password=null) {
public function userRequestsURLWithUsingBasicAuth($user, $url, $method, $password=null, $body=null) {
if ($password === null) {
$authString = "$user:" . $this->getPasswordForUser($user);
} else {
$authString = $password;
}
$this->sendRequest(
$url, $method, 'basic ' . \base64_encode($authString)
$url, $method, 'basic ' . \base64_encode($authString), false, $body
);
}

Expand Down
65 changes: 63 additions & 2 deletions tests/acceptance/features/bootstrap/OCSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function userSendsToOcsApiEndpoint($user, $verb, $url, $password = null)
public function userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $verb, $url, $body = null, $password = null
) {

/**
* array of the data to be sent in the body.
* contains $body data converted to an array
Expand Down Expand Up @@ -136,6 +135,22 @@ public function theAdministratorSendsHttpMethodToOcsApiEndpoint(
$this->userSendsToOcsApiEndpoint($admin, $verb, $url, $password);
}

/**
* @When the administrator requests these endpoints of specified API version with :method using password :invalid then the status codes should be as listed
*
* @param string $method
* @param string $password
* @param TableNode $table
*
* @return void
*/
public function administratorSendsRequestToEndpointsUsingSpecifiedApiVersion($method, $password, TableNode $table) {
foreach ($table->getHash() as $row) {
$this->featureContext->administratorRequestsURLWithUsingBasicAuth($row['endpoint'], $method, $password);
$this->featureContext->verifyStatusCode($row['ocs-code'], $row['http-code'], $row['endpoint']);
}
}

/**
* @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers$/
*
Expand Down Expand Up @@ -203,7 +218,7 @@ public function userSendsToOcsApiEndpointWithHeadersAndPassword(
/**
* @When /^the administrator sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers using password "([^"]*)"$/
*
* @param string $verb
* @param string $verb false, $body
* @param string $url
* @param string $password
* @param TableNode $headersTable
Expand Down Expand Up @@ -275,6 +290,29 @@ public function theAdministratorSendsHttpMethodToOcsApiWithBodyAndPassword(
);
}

/**
* @When administrator sends request these endpoints with :method with body using password :password then the status codes should be as listed
*
* @param string $method
* @param string $password
* @param TableNode $table
*
* @return void
*/
public function administratorSendsRequestToTheseEndpointsWithPassword($method, $password, TableNode $table) {
$admin = $this->featureContext->getAdminUsername();
foreach ($table->getHash() as $row) {
$this->featureContext->userRequestsURLWithUsingBasicAuth(
$admin,
$row['endpoint'],
$method,
$password,
$row['body']
);
$this->featureContext->verifyStatusCode($row['ocs-code'], $row['http-code'], $row['endpoint']);
}
}

/**
* @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body using password "([^"]*)"$/
*
Expand All @@ -294,6 +332,29 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBodyAndPassword(
);
}

/**
* @When user :user requests these endpoints with :method including body using password :password then the status codes should be as listed
*
* @param string $user
* @param string $method
* @param string $password
* @param TableNode $table
*
* @return void
*/
public function userSendsRequestToTheseEndpointsWithBodyUsingPassword($user, $method, $password, TableNode $table) {
foreach ($table->getHash() as $row) {
$this->featureContext->userRequestsURLWithUsingBasicAuth(
$user,
$row['endpoint'],
$method,
$password,
$row['body']
);
$this->featureContext->verifyStatusCode($row['ocs-code'], $row['http-code'], $row['endpoint']);
}
}

/**
* @Then /^the OCS status code should be "([^"]*)"$/
*
Expand Down

0 comments on commit 652b105

Please sign in to comment.