Skip to content

Commit 4a71313

Browse files
committed
test(ExternalStorage): Send basic auth during integrations tests
Signed-off-by: Louis Chemineau <[email protected]> [skip ci]
1 parent 271b0ac commit 4a71313

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

build/integration/features/bootstrap/ExternalStorage.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private function deleteStorage(string $storageId): void {
4848
* @param TableNode $fields
4949
*/
5050
public function loggedInUserCreatesExternalGlobalStorage(TableNode $fields): void {
51-
$this->sendJsonWithRequestToken('POST', '/index.php/apps/files_external/globalstorages', $fields);
51+
$this->sendJsonWithRequestTokenAndBasicAuth('POST', '/index.php/apps/files_external/globalstorages', $fields);
5252
$this->theHTTPStatusCodeShouldBe('201');
5353

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

6868
$this->lastExternalStorageData = json_decode($this->response->getBody(), $asAssociativeArray = true);
@@ -100,4 +100,23 @@ private function sendJsonWithRequestToken(string $method, string $url, TableNode
100100
];
101101
$this->sendingAToWithRequesttoken($method, $url, $body);
102102
}
103+
104+
private function sendJsonWithRequestTokenAndBasicAuth(string $method, string $url, TableNode $fields): void {
105+
$isFirstField = true;
106+
$fieldsAsJsonString = '{';
107+
foreach ($fields->getRowsHash() as $key => $value) {
108+
$fieldsAsJsonString .= ($isFirstField ? '' : ',') . '"' . $key . '":' . $value;
109+
$isFirstField = false;
110+
}
111+
$fieldsAsJsonString .= '}';
112+
113+
$body = [
114+
'headers' => [
115+
'Content-Type' => 'application/json',
116+
'Authorization' => 'Basic ' . base64_encode('admin:admin'),
117+
],
118+
'body' => $fieldsAsJsonString,
119+
];
120+
$this->sendingAToWithRequesttoken($method, $url, $body);
121+
}
103122
}

build/integration/features/external-storage.feature

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Feature: external-storage
1414
And As an "user1"
1515
And accepting last share
1616
When creating a share with
17-
| path | foo |
18-
| shareType | 3 |
17+
| path | foo |
18+
| shareType | 3 |
1919
Then the OCS status code should be "100"
2020
And the HTTP status code should be "200"
2121
And Share fields of last share match with
22-
| id | A_NUMBER |
23-
| url | AN_URL |
24-
| token | A_TOKEN |
22+
| id | A_NUMBER |
23+
| url | AN_URL |
24+
| token | A_TOKEN |
2525
| mimetype | httpd/unix-directory |
2626

2727
Scenario: Shares don't overwrite external storage
@@ -66,9 +66,9 @@ Feature: external-storage
6666
Scenario: Save an external storage with password provided by user
6767
Given Logging in using web as "admin"
6868
And logged in user creates external global storage
69-
| mountPoint | "ExternalStorageTest" |
70-
| backend | "owncloud" |
71-
| authMechanism | "password::userprovided" |
69+
| mountPoint | "ExternalStorageTest" |
70+
| backend | "owncloud" |
71+
| authMechanism | "password::userprovided" |
7272
| backendOptions | {"host":"http://localhost:8080","secure":false} |
7373
And fields of last external storage match with
7474
| status | 2 |
@@ -80,9 +80,9 @@ Feature: external-storage
8080
Scenario: Save an external storage again with an unmodified password provided by user
8181
Given Logging in using web as "admin"
8282
And logged in user creates external global storage
83-
| mountPoint | "ExternalStorageTest" |
84-
| backend | "owncloud" |
85-
| authMechanism | "password::userprovided" |
83+
| mountPoint | "ExternalStorageTest" |
84+
| backend | "owncloud" |
85+
| authMechanism | "password::userprovided" |
8686
| backendOptions | {"host":"http://localhost:8080","secure":false} |
8787
And fields of last external storage match with
8888
| status | 2 |
@@ -96,9 +96,9 @@ Feature: external-storage
9696
Scenario: Save an external storage with global credentials provided by user
9797
Given Logging in using web as "admin"
9898
And logged in user creates external global storage
99-
| mountPoint | "ExternalStorageTest" |
100-
| backend | "owncloud" |
101-
| authMechanism | "password::global::user" |
99+
| mountPoint | "ExternalStorageTest" |
100+
| backend | "owncloud" |
101+
| authMechanism | "password::global::user" |
102102
| backendOptions | {"host":"http://localhost:8080","secure":false} |
103103
And fields of last external storage match with
104104
| status | 2 |
@@ -110,9 +110,9 @@ Feature: external-storage
110110
Scenario: Save an external storage again with unmodified global credentials provided by user
111111
Given Logging in using web as "admin"
112112
And logged in user creates external global storage
113-
| mountPoint | "ExternalStorageTest" |
114-
| backend | "owncloud" |
115-
| authMechanism | "password::global::user" |
113+
| mountPoint | "ExternalStorageTest" |
114+
| backend | "owncloud" |
115+
| authMechanism | "password::global::user" |
116116
| backendOptions | {"host":"http://localhost:8080","secure":false} |
117117
And fields of last external storage match with
118118
| status | 2 |

0 commit comments

Comments
 (0)