From de7606dc6802a026f8ce33115c2f51a304aabc61 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sat, 21 Jul 2018 13:05:25 +0200 Subject: Adds disabled user unit tests Signed-off-by: Michael Weimann --- tests/Core/Controller/LoginControllerTest.php | 50 +++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 1e26d86a039..7ebd6ee8340 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -286,7 +286,52 @@ class LoginControllerTest extends TestCase { $this->assertEquals($expectedResponse, $this->loginController->showLoginForm('LdapUser', '', '')); } - public function testShowLoginFormForUserNamedNull() { + /** + * Asserts that a disabled user can't login and gets the expected response. + */ + public function testLoginForDisabledUser() { + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ + $user = $this->createMock(IUser::class); + $user->method('getUID') + ->willReturn('uid'); + $user->method('isEnabled') + ->willReturn(false); + + $this->request + ->expects($this->once()) + ->method('passesCSRFCheck') + ->willReturn(true); + + $this->userSession + ->method('isLoggedIn') + ->willReturn(false); + + $loginName = 'iMDisabled'; + $password = 'secret'; + + $this->session + ->expects($this->once()) + ->method('set') + ->with('loginMessages', [ + [LoginController::LOGIN_MSG_USERDISABLED], [] + ]); + + $this->userManager + ->expects($this->once()) + ->method('get') + ->with($loginName) + ->willReturn($user); + + $expected = new RedirectResponse(''); + $expected->throttle(['user' => $loginName]); + + $response = $this->loginController->tryLogin( + $loginName, $password, null, false, 'Europe/Berlin', '1' + ); + $this->assertEquals($expected, $response); + } + + public function testShowLoginFormForUserNamed0() { $this->userSession ->expects($this->once()) ->method('isLoggedIn') @@ -297,8 +342,7 @@ class LoginControllerTest extends TestCase { ->with('lost_password_link') ->willReturn(false); $user = $this->createMock(IUser::class); - $user - ->expects($this->once()) + $user->expects($this->once()) ->method('canChangePassword') ->willReturn(false); $this->userManager -- cgit v1.2.3 From 801bf813178573b539a8d66bcb1420cd11455994 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Sat, 21 Jul 2018 13:05:34 +0200 Subject: Adds disabled user acceptance tests Signed-off-by: Michael Weimann --- tests/acceptance/features/bootstrap/LoginPageContext.php | 16 ++++++++++++++++ tests/acceptance/features/login.feature | 6 ++++++ tests/acceptance/installAndConfigureServer.sh | 2 ++ 3 files changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/acceptance/features/bootstrap/LoginPageContext.php b/tests/acceptance/features/bootstrap/LoginPageContext.php index 1496e3030c2..df7944aa912 100644 --- a/tests/acceptance/features/bootstrap/LoginPageContext.php +++ b/tests/acceptance/features/bootstrap/LoginPageContext.php @@ -70,6 +70,14 @@ class LoginPageContext implements Context, ActorAwareInterface { describedAs("Wrong password message in Login page"); } + /** + * @return Locator + */ + public static function userDisabledMessage() { + return Locator::forThe()->xpath("//*[@class = 'warning userDisabledMsg' and normalize-space() = 'User disabled']")-> + describedAs('User disabled message on login page'); + } + /** * @When I log in with user :user and password :password */ @@ -96,6 +104,14 @@ class LoginPageContext implements Context, ActorAwareInterface { $this->actor->find(self::wrongPasswordMessage(), 10)->isVisible()); } + /** + * @Then I see that the disabled user message is shown + */ + public function iSeeThatTheDisabledUserMessageIsShown() { + PHPUnit_Framework_Assert::assertTrue( + $this->actor->find(self::userDisabledMessage(), 10)->isVisible()); + } + /** * @BeforeScenario */ diff --git a/tests/acceptance/features/login.feature b/tests/acceptance/features/login.feature index 3a31d3f88bd..44353d37c65 100644 --- a/tests/acceptance/features/login.feature +++ b/tests/acceptance/features/login.feature @@ -28,6 +28,12 @@ Feature: login Then I see that the current page is the Login page And I see that a wrong password message is shown + Scenario: try to log in as disabled user + Given I visit the Home page + When I log in with user disabledUser and password 123456acb + Then I see that the current page is the Login page + And I see that the disabled user message is shown + Scenario: log in with invalid user once fixed by admin Given I act as John And I can not log in with user unknownUser and password 123456acb diff --git a/tests/acceptance/installAndConfigureServer.sh b/tests/acceptance/installAndConfigureServer.sh index c61faeda238..98de72bf45e 100755 --- a/tests/acceptance/installAndConfigureServer.sh +++ b/tests/acceptance/installAndConfigureServer.sh @@ -35,6 +35,8 @@ fi php occ maintenance:install --admin-pass=admin OC_PASS=123456acb php occ user:add --password-from-env user0 +OC_PASS=123456acb php occ user:add --password-from-env disabledUser +php occ user:disable disabledUser if [ "$NEXTCLOUD_SERVER_DOMAIN" != "" ]; then # Default first trusted domain is "localhost"; replace it with given domain. -- cgit v1.2.3