From 8d1b91dfca2e56adfe9272b6fa5a96d863d2ecbd Mon Sep 17 00:00:00 2001 From: REJack Date: Sun, 9 Dec 2018 17:15:23 +0100 Subject: [PATCH] updated Aauth/LoginTest & renamed loginFailedName to loginFailedUsername in all langs --- CHANGES.md | 2 +- application/Language/de/Aauth.php | 2 +- application/Language/en/Aauth.php | 2 +- application/Language/es/Aauth.php | 2 +- application/Language/fa/Aauth.php | 2 +- application/Language/fr/Aauth.php | 2 +- application/Language/id/Aauth.php | 2 +- application/Language/ru/Aauth.php | 2 +- application/Language/sv/Aauth.php | 2 +- application/Language/zh-CN/Aauth.php | 2 +- application/Language/zh-TW/Aauth.php | 2 +- application/Libraries/Aauth.php | 2 +- tests/Aauth/Libraries/Aauth/LoginTest.php | 117 +++++++++++++++++++++- 13 files changed, 126 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index aecdd64..f943634 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -151,7 +151,7 @@ - aauth_error_no_access => notVerified - aauth_error_account_not_verified => notVerified - aauth_error_login_failed_email => loginFailedEmail - - aauth_error_login_failed_name => loginFailedName + - aauth_error_login_failed_name => loginFailedUsername - aauth_error_login_failed_all => loginFailedAll - aauth_error_login_attempts_exceeded => loginAttemptsExceeded - aauth_error_email_invalid => invalidEmail diff --git a/application/Language/de/Aauth.php b/application/Language/de/Aauth.php index e01efbf..61680a4 100644 --- a/application/Language/de/Aauth.php +++ b/application/Language/de/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Dein Account wurde bisher nicht bestätigt. Bitte prüfe deine E-Mails und bestätige deine Registrierung.', 'loginFailedEmail' => 'E-Mail-Adresse oder Passwort falsch.', - 'loginFailedName' => 'Benutzername oder Passwort falsch.', + 'loginFailedUsername' => 'Benutzername oder Passwort falsch.', 'loginFailedAll' => 'E-Mail-Adresse, Benutzername oder Passwort falsch.', 'loginAttemptsExceeded' => 'Du hast die maximale Anzahl Login versuche erreicht, dein Account wurde gesperrt.', diff --git a/application/Language/en/Aauth.php b/application/Language/en/Aauth.php index c235ffb..146a92f 100644 --- a/application/Language/en/Aauth.php +++ b/application/Language/en/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Your account has not been verified. Please check your email and verify your account.', 'loginFailedEmail' => 'Email Address and Password do not match.', - 'loginFailedName' => 'Username and Password do not match.', + 'loginFailedUsername' => 'Username and Password do not match.', 'loginFailedAll' => 'Email, Username or Password do not match.', 'loginAttemptsExceeded' => 'You have exceeded your login attempts, your account has now been locked.', diff --git a/application/Language/es/Aauth.php b/application/Language/es/Aauth.php index b49cd9f..080d742 100644 --- a/application/Language/es/Aauth.php +++ b/application/Language/es/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Tu cuenta aún no ha sido verificada, por favor revisa tu correo electrónico y verifica tu cuenta.', 'loginFailedEmail' => 'El Correo electrónico y contraseña no coinciden.', - 'loginFailedName' => 'El Nombre de usuario y contraseña no coinciden.', + 'loginFailedUsername' => 'El Nombre de usuario y contraseña no coinciden.', 'loginFailedAll' => 'El Correo electrónico, nombre de usuario y contraseña no coinciden.', 'loginAttemptsExceeded' => 'Has excedido el número de intentos de inicio de sesión, tu cuenta ha sido bloqueada.', diff --git a/application/Language/fa/Aauth.php b/application/Language/fa/Aauth.php index cea0daf..d9ecc59 100644 --- a/application/Language/fa/Aauth.php +++ b/application/Language/fa/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'حساب کاربری شما تایید نشده است. لطفا ایمیل خود را برای تایید حسا کاربری بررسی کنید.', 'loginFailedEmail' => 'ایمیل و کلمه عبور همخوانی ندارند.', - 'loginFailedName' => 'نام کاربری و کلمه عبور همخوانی ندارند.', + 'loginFailedUsername' => 'نام کاربری و کلمه عبور همخوانی ندارند.', 'loginFailedAll' => 'ایمیل یا نام کاربری با کلمه عبور همخوانی ندارد.', 'loginAttemptsExceeded' => 'شما بیش از حد مجاز برای ورود به سایت تلاش کردید. حساب کاربری شما موقتا غیر فعال شد.', diff --git a/application/Language/fr/Aauth.php b/application/Language/fr/Aauth.php index eb18945..f16422b 100644 --- a/application/Language/fr/Aauth.php +++ b/application/Language/fr/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Votre compte n\'a pas été confirmé. Merci de vérifier vos email et de confirmer votre compte.', 'loginFailedEmail' => 'L\'adresse email et le mot de passe ne correspondent pas.', - 'loginFailedName' => 'Le nom d\'utilisateur et le mot de passe ne correspondent pas.', + 'loginFailedUsername' => 'Le nom d\'utilisateur et le mot de passe ne correspondent pas.', 'loginFailedAll' => 'L\'adresse email, le nom d\'utilisateur ou le mot de passe ne correspondent pas.', 'loginAttemptsExceeded' => 'Vous avez dépassé le nombre de tentatives de connexion autorisées, votre compte a été bloqué.', diff --git a/application/Language/id/Aauth.php b/application/Language/id/Aauth.php index 1840d39..d45b92d 100644 --- a/application/Language/id/Aauth.php +++ b/application/Language/id/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Akun anda belum diverifikasi. Silakan cek email anda dan verifikasi akun anda.', 'loginFailedEmail' => 'Email dan sandi yang anda masukkan tidak cocok.', - 'loginFailedName' => 'Username dan sandi yang Anda masukkan tidak cocok.', + 'loginFailedUsername' => 'Username dan sandi yang Anda masukkan tidak cocok.', 'loginFailedAll' => 'Email, username dan sandi yang Anda masukkan tidak cocok.', 'loginAttemptsExceeded' => 'Anda telah melebihi upaya login anda, akun anda telah diblokir.', diff --git a/application/Language/ru/Aauth.php b/application/Language/ru/Aauth.php index d53cbc0..a53601d 100644 --- a/application/Language/ru/Aauth.php +++ b/application/Language/ru/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Ваш акккаунт не подтвержден. Проверьте ваш ящик e-mail и подтвердите аккаунт.', 'loginFailedEmail' => 'Неверный email или пароль.', - 'loginFailedName' => 'Неверное имя пользователя или пароль.', + 'loginFailedUsername' => 'Неверное имя пользователя или пароль.', 'loginFailedAll' => 'Неверный E-mail, имя пользователя или пароль.', 'loginAttemptsExceeded' => 'Количество попыток входа превышено, ваш аккаунт временно заблокирован.', diff --git a/application/Language/sv/Aauth.php b/application/Language/sv/Aauth.php index c3356a7..6e42da2 100644 --- a/application/Language/sv/Aauth.php +++ b/application/Language/sv/Aauth.php @@ -44,7 +44,7 @@ return [ 'notVerified' => 'Ditt konto är inte bekräftat. Var vänlig kolla din e-post och bekräfta ditt konto.', 'loginFailedEmail' => 'E-postadressen och lösenordet stämmer inte överens.', - 'loginFailedName' => 'Användarnamnet och lösenordet stämmer inte överens.', + 'loginFailedUsername' => 'Användarnamnet och lösenordet stämmer inte överens.', 'loginFailedAll' => 'E-postadress, användarnamn och lösenord stämmer inte överens.', 'loginAttemptsExceeded' => 'Du har förbrukat dina försök att logga in, ditt konto har blivit låst.', diff --git a/application/Language/zh-CN/Aauth.php b/application/Language/zh-CN/Aauth.php index 217b519..f52a532 100644 --- a/application/Language/zh-CN/Aauth.php +++ b/application/Language/zh-CN/Aauth.php @@ -46,7 +46,7 @@ return [ 'notVerified' => '您的帐户尚未验证,请检查信箱并验证帐户。', 'loginFailedEmail' => '电邮地址和密码不符', - 'loginFailedName' => '用户名和密码不符', + 'loginFailedUsername' => '用户名和密码不符', 'loginFailedAll' => '电邮地址、用户名和或密码不符', 'loginAttemptsExceeded' => '您已达到登入尝试限制数,您的帐户已被锁住。', diff --git a/application/Language/zh-TW/Aauth.php b/application/Language/zh-TW/Aauth.php index 438d578..8d55cba 100644 --- a/application/Language/zh-TW/Aauth.php +++ b/application/Language/zh-TW/Aauth.php @@ -46,7 +46,7 @@ return [ 'notVerified' => '您的帳號尚未驗證,請檢查信箱並驗證帳號。', 'loginFailedEmail' => '電郵地址和密碼不符', - 'loginFailedName' => '用戶名和密碼不符', + 'loginFailedUsername' => '用戶名和密碼不符', 'loginFailedAll' => '電郵地址、用戶名和或密碼不符', 'loginAttemptsExceeded' => '您已達到登入嘗試限制數,您的帳號已被鎖住。', diff --git a/application/Libraries/Aauth.php b/application/Libraries/Aauth.php index 1107288..503681b 100644 --- a/application/Libraries/Aauth.php +++ b/application/Libraries/Aauth.php @@ -637,7 +637,7 @@ class Aauth { if (! $identifier || strlen($password) < $this->config->passwordMin || strlen($password) > $this->config->passwordMax) { - $this->error(lang('Aauth.loginFailedName')); + $this->error(lang('Aauth.loginFailedUsername')); return false; } diff --git a/tests/Aauth/Libraries/Aauth/LoginTest.php b/tests/Aauth/Libraries/Aauth/LoginTest.php index 1f2104b..f2a5693 100644 --- a/tests/Aauth/Libraries/Aauth/LoginTest.php +++ b/tests/Aauth/Libraries/Aauth/LoginTest.php @@ -1,5 +1,6 @@ getInstance(); - $this->library = new Aauth(NULL, $session); + $this->library = new Aauth(null, $session); $this->assertTrue($this->library->login('admin@example.com', 'password123456')); - print_r($_SESSION); + } + + public function testLoginFalseEmailFailedEmail() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $this->assertFalse($this->library->login('adminaexample.com', 'password123456')); + $this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalseEmailFailedPassword() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $this->assertFalse($this->library->login('admin@aexample.com', 'password')); + $this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalseEmailNotFound() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $this->assertFalse($this->library->login('admina@example.com', 'password123456')); + $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); + } + + public function testLoginUsernameTrue() + { + $session = $this->getInstance(); + $config = new AauthConfig(); + $config->loginUseUsername = true; + $this->library = new Aauth($config, $session); + $this->assertTrue($this->library->login('admin', 'password123456')); + } + + public function testLoginFalseUsernameFailedPassword() + { + $session = $this->getInstance(); + $config = new AauthConfig(); + $config->loginUseUsername = true; + $this->library = new Aauth($config, $session); + $this->assertFalse($this->library->login('admin', 'password')); + $this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalseUsernameNotFound() + { + $session = $this->getInstance(); + $config = new AauthConfig(); + $config->loginUseUsername = true; + $this->library = new Aauth($config, $session); + $this->assertFalse($this->library->login('admina', 'password')); + $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalseNotVerified() + { + $userVariableModel = new UserVariableModel(); + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $userVariableModel->save(1, 'verification_code', '12345678', true); + $this->assertFalse($this->library->login('admin@aexample.com', 'password123456')); + $this->assertEquals(lang('Aauth.notVerified'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalseBanned() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $this->library->banUser(1); + $this->assertFalse($this->library->login('admin@aexample.com', 'password123456')); + $this->assertEquals(lang('Aauth.invalidUserBanned'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalse() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $this->assertFalse($this->library->login('admin@aexample.com', 'password1234567')); + $this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]); + } + + public function testLoginFalseLoginAttemptsExceeded() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->library->login('admina@example.com', 'password123456'); + $this->assertFalse($this->library->login('admina@example.com', 'password123456')); + $this->assertEquals(lang('Aauth.loginAttemptsExceeded'), $this->library->getErrorsArray()[0]); } public function testIsLoggedIn() { $session = $this->getInstance(); - $this->library = new Aauth(NULL, $session); + $this->library = new Aauth(null, $session); + $session->set('user', [ + 'loggedIn' => true, + ]); + $this->assertTrue($this->library->isLoggedIn()); + } + + public function testLogout() + { + $session = $this->getInstance(); + $this->library = new Aauth(null, $session); $session->set('user', [ 'loggedIn' => true, ]); $this->assertTrue($this->library->isLoggedIn()); + $this->library->logout(); + $this->assertFalse($this->library->isLoggedIn()); } }