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]>
  • Loading branch information
artonge committed Nov 27, 2024
1 parent 728b6ec commit 139268f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion 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->sendJsonWithRequestTokenAndBasicAutherr('POST', '/index.php/apps/files_external/globalstorages', $fields);
$this->theHTTPStatusCodeShouldBe('201');

$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($this->currentUser . ':' . self::TEST_PASSWORD),
],
'body' => $fieldsAsJsonString,
];
$this->sendingAToWithRequesttoken($method, $url, $body);
}
}

0 comments on commit 139268f

Please sign in to comment.