Skip to content

Commit

Permalink
add action Auth to verify SVN username/password
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Dec 17, 2018
1 parent 41c96f5 commit 6fce491
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/CrowdStar/SVNAgent/Actions/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**************************************************************************
* Copyright 2018 Glu Mobile Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*************************************************************************/

namespace CrowdStar\SVNAgent\Actions;

use CrowdStar\SVNAgent\SVNHelper;
use CrowdStar\SVNAgent\Traits\SimpleResponseTrait;
use MrRio\ShellWrap;

/**
* Class Auth
* Verify the SVN username/password passed in.
*
* @package CrowdStar\SVNAgent\Actions
*/
class Auth extends AbstractAction implements PathNotRequiredActionInterface
{
use SimpleResponseTrait;

/**
* @inheritdoc
*/
public function processAction(): AbstractAction
{
$this->setMessage('check SVN credentials')->exec(
function () {
ShellWrap::svn('info', $this->getConfig()->getSvnRoot(), SVNHelper::getOptions($this->getRequest()));
}
);

return $this;
}
}
76 changes: 76 additions & 0 deletions tests/CrowdStar/SVNAgent/Actions/AuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**************************************************************************
* Copyright 2018 Glu Mobile Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*************************************************************************/

namespace CrowdStar\Tests\SVNAgent\Actions;

use CrowdStar\SVNAgent\Actions\AbstractAction;
use CrowdStar\SVNAgent\Actions\Auth;
use CrowdStar\SVNAgent\Exceptions\ClientException;
use CrowdStar\SVNAgent\Request;
use CrowdStar\Tests\SVNAgent\AbstractSvnTestCase;

/**
* Class AuthTest
*
* @package CrowdStar\Tests\SVNAgent\Actions
*/
class AuthTest extends AbstractSvnTestCase
{
/**
* @return array
*/
public function dataProcessAction(): array
{
return [
[
false,
array_merge($this->getBasicRequestData(), ['username' => 'invalid_username']),
'SVN access with invalid username',
],
[
true,
$this->getBasicRequestData(),
'SVN access with valid username/password',
],
[
false,
array_merge($this->getBasicRequestData(), ['password' => 'invalid_password']),
'SVN access with invalid password',
],
];
}

/**
* @dataProvider dataProcessAction
* @covers AbstractAction::run()
* @covers AbstractAction::process()
* @covers Auth::processAction()
* @group svn-server
* @param bool $expected
* @param array $requestData
* @param string $message
* @throws ClientException
*/
public function testProcessAction(bool $expected, array $requestData, string $message)
{
$this->assertSame(
$expected,
(new Auth((new Request())->init($requestData)))->run()->toArray()['success'],
$message
);
}
}

0 comments on commit 6fce491

Please sign in to comment.