diff options
author | Zoltan Flamis <flamisz@gmail.com> | 2021-03-16 16:29:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 16:29:22 +0300 |
commit | 9ae5d067b064f64a393b636b223630ad67f99883 (patch) | |
tree | b8050f87a1a0c070fb4be9b922176d0d134dc50c /plugins/UsersManager/tests/Integration/APITest.php | |
parent | 4493012f3ad24dc9b773ec7212ca2f38e41ac57c (diff) |
Check usernames and emails against each other on user create and update (#17296)
* check username and email together on user create and update
* Update APITest.php
Diffstat (limited to 'plugins/UsersManager/tests/Integration/APITest.php')
-rw-r--r-- | plugins/UsersManager/tests/Integration/APITest.php | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/plugins/UsersManager/tests/Integration/APITest.php b/plugins/UsersManager/tests/Integration/APITest.php index 5ce6ba2bd0..6aec636762 100644 --- a/plugins/UsersManager/tests/Integration/APITest.php +++ b/plugins/UsersManager/tests/Integration/APITest.php @@ -137,7 +137,7 @@ class APITest extends IntegrationTestCase * @var Model */ private $model; - + private $login = 'userLogin'; private $password = 'password'; @@ -159,14 +159,14 @@ class APITest extends IntegrationTestCase Fixture::createWebsite('2014-01-01 00:00:00'); $this->api->addUser($this->login, $this->password, $this->email); } - + public function tearDown(): void { Config::getInstance()->General['enable_update_users_email'] = 1; - parent::tearDown(); + parent::tearDown(); } - + public function test_setUserAccess_ShouldTriggerRemoveSiteAccessEvent_IfAccessToAWebsiteIsRemoved() { $eventTriggered = false; @@ -387,6 +387,49 @@ class APITest extends IntegrationTestCase $this->api->updateUser($this->login, str_pad('foo', UsersManager::PASSWORD_MAX_LENGTH + 1), 'email@example.com', false, $this->password); } + public function test_update_user_fails_if_email_exists_as_other_user_username() + { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('UsersManager_ExceptionEmailExistsAsLogin'); + + $user2 = 'existed@example.com'; + $this->api->addUser($user2, 'password', 'userlogin2@password.de'); + + $this->api->updateUser($this->login, $this->password, $user2, false, $this->password); + } + + public function test_update_can_update_user_email_to_own_username() + { + $user2 = 'ownemail@example.com'; + $password = 'password'; + $this->api->addUser($user2, $password, 'ownemail_wrong@example.com'); + + FakeAccess::$identity = $user2; + $this->api->updateUser($user2, $password, $user2, false, $password); + + $user2Array = $this->api->getUser($user2); + $this->assertEquals($user2Array['email'], $user2); + } + + public function test_cannot_create_user_if_email_exists_as_username() + { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('UsersManager_ExceptionEmailExistsAsLogin'); + + $user2 = 'existed@example.com'; + $this->api->addUser($user2, 'password', 'email@example.com'); + + $this->api->addUser('user3', 'password', $user2); + } + + public function test_cannot_create_user_if_username_exists_as_email() + { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('UsersManager_ExceptionLoginExistsAsEmail'); + + $this->api->addUser($this->email, 'password', 'new_user@example.com'); + } + public function test_getSitesAccessFromUser_forSuperUser() { $user2 = 'userLogin2'; |