-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from OpenConext/feature/allow-disabling-of-re…
…covery-tokens Add toggles to disable recovery token types
- Loading branch information
Showing
9 changed files
with
181 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
25 changes: 25 additions & 0 deletions
25
...erviceBundle/Service/SelfAssertedTokens/Exception/RecoveryTokenConfigurationException.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,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2022 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\Exception; | ||
|
||
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\RuntimeException; | ||
|
||
class RecoveryTokenConfigurationException extends RuntimeException | ||
{ | ||
} |
55 changes: 55 additions & 0 deletions
55
...et/StepupSelfService/SelfServiceBundle/Service/SelfAssertedTokens/RecoveryTokenConfig.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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright 2022 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens; | ||
|
||
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\Exception\RecoveryTokenConfigurationException; | ||
|
||
class RecoveryTokenConfig | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
private $smsEnabled; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $safeStoreCodeEnabled; | ||
|
||
public function __construct(bool $smsEnabled, bool $safeStoreCodeEnabled) | ||
{ | ||
if ($smsEnabled === false && $safeStoreCodeEnabled === false) { | ||
throw new RecoveryTokenConfigurationException('The SMS or safe-store code recovery token must be enabled'); | ||
} | ||
$this->smsEnabled = $smsEnabled; | ||
$this->safeStoreCodeEnabled = $safeStoreCodeEnabled; | ||
} | ||
|
||
public function isSmsDisabled(): bool | ||
{ | ||
return !$this->smsEnabled; | ||
} | ||
|
||
public function isSafeStoreCodeDisabled(): bool | ||
{ | ||
return !$this->safeStoreCodeEnabled; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...elfService/SelfServiceBundle/Tests/Service/SelfAssertedTokens/RecoveryTokenConfigTest.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,54 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2022 SURFnet bv | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Surfnet\StepupSelfService\SelfServiceBundle\Tests\Service\SelfAssertedTokens; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\Exception\RecoveryTokenConfigurationException; | ||
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\RecoveryTokenConfig; | ||
|
||
class RecoveryTokenConfigTest extends TestCase | ||
{ | ||
public function test_both_recovery_token_methods_can_be_enabled() | ||
{ | ||
$config = new RecoveryTokenConfig(true, true); | ||
self::assertFalse($config->isSafeStoreCodeDisabled()); | ||
self::assertFalse($config->isSmsDisabled()); | ||
} | ||
|
||
public function test_only_sms_can_be_enabled() | ||
{ | ||
$config = new RecoveryTokenConfig(true, false); | ||
self::assertTrue($config->isSafeStoreCodeDisabled()); | ||
self::assertFalse($config->isSmsDisabled()); | ||
} | ||
|
||
public function test_only_safe_store_can_be_enabled() | ||
{ | ||
$config = new RecoveryTokenConfig(false, true); | ||
self::assertFalse($config->isSafeStoreCodeDisabled()); | ||
self::assertTrue($config->isSmsDisabled()); | ||
} | ||
|
||
public function test_not_allowed_to_disable_both() | ||
{ | ||
self::expectException(RecoveryTokenConfigurationException::class); | ||
self::expectExceptionMessage('The SMS or safe-store code recovery token must be enabled'); | ||
new RecoveryTokenConfig(false, false); | ||
} | ||
} |