-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a Yubikey test double in test + smoketest envs
This now works around the actual yubikey api interaction. Passing every input as a valid OTP. Be carefull! Use responsibile. This feature is only enabled for test and smoketest.
- Loading branch information
Showing
6 changed files
with
120 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Use this service definition file to override services and parameters in the test environment. | ||
# For example to mock certain services, or override a parameter for test. | ||
|
||
services: | ||
surfnet_stepup.service.sms_second_factor: | ||
class: Surfnet\StepupBundle\Tests\TestDouble\Service\SmsSecondFactorService | ||
arguments: | ||
- "@surfnet_stepup.service.challenge_handler" | ||
|
||
ra.service.yubikey_second_factor: | ||
public: true | ||
class: Surfnet\StepupRa\RaBundle\Tests\TestDouble\Service\YubikeySecondFactorService | ||
arguments: | ||
- "@logger" | ||
|
||
|
||
# The middleware client bundle guzzle client is overloaded to be able to pass the testcookie to the ensure MW is | ||
# loaded in test mode. This way people setting the testcookie in prod will not switch their mw api into testmode | ||
# resulting in 500 errors. | ||
surfnet_stepup_middleware_client.guzzle.api: | ||
public: false | ||
class: GuzzleHttp\Client | ||
factory: ['Surfnet\StepupRa\RaBundle\Tests\TestDouble\Factory\GuzzleApiFactory', createApiGuzzleClient] | ||
arguments: | ||
- "%middleware_url_api%" | ||
- "%middleware_credentials_username%" | ||
- "secret" | ||
|
||
surfnet_stepup_middleware_client.guzzle.commands: | ||
public: false | ||
class: GuzzleHttp\Client | ||
factory: ['Surfnet\StepupRa\RaBundle\Tests\TestDouble\Factory\GuzzleApiFactory', createCommandGuzzleClient] | ||
arguments: | ||
- "%middleware_url_command_api%" |
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
27 changes: 27 additions & 0 deletions
27
src/Surfnet/StepupRa/RaBundle/Service/YubikeySecondFactorServiceInterface.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,27 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 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\StepupRa\RaBundle\Service; | ||
|
||
use Surfnet\StepupRa\RaBundle\Command\VerifyYubikeyPublicIdCommand; | ||
use Surfnet\StepupRa\RaBundle\Service\YubikeySecondFactor\VerificationResult; | ||
|
||
interface YubikeySecondFactorServiceInterface | ||
{ | ||
public function verifyYubikeyPublicId(VerifyYubikeyPublicIdCommand $command): VerificationResult; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Surfnet/StepupRa/RaBundle/Tests/TestDouble/Service/YubikeySecondFactorService.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,48 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright 2024 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\StepupRa\RaBundle\Tests\TestDouble\Service; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Cookie\CookieJar; | ||
use Psr\Log\LoggerInterface; | ||
use Surfnet\StepupBundle\Value\YubikeyOtp; | ||
use Surfnet\StepupBundle\Value\YubikeyPublicId; | ||
use Surfnet\StepupRa\RaBundle\Command\VerifyYubikeyOtpCommand; | ||
use Surfnet\StepupRa\RaBundle\Command\VerifyYubikeyPublicIdCommand; | ||
use Surfnet\StepupRa\RaBundle\Service\YubikeySecondFactor\VerificationResult; | ||
use Surfnet\StepupRa\RaBundle\Service\YubikeySecondFactorServiceInterface; | ||
|
||
class YubikeySecondFactorService implements YubikeySecondFactorServiceInterface | ||
{ | ||
private $logger; | ||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
public function verifyYubikeyPublicId(VerifyYubikeyPublicIdCommand $command): VerificationResult | ||
{ | ||
$this->logger->critical( | ||
'Using the TestDouble yubikey YubikeySecondFactorService::verifyYubikeyPublicId method. '. | ||
'Always returns a positive result. Be careful, only to use this during test or development!' | ||
); | ||
$publicId = new YubikeyPublicId('09999999'); | ||
return new VerificationResult(VerificationResult::RESULT_PUBLIC_ID_MATCHED, $publicId); | ||
} | ||
} |