Skip to content

Commit

Permalink
fix login test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Nov 22, 2024
1 parent ce3cc88 commit 048e512
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
44 changes: 18 additions & 26 deletions tests/Fixture/UsersFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace CakeDC\Api\Test\Fixture;

use Authentication\PasswordHasher\DefaultPasswordHasher;
use Authentication\PasswordHasher\PasswordHasherFactory;
use Cake\TestSuite\Fixture\TestFixture;
use CakeDC\Users\Webauthn\Base64Utility;

Expand All @@ -20,12 +22,20 @@
*/
class UsersFixture extends TestFixture
{

/**
* records property
*
* @var array
*/
public array $records = [];

/**
* Init method
*
* @return void
*/
public function init(): void
public function __construct()
{
$this->records = [
[
Expand All @@ -42,20 +52,18 @@ public function init(): void
'secret' => 'yyy',
'secret_verified' => false,
'tos_date' => '2015-06-24 17:33:54',
'active' => false,
'active' => true,
'is_superuser' => true,
'role' => 'admin',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
'additional_data' => null,
'last_login' => '2015-06-24 17:33:54',
],
[
'id' => '00000000-0000-0000-0000-000000000002',
'username' => 'user-2',
'email' => '[email protected]',
//The password real value is 12345
'password' => '$2y$10$Nvu7ipP.z8tiIl75OdUvt.86vuG6iKMoHIOc7O7mboFI85hSyTEde',
'password' => '12345',
'first_name' => 'user',
'last_name' => 'second',
'token' => '6614f65816754310a5f0553436dd89e9',
Expand Down Expand Up @@ -212,28 +220,12 @@ public function init(): void
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
],
[
'id' => '00000000-0000-0000-0000-000000000010',
'username' => 'Lorem ipsum dolor sit amet',
'email' => 'Lorem ipsum dolor sit amet',
'password' => 'Lorem ipsum dolor sit amet',
'first_name' => 'Lorem ipsum dolor sit amet',
'last_name' => 'Lorem ipsum dolor sit amet',
'token' => 'Lorem ipsum dolor sit amet',
'token_expires' => '2015-06-24 17:33:54',
'api_token' => 'Lorem ipsum dolor sit amet',
'activation_date' => '2015-06-24 17:33:54',
'secret' => 'Lorem ipsum dolor sit amet',
'secret_verified' => false,
'tos_date' => '2015-06-24 17:33:54',
'active' => true,
'is_superuser' => false,
'role' => 'Lorem ipsum dolor sit amet',
'created' => '2015-06-24 17:33:54',
'modified' => '2015-06-24 17:33:54',
],
];

parent::init();
parent::__construct();
$hasher = PasswordHasherFactory::build(DefaultPasswordHasher::class);
foreach ($this->records as $id => $record) {
$this->records[$id]['password'] = $hasher->hash($record['password']);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function testSuccessLogin()
'active' => true,
'api_token' => 'yyy',
'role' => 'admin',
'secret_verified' => false,
'last_login' => '2015-06-24T17:33:54+00:00',
];
$data = Hash::get($result, 'data');
unset($data['activation_date']);
Expand Down

0 comments on commit 048e512

Please sign in to comment.