-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Security): Allow setting password context for validation and gen…
…eration Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Joas Schilling <213943+nickvergessen@users.noreply.github.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
- Loading branch information
1 parent
b36ced8
commit 3c51924
Showing
7 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCP\Security; | ||
|
||
/** | ||
* Define the context in which a password is used. | ||
* This allows setting a context for password validation and password generation. | ||
* | ||
* @package OCP\Security | ||
* @since 31.0.0 | ||
*/ | ||
enum PasswordContext: string { | ||
/** | ||
* Password used for an user account | ||
* @since 31.0.0 | ||
*/ | ||
case ACCOUNT = 'account'; | ||
|
||
/** | ||
* Password used for (public) shares | ||
* @since 31.0.0 | ||
*/ | ||
case SHARING = 'sharing'; | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/lib/Security/Events/GenerateSecurePasswordEventTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace Test\Security\Events; | ||
|
||
use OCP\Security\Events\GenerateSecurePasswordEvent; | ||
use OCP\Security\PasswordContext; | ||
|
||
class GenerateSecurePasswordEventTest extends \Test\TestCase { | ||
|
||
public function testDefaultProperties() { | ||
$event = new GenerateSecurePasswordEvent(); | ||
$this->assertNull($event->getPassword()); | ||
$this->assertEquals(PasswordContext::ACCOUNT, $event->getContext()); | ||
} | ||
|
||
public function testSettingPassword() { | ||
$event = new GenerateSecurePasswordEvent(); | ||
$event->setPassword('example'); | ||
$this->assertEquals('example', $event->getPassword()); | ||
} | ||
|
||
public function testSettingContext() { | ||
$event = new GenerateSecurePasswordEvent(PasswordContext::SHARING); | ||
$this->assertEquals(PasswordContext::SHARING, $event->getContext()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/lib/Security/Events/ValidatePasswordPolicyEventTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace Test\Security\Events; | ||
|
||
use OCP\Security\Events\ValidatePasswordPolicyEvent; | ||
use OCP\Security\PasswordContext; | ||
|
||
class ValidatePasswordPolicyEventTest extends \Test\TestCase { | ||
|
||
public function testDefaultProperties() { | ||
$password = 'example'; | ||
$event = new ValidatePasswordPolicyEvent($password); | ||
$this->assertEquals($password, $event->getPassword()); | ||
$this->assertEquals(PasswordContext::ACCOUNT, $event->getContext()); | ||
} | ||
|
||
public function testSettingContext() { | ||
$event = new ValidatePasswordPolicyEvent('example', PasswordContext::SHARING); | ||
$this->assertEquals(PasswordContext::SHARING, $event->getContext()); | ||
} | ||
} |