EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Add test
Yurii55fece7ebd44
diff --git a/tests/integration/Espo/Core/Authentication/AuthenticationTest.php b/tests/integration/Espo/Core/Authentication/AuthenticationTest.phpindex 6d2fb3eb2f..c1154f4452 100644--- a/tests/integration/Espo/Core/Authentication/AuthenticationTest.php+++ b/tests/integration/Espo/Core/Authentication/AuthenticationTest.php@@ -185,29 +185,7 @@ class AuthenticationTest extends BaseTestCaseUser::FIELD_PASSWORD => $password,]);- $result = $this->createAuthentication()->login(- data: AuthenticationData::create()- ->withUsername($username)- ->withPassword($password),- request: $this->createSimpleGetRequest(- headers: [- HeaderKey::AUTHORIZATION => 'any',- ],- ),- response: $this->createMock(Response::class),- );-- $this->assertTrue($result->isSuccess());-- $token = $result->getUser()->get(User::FIELD_TOKEN);-- $this->assertNotNull($token);-- //-- $secret = $this->getTokenSecret($token);-- $this->assertNotNull($secret);+ [$token, $secret] = $this->processLogIn($username, $password);$secondResult = $this->createAuthentication()->login(data: AuthenticationData::create()@@ -237,39 +215,53 @@ class AuthenticationTest extends BaseTestCaseUser::FIELD_PASSWORD => $password,]);- $result = $this->createAuthentication()->login(+ [$token] = $this->processLogIn($username, $password);++ $secondResult = $this->createAuthentication()->login(data: AuthenticationData::create()->withUsername($username)- ->withPassword($password),+ ->withPassword($token),request: $this->createSimpleGetRequest(- headers: [- HeaderKey::AUTHORIZATION => 'any',- ],+ cookieParams: [+ self::COOKIE_AUTH_TOKEN_SECRET => 'wrong',+ ]),response: $this->createMock(Response::class),);- $this->assertTrue($result->isSuccess());+ $this->assertFalse($secondResult->isSuccess());+ }- $token = $result->getUser()->get(User::FIELD_TOKEN);+ /**+ * @noinspection PhpUnhandledExceptionInspection+ */+ public function testLoginAuthTokenOnlySuccess(): void+ {+ $username = 'test';+ $password = 'hello';- $this->assertNotNull($token);+ $this->createUser([+ User::FIELD_USER_NAME => $username,+ User::FIELD_PASSWORD => $password,+ ]);- //+ [$token, $secret] = $this->processLogIn($username, $password);++ $this->assertNotNull($secret);$secondResult = $this->createAuthentication()->login(data: AuthenticationData::create()- ->withUsername($username)+ ->withByTokenOnly(true)->withPassword($token),request: $this->createSimpleGetRequest(cookieParams: [- self::COOKIE_AUTH_TOKEN_SECRET => 'wrong',+ self::COOKIE_AUTH_TOKEN_SECRET => $secret,]),response: $this->createMock(Response::class),);- $this->assertFalse($secondResult->isSuccess());+ $this->assertTrue($secondResult->isSuccess());}private function createAuthentication(?ApplicationUser $applicationUser = null): Authentication@@ -291,6 +283,7 @@ class AuthenticationTest extends BaseTestCasearray $headers = [],array $cookieParams = [],): RequestWrapper {+return $this->createRequest(method: Method::GET,headers: [@@ -310,4 +303,35 @@ class AuthenticationTest extends BaseTestCasereturn $authToken?->getSecret();}++ /**+ * @return array{string, string}+ * @noinspection PhpUnhandledExceptionInspection+ */+ private function processLogIn(string $username, string $password): array+ {+ $result = $this->createAuthentication()->login(+ data: AuthenticationData::create()+ ->withUsername($username)+ ->withPassword($password),+ request: $this->createSimpleGetRequest(+ headers: [+ HeaderKey::AUTHORIZATION => 'any',+ ],+ ),+ response: $this->createMock(Response::class),+ );++ $this->assertTrue($result->isSuccess());++ $token = $result->getUser()->get(User::FIELD_TOKEN);++ $this->assertNotNull($token);++ $secret = $this->getTokenSecret($token);++ $this->assertNotNull($secret);++ return [$token, $secret];+ }}