Skip to content

Commit

Permalink
test(ExternalStorage): Send basic auth during integrations tests
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>

[skip ci]
  • Loading branch information
artonge committed Nov 28, 2024
1 parent c335d25 commit 6977855
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
23 changes: 21 additions & 2 deletions build/integration/features/bootstrap/ExternalStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function deleteStorage(string $storageId): void {
* @param TableNode $fields
*/
public function loggedInUserCreatesExternalGlobalStorage(TableNode $fields): void {
$this->sendJsonWithRequestToken('POST', '/index.php/apps/files_external/globalstorages', $fields);
$this->sendJsonWithRequestTokenAndBasicAuth('POST', '/index.php/apps/files_external/globalstorages', $fields);
$this->theHTTPStatusCodeShouldBe('201');

$this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true);
Expand All @@ -62,7 +62,7 @@ public function loggedInUserCreatesExternalGlobalStorage(TableNode $fields): voi
* @param TableNode $fields
*/
public function loggedInUserUpdatesLastExternalUserglobalStorage(TableNode $fields): void {
$this->sendJsonWithRequestToken('PUT', '/index.php/apps/files_external/userglobalstorages/' . $this->lastExternalStorageData['id'], $fields);
$this->sendJsonWithRequestTokenAndBasicAuth('PUT', '/index.php/apps/files_external/userglobalstorages/' . $this->lastExternalStorageData['id'], $fields);
$this->theHTTPStatusCodeShouldBe('200');

$this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true);
Expand Down Expand Up @@ -100,4 +100,23 @@ private function sendJsonWithRequestToken(string $method, string $url, TableNode
];
$this->sendingAToWithRequesttoken($method, $url, $body);
}

private function sendJsonWithRequestTokenAndBasicAuth(string $method, string $url, TableNode $fields): void {
$isFirstField = true;
$fieldsAsJsonString = '{';
foreach ($fields->getRowsHash() as $key => $value) {
$fieldsAsJsonString .= ($isFirstField ? '' : ',') . '"' . $key . '":' . $value;
$isFirstField = false;
}
$fieldsAsJsonString .= '}';

$body = [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . base64_encode('admin:admin'),
],
'body' => $fieldsAsJsonString,
];
$this->sendingAToWithRequesttoken($method, $url, $body);
}
}
34 changes: 17 additions & 17 deletions build/integration/files_features/external-storage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Feature: external-storage
And As an "user1"
And accepting last share
When creating a share with
| path | foo |
| shareType | 3 |
| path | foo |
| shareType | 3 |
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And Share fields of last share match with
| id | A_NUMBER |
| url | AN_URL |
| token | A_TOKEN |
| id | A_NUMBER |
| url | AN_URL |
| token | A_TOKEN |
| mimetype | httpd/unix-directory |

Scenario: Shares don't overwrite external storage
Expand Down Expand Up @@ -66,9 +66,9 @@ Feature: external-storage
Scenario: Save an external storage with password provided by user
Given Logging in using web as "admin"
And logged in user creates external global storage
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::userprovided" |
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::userprovided" |
| backendOptions | {"host":"http://localhost:8080","secure":false} |
And fields of last external storage match with
| status | 2 |
Expand All @@ -80,9 +80,9 @@ Feature: external-storage
Scenario: Save an external storage again with an unmodified password provided by user
Given Logging in using web as "admin"
And logged in user creates external global storage
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::userprovided" |
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::userprovided" |
| backendOptions | {"host":"http://localhost:8080","secure":false} |
And fields of last external storage match with
| status | 2 |
Expand All @@ -96,9 +96,9 @@ Feature: external-storage
Scenario: Save an external storage with global credentials provided by user
Given Logging in using web as "admin"
And logged in user creates external global storage
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::global::user" |
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::global::user" |
| backendOptions | {"host":"http://localhost:8080","secure":false} |
And fields of last external storage match with
| status | 2 |
Expand All @@ -110,9 +110,9 @@ Feature: external-storage
Scenario: Save an external storage again with unmodified global credentials provided by user
Given Logging in using web as "admin"
And logged in user creates external global storage
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::global::user" |
| mountPoint | "ExternalStorageTest" |
| backend | "owncloud" |
| authMechanism | "password::global::user" |
| backendOptions | {"host":"http://localhost:8080","secure":false} |
And fields of last external storage match with
| status | 2 |
Expand Down

0 comments on commit 6977855

Please sign in to comment.