|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/** |
| 3 | + * ownCloud |
| 4 | + * |
| 5 | + * @author Niraj Acharya <[email protected]> |
| 6 | + * @copyright Copyright (c) 2024 Niraj Acharya [email protected] |
| 7 | + * |
| 8 | + * This code is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License, |
| 10 | + * as published by the Free Software Foundation; |
| 11 | + * either version 3 of the License, or any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +use Behat\Behat\Context\Context; |
| 24 | +use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
| 25 | +use TestHelpers\BehatHelper; |
| 26 | +use GuzzleHttp\Exception\GuzzleException; |
| 27 | +use TestHelpers\AuthAppHelper; |
| 28 | + |
| 29 | +require_once 'bootstrap.php'; |
| 30 | + |
| 31 | +/** |
| 32 | + * AuthApp context |
| 33 | + */ |
| 34 | +class AuthAppContext implements Context { |
| 35 | + private FeatureContext $featureContext; |
| 36 | + |
| 37 | + /** |
| 38 | + * @BeforeScenario |
| 39 | + * |
| 40 | + * @param BeforeScenarioScope $scope |
| 41 | + * |
| 42 | + * @return void |
| 43 | + */ |
| 44 | + public function before(BeforeScenarioScope $scope): void { |
| 45 | + // Get the environment |
| 46 | + $environment = $scope->getEnvironment(); |
| 47 | + // Get all the contexts you need in this context |
| 48 | + $this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext'); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @When user :user creates app token with expiration time :expiration using the auth-app API |
| 53 | + * |
| 54 | + * @param string $user |
| 55 | + * @param string $expiration |
| 56 | + * |
| 57 | + * @return void |
| 58 | + */ |
| 59 | + public function userCreatesAppTokenWithExpirationTimeUsingTheAuthAppApi(string $user, string $expiration): void { |
| 60 | + $this->featureContext->setResponse( |
| 61 | + AuthAppHelper::createAppAuthToken( |
| 62 | + $this->featureContext->getBaseUrl(), |
| 63 | + $this->featureContext->getActualUsername($user), |
| 64 | + $this->featureContext->getPasswordForUser($user), |
| 65 | + $expiration, |
| 66 | + ) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @Given user :user has created app token with expiration time :expiration |
| 72 | + * |
| 73 | + * @param string $user |
| 74 | + * @param string $expiration |
| 75 | + * |
| 76 | + * @return void |
| 77 | + */ |
| 78 | + public function userHasCreatedAppTokenWithExpirationTime(string $user, string $expiration): void { |
| 79 | + $response = AuthAppHelper::createAppAuthToken( |
| 80 | + $this->featureContext->getBaseUrl(), |
| 81 | + $this->featureContext->getActualUsername($user), |
| 82 | + $this->featureContext->getPasswordForUser($user), |
| 83 | + $expiration, |
| 84 | + ); |
| 85 | + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @When user :user lists all created tokens using the auth-app API |
| 90 | + * |
| 91 | + * @param string $user |
| 92 | + * |
| 93 | + * @return void |
| 94 | + */ |
| 95 | + public function userListsAllCreatedTokensUsingTheAuthAppApi(string $user): void { |
| 96 | + $this->featureContext->setResponse( |
| 97 | + AuthAppHelper::listAllAppAuthTokensForUser( |
| 98 | + $this->featureContext->getBaseUrl(), |
| 99 | + $this->featureContext->getActualUsername($user), |
| 100 | + $this->featureContext->getPasswordForUser($user), |
| 101 | + ) |
| 102 | + ); |
| 103 | + } |
| 104 | +} |
0 commit comments