Skip to content

Commit db88889

Browse files
committed
IBX-8804: Moved PASSWORD_HASH_OAUTH2 from ibexa/oauth2-client
1 parent 04b97ef commit db88889

File tree

7 files changed

+37
-154
lines changed

7 files changed

+37
-154
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61010,41 +61010,6 @@ parameters:
6101061010
count: 1
6101161011
path: tests/lib/Repository/Values/User/UserTest.php
6101261012

61013-
-
61014-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testGetName\\(\\) has no return type specified\\.$#"
61015-
count: 1
61016-
path: tests/lib/Repository/Values/User/UserTest.php
61017-
61018-
-
61019-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testIsPropertySet\\(\\) has no return type specified\\.$#"
61020-
count: 1
61021-
path: tests/lib/Repository/Values/User/UserTest.php
61022-
61023-
-
61024-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testMissingProperty\\(\\) has no return type specified\\.$#"
61025-
count: 1
61026-
path: tests/lib/Repository/Values/User/UserTest.php
61027-
61028-
-
61029-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testNewClass\\(\\) has no return type specified\\.$#"
61030-
count: 1
61031-
path: tests/lib/Repository/Values/User/UserTest.php
61032-
61033-
-
61034-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testObjectProperties\\(\\) has no return type specified\\.$#"
61035-
count: 1
61036-
path: tests/lib/Repository/Values/User/UserTest.php
61037-
61038-
-
61039-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testReadOnlyProperty\\(\\) has no return type specified\\.$#"
61040-
count: 1
61041-
path: tests/lib/Repository/Values/User/UserTest.php
61042-
61043-
-
61044-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Repository\\\\Values\\\\User\\\\UserTest\\:\\:testUnsetProperty\\(\\) has no return type specified\\.$#"
61045-
count: 1
61046-
path: tests/lib/Repository/Values/User/UserTest.php
61047-
6104861013
-
6104961014
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Search\\\\Common\\\\FieldValueMapper\\\\RemoteIdentifierMapperTest\\:\\:getDataForTestCanMap\\(\\) return type has no value type specified in iterable type iterable\\.$#"
6105061015
count: 1

src/contracts/Repository/Values/User/User.php

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Ibexa\Contracts\Core\Repository\Values\User;
1010

11+
use DateTimeInterface;
1112
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1213

