-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POC][tests-only] add endpoints to accept ocis commands #9546
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6e2ccef
feat: add command and stop endpoints
saw-jan d1d25ae
feat: add option to skip running ocis
saw-jan 3306a1f
timeout command execution
saw-jan 733f185
feat: add start endpoint
saw-jan 7f0a1b0
fix: cumulative env and clear command var
saw-jan d8dff89
feat: allow interactive command execution
saw-jan 2b88c19
refactor: allow any commands and user inputs
saw-jan 86fd73e
refactor: respond 409 conflict if server is already running
saw-jan 9baecdf
fix: return early if the ocis is not running
saw-jan fd6e773
test: prepare cli test suite
saw-jan 78ca9ba
test: add cli test for resetting user password
saw-jan 13b428e
refactor: remove stdins from the command logs
saw-jan 9e6b6bc
test: run cli test suites
saw-jan d8ab9c5
docs: add docs on new APIs
saw-jan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* ownCloud | ||
* | ||
* @author Sajan Gurung <[email protected]> | ||
* @copyright Copyright (c) 2024 Sajan Gurung [email protected] | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, | ||
* as published by the Free Software Foundation; | ||
* either version 3 of the License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace TestHelpers; | ||
|
||
use GuzzleHttp\Exception\ConnectException; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
use GuzzleHttp\Psr7\Request; | ||
use Psr\Http\Message\ResponseInterface; | ||
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 { | ||
$url = OcisConfigHelper::getWrapperUrl() . "/command"; | ||
return OcisConfigHelper::sendRequest($url, "POST", \json_encode($body)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* ownCloud | ||
* | ||
* @author Sajan Gurung <[email protected]> | ||
* @copyright Copyright (c) 2024 Sajan Gurung [email protected] | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, | ||
* as published by the Free Software Foundation; | ||
* either version 3 of the License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use Behat\Behat\Context\Context; | ||
use PHPUnit\Framework\Assert; | ||
use Psr\Http\Message\ResponseInterface; | ||
use TestHelpers\CliHelper; | ||
use TestHelpers\OcisConfigHelper; | ||
|
||
/** | ||
* CLI context | ||
*/ | ||
class CliContext implements Context { | ||
private FeatureContext $featureContext; | ||
|
||
/** | ||
* @BeforeScenario | ||
* | ||
* @param BeforeScenarioScope $scope | ||
* | ||
* @return void | ||
*/ | ||
public function setUpScenario(BeforeScenarioScope $scope): void { | ||
// Get the environment | ||
$environment = $scope->getEnvironment(); | ||
// Get all the contexts you need in this context | ||
$this->featureContext = $environment->getContext('FeatureContext'); | ||
} | ||
|
||
/** | ||
* @Given the administrator has stopped the server | ||
* | ||
* @return void | ||
*/ | ||
public function theAdministratorHasStoppedTheServer(): void { | ||
$response = OcisConfigHelper::stopOcis(); | ||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); | ||
} | ||
|
||
/** | ||
* @Given the administrator has started the server | ||
* | ||
* @return void | ||
*/ | ||
public function theAdministratorHasStartedTheServer(): void { | ||
$response = OcisConfigHelper::startOcis(); | ||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); | ||
} | ||
|
||
/** | ||
* @When the administrator resets the password of user :user to :password using the CLI | ||
* | ||
* @param string $user | ||
* @param string $password | ||
* | ||
* @return void | ||
*/ | ||
public function theAdministratorResetsThePasswordOfUserUsingTheCLI(string $user, string $password): void { | ||
$command = "idm resetpassword -u $user"; | ||
$body = [ | ||
"command" => $command, | ||
"inputs" => [$password, $password] | ||
]; | ||
|
||
$this->featureContext->setResponse(CliHelper::runCommand($body)); | ||
$this->featureContext->updateUserPassword($user, $password); | ||
} | ||
|
||
/** | ||
* @Then the command should be successful | ||
* | ||
* @return void | ||
*/ | ||
public function theCommandShouldBeSuccessful(): void { | ||
$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"]); | ||
} | ||
|
||
/** | ||
* @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(); | ||
$jsonResponse = $this->featureContext->getJsonDecodedResponse($response); | ||
|
||
if ($shouldOrNot === "should") { | ||
Assert::assertStringContainsString($output, $jsonResponse["message"]); | ||
} else { | ||
Assert::assertStringNotContainsString($output, $jsonResponse["message"]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHat will it throw if it's GuzzleException and response is not null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will not throw but returns the response