mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-05 19:48:59 -06:00
refactor: remove stdins from the command logs
This commit is contained in:
@@ -32,15 +32,14 @@ use TestHelpers\OcisConfigHelper;
|
||||
* A helper class for running oCIS CLI commands
|
||||
*/
|
||||
class CliHelper {
|
||||
|
||||
/**
|
||||
* @param array $body
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function runCommand(array $body): ResponseInterface {
|
||||
public static function runCommand(array $body): ResponseInterface {
|
||||
$url = OcisConfigHelper::getWrapperUrl() . "/command";
|
||||
return OcisConfigHelper::sendRequest($url, "POST", \json_encode($body));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class CliContext implements Context {
|
||||
$environment = $scope->getEnvironment();
|
||||
// Get all the contexts you need in this context
|
||||
$this->featureContext = $environment->getContext('FeatureContext');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the administrator has stopped the server
|
||||
@@ -53,7 +53,7 @@ class CliContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorHasStoppedTheServer(): void {
|
||||
$response = OcisConfigHelper::stopOcis();
|
||||
$response = OcisConfigHelper::stopOcis();
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class CliContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorHasStartedTheServer(): void {
|
||||
$response = OcisConfigHelper::startOcis();
|
||||
$response = OcisConfigHelper::startOcis();
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
|
||||
}
|
||||
|
||||
@@ -76,13 +76,13 @@ class CliContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorResetsThePasswordOfUserUsingTheCLI(string $user, string $password): void {
|
||||
$command = "idm resetpassword -u $user";
|
||||
$body = [
|
||||
"command" => $command,
|
||||
"inputs" => [$password, $password]
|
||||
];
|
||||
$command = "idm resetpassword -u $user";
|
||||
$body = [
|
||||
"command" => $command,
|
||||
"inputs" => [$password, $password]
|
||||
];
|
||||
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
$this->featureContext->setResponse(CliHelper::runCommand($body));
|
||||
$this->featureContext->updateUserPassword($user, $password);
|
||||
}
|
||||
|
||||
@@ -92,24 +92,25 @@ class CliContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function theCommandShouldBeSuccessful(): void {
|
||||
$response = $this->featureContext->getResponse();
|
||||
$response = $this->featureContext->getResponse();
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
|
||||
|
||||
$jsonResponse = $this->featureContext->getJsonDecodedResponse($response);
|
||||
|
||||
Assert::assertSame("OK", $jsonResponse["status"]);
|
||||
Assert::assertSame(0, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"]);
|
||||
Assert::assertSame("OK", $jsonResponse["status"]);
|
||||
Assert::assertSame(0, $jsonResponse["exitCode"], "Expected exit code to be 0, but got " . $jsonResponse["exitCode"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the command output (should|should not) contain "([^"]*)"$/
|
||||
*
|
||||
* @param string $shouldOrNot
|
||||
* @param string $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theCommandOutputShouldContain(string $shouldOrNot,string $output): void {
|
||||
$response = $this->featureContext->getResponse();
|
||||
public function theCommandOutputShouldContain(string $shouldOrNot, string $output): void {
|
||||
$response = $this->featureContext->getResponse();
|
||||
$jsonResponse = $this->featureContext->getJsonDecodedResponse($response);
|
||||
|
||||
if ($shouldOrNot === "should") {
|
||||
@@ -118,4 +119,4 @@ class CliContext implements Context {
|
||||
Assert::assertStringNotContainsString($output, $jsonResponse["message"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,7 +672,6 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$this->theHTTPStatusCodeShouldBe([200, 409], 'Starting oCIS server', $response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the externally-defined admin username, if any
|
||||
*
|
||||
|
||||
@@ -14,4 +14,4 @@ Feature: reset user password via CLI command
|
||||
But the command output should not contain "Failed to update user password: entry does not exist"
|
||||
And the administrator has started the server
|
||||
And user "Alice" should be able to create folder "newFolder" using password "newpass"
|
||||
But user "Alice" should not be able to create folder "anotherFolder" using password "%alt1%"
|
||||
But user "Alice" should not be able to create folder "anotherFolder" using password "%alt1%"
|
||||
|
||||
@@ -266,5 +266,8 @@ func RunCommand(command string, inputs []string) (int, string) {
|
||||
io.Copy(logs, ptyF)
|
||||
cmdOutput += logs.String()
|
||||
|
||||
// TODO: find if there is a better way to remove stdins from the output
|
||||
cmdOutput = strings.TrimLeft(cmdOutput, strings.Join(inputs, "\r\n"))
|
||||
|
||||
return c.ProcessState.ExitCode(), cmdOutput
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user