1314
/**
@@ -24,63 +25,36 @@ abstract class User extends Content implements UserReference
2425
/**
2526
* @var int[] List of supported (by default) hash types.
2627
*/
27-
public const SUPPORTED_PASSWORD_HASHES = [
28+
public const array SUPPORTED_PASSWORD_HASHES = [
2829
self::PASSWORD_HASH_BCRYPT,
2930
self::PASSWORD_HASH_PHP_DEFAULT,
31+
self::PASSWORD_HASH_INVALID,
3032
];
3133

32-
/** @var int Passwords in bcrypt */
33-
public const PASSWORD_HASH_BCRYPT = 6;
34+
public const int PASSWORD_HASH_BCRYPT = 6;
3435

35-
/** @var int Passwords hashed by PHPs default algorithm, which may change over time */
36-
public const PASSWORD_HASH_PHP_DEFAULT = 7;
36+
public const int PASSWORD_HASH_PHP_DEFAULT = 7;
3737

38-
/** @var int Default password hash, used when none is specified, may change over time */
39-
public const DEFAULT_PASSWORD_HASH = self::PASSWORD_HASH_PHP_DEFAULT;
38+
public const int PASSWORD_HASH_INVALID = 256;
4039

41-
/**
42-
* User login.
43-
*
44-
* @var string
45-
*/
46-
protected $login;
40+
public const int DEFAULT_PASSWORD_HASH = self::PASSWORD_HASH_PHP_DEFAULT;
4741

48-
/**
49-
* User E-Mail address.
50-
*
51-
* @var string
52-
*/
53-
protected $email;
42+
protected string $login;
5443

55-
/**
56-
* User password hash.
57-
*
58-
* @var string
59-
*/
60-
protected $passwordHash;
44+
protected string $email;
6145

62-
/**
63-
* Datetime of last password update.
64-
*
65-
* @var \DateTimeInterface|null
66-
*/
67-
protected $passwordUpdatedAt;
46+
protected string $passwordHash;
6847

69-
/**
70-
* Hash algorithm used to hash the password.
71-
*
72-
* @var int
73-
*/
74-
protected $hashAlgorithm;
48+
protected ?DateTimeInterface $passwordUpdatedAt;
49+
50+
protected int $hashAlgorithm;
7551

7652
/**
7753
* Flag to signal if user is enabled or not.
7854
*
79-
* User can not login if false
80-
*
81-
* @var bool
55+
* User cannot login if false
8256
*/
83-
protected $enabled = false;
57+
protected bool $enabled = false;
8458

8559
/**
8660
* Max number of time user is allowed to login.
@@ -90,7 +64,7 @@ abstract class User extends Content implements UserReference
9064
*
9165
* @var int
9266
*/
93-
protected $maxLogin;
67+
protected int $maxLogin;
9468

9569
public function getUserId(): int
9670
{

src/lib/Repository/User/Exception/UnsupportedPasswordHashType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Ibexa\Core\Base\Exceptions\InvalidArgumentException;
1212

13-
class UnsupportedPasswordHashType extends InvalidArgumentException
13+
final class UnsupportedPasswordHashType extends InvalidArgumentException
1414
{
1515
public function __construct(int $hashType)
1616
{

src/lib/Repository/User/PasswordHashService.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
namespace Ibexa\Core\Repository\User;
1010

11+
use Ibexa\Contracts\Core\Repository\PasswordHashService as APIPasswordHashService;
1112
use Ibexa\Contracts\Core\Repository\Values\User\User;
1213
use Ibexa\Core\Repository\User\Exception\UnsupportedPasswordHashType;
1314

1415
/**
1516
* @internal
1617
*/
17-
final class PasswordHashService implements PasswordHashServiceInterface
18+
final class PasswordHashService implements APIPasswordHashService
1819
{
19-
/** @var int */
20-
private $defaultHashType;
20+
private int $defaultHashType;
2121

2222
public function __construct(int $hashType = User::DEFAULT_PASSWORD_HASH)
2323
{
@@ -56,6 +56,9 @@ public function createPasswordHash(
5656
case User::PASSWORD_HASH_PHP_DEFAULT:
5757
return password_hash($password, PASSWORD_DEFAULT);
5858

59+
case User::PASSWORD_HASH_INVALID:
60+
return '';
61+
5962
default:
6063
throw new UnsupportedPasswordHashType($hashType);
6164
}
@@ -68,7 +71,11 @@ public function isValidPassword(
6871
string $passwordHash,
6972
?int $hashType = null
7073
): bool {
71-
if ($hashType === User::PASSWORD_HASH_BCRYPT || $hashType === User::PASSWORD_HASH_PHP_DEFAULT) {
74+
if (
75+
$hashType === User::PASSWORD_HASH_BCRYPT
76+
|| $hashType === User::PASSWORD_HASH_PHP_DEFAULT
77+
|| $hashType === User::PASSWORD_HASH_INVALID
78+
) {
7279
// In case of bcrypt let PHP's password functionality do its magic
7380
return password_verify($plainPassword, $passwordHash);
7481
}

src/lib/Repository/User/PasswordHashServiceInterface.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/lib/Repository/User/PasswordHashServiceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515

1616
final class PasswordHashServiceTest extends TestCase
1717
{
18-
private const NON_EXISTING_PASSWORD_HASH = PHP_INT_MAX;
18+
private const int NON_EXISTING_PASSWORD_HASH = PHP_INT_MAX;
1919

20-
/** @var \Ibexa\Core\Repository\User\PasswordHashService */
21-
private $passwordHashService;
20+
private PasswordHashService $passwordHashService;
2221

2322
protected function setUp(): void
2423
{
@@ -31,6 +30,7 @@ public function testGetSupportedHashTypes(): void
3130
[
3231
User::PASSWORD_HASH_BCRYPT,
3332
User::PASSWORD_HASH_PHP_DEFAULT,
33+
User::PASSWORD_HASH_INVALID,
3434
],
3535
$this->passwordHashService->getSupportedHashTypes()
3636
);

tests/lib/Repository/Values/User/UserTest.php

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,11 @@
1818
/**
1919
* @covers \Ibexa\Core\Repository\Values\User\User
2020
*/
21-
class UserTest extends TestCase
21+
final class UserTest extends TestCase
2222
{
2323
use ValueObjectTestTrait;
2424

25-
/**
26-
* Test a new class and default values on properties.
27-
*/
28-
public function testNewClass()
29-
{
30-
$user = new User();
31-
32-
$this->assertPropertiesCorrect(
33-
[
34-
'login' => null,
35-
'email' => null,
36-
'passwordHash' => null,
37-
'hashAlgorithm' => null,
38-
'maxLogin' => null,
39-
'enabled' => false,
40-
],
41-
$user
42-
);
43-
}
44-
45-
/**
46-
* Test getName method.
47-
*/
48-
public function testGetName()
25+
public function testGetName(): void
4926
{
5027
$name = 'Translated name';
5128
$contentMock = $this->createMock(Content::class);
@@ -64,10 +41,7 @@ public function testGetName()
6441
self::assertEquals($name, $object->getName());
6542
}
6643

67-
/**
68-
* Test retrieving missing property.
69-
*/
70-
public function testMissingProperty()
44+
public function testMissingProperty(): void
7145
{
7246
$this->expectException(PropertyNotFoundException::class);
7347

@@ -76,7 +50,7 @@ public function testMissingProperty()
7650
self::fail('Succeeded getting non existing property');
7751
}
7852

79-
public function testObjectProperties()
53+
public function testObjectProperties(): void
8054
{
8155
$object = new User();
8256
$properties = $object->attributes();
@@ -98,22 +72,7 @@ public function testObjectProperties()
9872
}
9973
}
10074

101-
/**
102-
* Test setting read only property.
103-
*/
104-
public function testReadOnlyProperty()
105-
{
106-
$this->expectException(PropertyReadOnlyException::class);
107-
108-
$user = new User();
109-
$user->login = 'user';
110-
self::fail('Succeeded setting read only property');
111-
}
112-
113-
/**
114-
* Test if property exists.
115-
*/
116-
public function testIsPropertySet()
75+
public function testIsPropertySet(): void
11776
{
11877
$user = new User();
11978
$value = isset($user->notDefined);
@@ -123,10 +82,7 @@ public function testIsPropertySet()
12382
self::assertTrue($value);
12483
}
12584

126-
/**
127-
* Test unsetting a property.
128-
*/
129-
public function testUnsetProperty()
85+
public function testUnsetProperty(): void
13086
{
13187
$this->expectException(PropertyReadOnlyException::class);
13288

0 commit comments

Comments
 (0)