-
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.
Create GW Inst Config if not present in projection
When the Gateway institution configuration is updated because the sso on 2fa config changed for that institution. The projection would only be updated if the institution already exists in the projection. If the projection did not yet have the institution, then the projection was not updated. This fix now creates the row if the projection is not yet present.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 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
79 changes: 79 additions & 0 deletions
79
.../StepupMiddleware/GatewayBundle/Tests/Projector/InstitutionConfigurationProjectorTest.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,79 @@ | ||
<?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\StepupMiddleware\GatewayBundle\Tests\Projector; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Rhumsaa\Uuid\Uuid; | ||
use Surfnet\Stepup\Configuration\Event\SsoOn2faOptionChangedEvent; | ||
use Surfnet\Stepup\Configuration\Value\Institution; | ||
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId; | ||
use Surfnet\Stepup\Configuration\Value\SsoOn2faOption; | ||
use Surfnet\StepupMiddleware\GatewayBundle\Entity\InstitutionConfiguration; | ||
use Surfnet\StepupMiddleware\GatewayBundle\Projector\InstitutionConfigurationProjector; | ||
use Surfnet\StepupMiddleware\GatewayBundle\Repository\InstitutionConfigurationRepository; | ||
|
||
class InstitutionConfigurationProjectorTest extends TestCase | ||
{ | ||
use m\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
|
||
private $projector; | ||
|
||
private $repository; | ||
protected function setUp(): void | ||
{ | ||
$repository = m::mock(InstitutionConfigurationRepository::class); | ||
$projector = new InstitutionConfigurationProjector($repository); | ||
$this->repository = $repository; | ||
$this->projector = $projector; | ||
} | ||
|
||
public function test_create_row_when_non_existent() | ||
{ | ||
$event = new SsoOn2faOptionChangedEvent( | ||
new InstitutionConfigurationId(Uuid::uuid4()->toString()), | ||
new Institution('institution-a.nl'), | ||
new SsoOn2faOption(true) | ||
); | ||
$this->repository->shouldReceive('findByInstitution')->with('institution-a.nl')->andReturn(null); | ||
$this->repository->shouldReceive('save')->withArgs(function(InstitutionConfiguration $configuration){ | ||
return $configuration->institution === 'institution-a.nl' && $configuration->ssoOn2faEnabled === true; | ||
}); | ||
|
||
$this->projector->applySsoOn2faOptionChangedEvent($event); | ||
} | ||
public function test_updates_existing_row() | ||
{ | ||
$event = new SsoOn2faOptionChangedEvent( | ||
new InstitutionConfigurationId(Uuid::uuid4()->toString()), | ||
new Institution('institution-a.nl'), | ||
new SsoOn2faOption(true) | ||
); | ||
$configuration = new InstitutionConfiguration('institution-a.nl', false); | ||
|
||
$this->repository->shouldReceive('findByInstitution')->with('institution-a.nl')->andReturn($configuration); | ||
$this->repository->shouldReceive('save')->withArgs(function(InstitutionConfiguration $configuration){ | ||
return $configuration->institution === 'institution-a.nl' && $configuration->ssoOn2faEnabled === true; | ||
}); | ||
|
||
$this->projector->applySsoOn2faOptionChangedEvent($event); | ||
} | ||
} |