Skip to content

Commit 048e512

Browse files
committed
fix login test cases
1 parent ce3cc88 commit 048e512

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

tests/Fixture/UsersFixture.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace CakeDC\Api\Test\Fixture;
1414

15+
use Authentication\PasswordHasher\DefaultPasswordHasher;
16+
use Authentication\PasswordHasher\PasswordHasherFactory;
1517
use Cake\TestSuite\Fixture\TestFixture;
1618
use CakeDC\Users\Webauthn\Base64Utility;
1719

@@ -20,12 +22,20 @@
2022
*/
2123
class UsersFixture extends TestFixture
2224
{
25+
26+
/**
27+
* records property
28+
*
29+
* @var array
30+
*/
31+
public array $records = [];
32+
2333
/**
2434
* Init method
2535
*
2636
* @return void
2737
*/
28-
public function init(): void
38+
public function __construct()
2939
{
3040
$this->records = [
3141
[
@@ -42,20 +52,18 @@ public function init(): void
4252
'secret' => 'yyy',
4353
'secret_verified' => false,
4454
'tos_date' => '2015-06-24 17:33:54',
45-
'active' => false,
55+
'active' => true,
4656
'is_superuser' => true,
4757
'role' => 'admin',
4858
'created' => '2015-06-24 17:33:54',
4959
'modified' => '2015-06-24 17:33:54',
50-
'additional_data' => null,
5160
'last_login' => '2015-06-24 17:33:54',
5261
],
5362
[
5463
'id' => '00000000-0000-0000-0000-000000000002',
5564
'username' => 'user-2',
5665
'email' => '[email protected]',
57-
//The password real value is 12345
58-
'password' => '$2y$10$Nvu7ipP.z8tiIl75OdUvt.86vuG6iKMoHIOc7O7mboFI85hSyTEde',
66+
'password' => '12345',
5967
'first_name' => 'user',
6068
'last_name' => 'second',
6169
'token' => '6614f65816754310a5f0553436dd89e9',
@@ -212,28 +220,12 @@ public function init(): void
212220
'created' => '2015-06-24 17:33:54',
213221
'modified' => '2015-06-24 17:33:54',
214222
],
215-
[
216-
'id' => '00000000-0000-0000-0000-000000000010',
217-
'username' => 'Lorem ipsum dolor sit amet',
218-
'email' => 'Lorem ipsum dolor sit amet',
219-
'password' => 'Lorem ipsum dolor sit amet',
220-
'first_name' => 'Lorem ipsum dolor sit amet',
221-
'last_name' => 'Lorem ipsum dolor sit amet',
222-
'token' => 'Lorem ipsum dolor sit amet',
223-
'token_expires' => '2015-06-24 17:33:54',
224-
'api_token' => 'Lorem ipsum dolor sit amet',
225-
'activation_date' => '2015-06-24 17:33:54',
226-
'secret' => 'Lorem ipsum dolor sit amet',
227-
'secret_verified' => false,
228-
'tos_date' => '2015-06-24 17:33:54',
229-
'active' => true,
230-
'is_superuser' => false,
231-
'role' => 'Lorem ipsum dolor sit amet',
232-
'created' => '2015-06-24 17:33:54',
233-
'modified' => '2015-06-24 17:33:54',
234-
],
235223
];
236224

237-
parent::init();
225+
parent::__construct();
226+
$hasher = PasswordHasherFactory::build(DefaultPasswordHasher::class);
227+
foreach ($this->records as $id => $record) {
228+
$this->records[$id]['password'] = $hasher->hash($record['password']);
229+
}
238230
}
239231
}

tests/TestCase/Integration/Service/Action/Auth/LoginActionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public function testSuccessLogin()
6464
'active' => true,
6565
'api_token' => 'yyy',
6666
'role' => 'admin',
67+
'secret_verified' => false,
68+
'last_login' => '2015-06-24T17:33:54+00:00',
6769
];
6870
$data = Hash::get($result, 'data');
6971
unset($data['activation_date']);

0 commit comments

Comments
 (0)