Skip to content

Commit 0a9a75b

Browse files
committed
Ensure deprovisioning non existing identities is handled gracefully
This adds test coverage for the logging of a notice when a non-existing identity is deprovisioned.
1 parent 3a93c9d commit 0a9a75b

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

src/Surfnet/Stepup/Tests/Helper/UserDataFormatterTest.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public function test_errors_are_included_in_output(): void
5757
['name' => 'name1', 'value' => 'some-value-1'],
5858
],
5959
'name' => 'Stepup-Middleware',
60-
'message' => [
61-
'The application is teetering on the edge of catastrophe!',
62-
],
60+
'message' => ['The application is teetering on the edge of catastrophe!'],
6361
];
6462

6563
$inputData = [
@@ -74,4 +72,29 @@ public function test_errors_are_included_in_output(): void
7472
),
7573
);
7674
}
75+
76+
public function test_multiple_errors_result_in_one_errormessage(): void
77+
{
78+
$formatter = new UserDataFormatter('Stepup-Middleware');
79+
$expected = [
80+
'status' => 'FAILED',
81+
'data' => [
82+
['name' => 'name1', 'value' => 'some-value-1'],
83+
],
84+
'name' => 'Stepup-Middleware',
85+
'message' => ['The application is teetering on the edge of catastrophe!', 'This and that is wrong.']
86+
];
87+
88+
$inputData = [
89+
'foobar-name1' => 'some-value-1',
90+
];
91+
92+
$this->assertEquals(
93+
$expected,
94+
$formatter->format(
95+
$inputData,
96+
['The application is teetering on the edge of catastrophe!', 'This and that is wrong.'],
97+
),
98+
);
99+
}
77100
}

src/Surfnet/StepupMiddleware/ApiBundle/Tests/Service/DeprovisionServiceTest.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp(): void
6262

6363
$logger = m::mock(LoggerInterface::class);
6464
$logger->shouldIgnoreMissing(); // Not going to verify every log message at this point
65-
$this->deprovisionService = new DeprovisionService($this->pipeline, $this->eventRepo, $this->apiRepo, $logger, $this->sraaRepo, $this->raListingRepo);
65+
$this->deprovisionService = $this->buildDeprovisionService($logger);
6666
}
6767

6868
public function test_it_can_be_created(): void
@@ -112,6 +112,50 @@ public function test_deprovision_does_not_deprovision_when_user_is_not_found():
112112
$this->deprovisionService->deprovision('urn:collab:person:example.com:maynard_keenan');
113113
}
114114

115+
#[Group('api-bundle')]
116+
public function test_deprovision_logs_unknown_identity_when_not_found(): void
117+
{
118+
$logger = m::mock(LoggerInterface::class);
119+
$logger->shouldReceive('debug')->once();
120+
$logger->shouldReceive('notice')
121+
->once()
122+
->with(m::on(static fn(string $message): bool => str_contains($message, 'was not found')));
123+
124+
$deprovisionService = $this->buildDeprovisionService($logger);
125+
126+
$this->apiRepo
127+
->shouldReceive('findOneByNameId')
128+
->with('urn:collab:person:example.com:unknown_user')
129+
->once()
130+
->andReturnNull();
131+
132+
$this->pipeline->shouldNotReceive('process');
133+
134+
$deprovisionService->deprovision('urn:collab:person:example.com:unknown_user');
135+
}
136+
137+
#[Group('api-bundle')]
138+
public function test_read_user_data_returns_empty_array_for_unknown_identity(): void
139+
{
140+
$logger = m::mock(LoggerInterface::class);
141+
$logger->shouldReceive('debug')->once();
142+
$logger->shouldReceive('notice')
143+
->once()
144+
->with(m::on(static fn(string $message): bool => str_contains($message, 'was not found')));
145+
146+
$deprovisionService = $this->buildDeprovisionService($logger);
147+
148+
$this->apiRepo
149+
->shouldReceive('findOneByNameId')
150+
->with('urn:collab:person:example.com:unknown_user')
151+
->once()
152+
->andReturnNull();
153+
154+
$result = $deprovisionService->readUserData('urn:collab:person:example.com:unknown_user');
155+
156+
$this->assertEmpty($result);
157+
}
158+
115159
public function test_deprovision_method_performs_the_right_to_be_forgotten_command(): void
116160
{
117161
$identity = m::mock(Identity::class);
@@ -162,4 +206,16 @@ public function test_is_allowed_to_deprovision_user(): void
162206

163207
$this->deprovisionService->assertIsAllowed($nameId);
164208
}
209+
210+
private function buildDeprovisionService(LoggerInterface $logger): DeprovisionService
211+
{
212+
return new DeprovisionService(
213+
$this->pipeline,
214+
$this->eventRepo,
215+
$this->apiRepo,
216+
$logger,
217+
$this->sraaRepo,
218+
$this->raListingRepo
219+
);
220+
}
165221
}

0 commit comments

Comments
 (0)