Skip to content

Commit 6d7bb4d

Browse files
committed
Test that user with dedicated feature can delete other users
1 parent fa5f874 commit 6d7bb4d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/UsersTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,45 @@ public function testRemoveNonExistingUser()
277277
$this->expectException(ClientException::class);
278278
$this->client->removeUser($email);
279279
}
280+
281+
public function testNormalUserCanDeleteUserWhenHavingFeature()
282+
{
283+
$featureName = 'can-manage-users';
284+
285+
$token = $this->normalUserClient->verifyToken();
286+
$this->assertArrayHasKey('user', $token);
287+
$userId = $token['user']['id'];
288+
289+
$this->client->removeUserFeature($userId, $featureName);
290+
291+
$organization = $this->client->createOrganization($this->testMaintainerId, ['name' => 'ToRemoveOrg-1']);
292+
$project = $this->client->createProject($organization['id'], [
293+
'name' => 'ToRemoveProj-1',
294+
'dataRetentionTimeInDays' => 1,
295+
]);
296+
$email = 'devel-tests+remove' . uniqid() . '@keboola.com';
297+
298+
$this->client->addUserToProject($project['id'], ['email' => $email]);
299+
$newUser = $this->client->getUser($email);
300+
301+
try {
302+
// Remove user by normal user without feature
303+
$this->normalUserClient->removeUser($newUser['id']);
304+
$this->fail('Normal user cannot delete user');
305+
} catch (ClientException $e) {
306+
$this->assertEquals(403, $e->getCode());
307+
$this->assertEquals('accessDenied', $e->getStringCode());
308+
}
309+
310+
// Add feature to normal user
311+
$this->client->addUserFeature($userId, $featureName);
312+
313+
// now normal user should be able to delete user
314+
$this->normalUserClient->removeUser($newUser['id']);
315+
$deletedUser = $this->client->getUser($newUser['id']);
316+
317+
$this->assertSame('DELETED', $deletedUser['email'], 'User e-mail has not been deleted');
318+
$this->assertSame(false, $deletedUser['mfaEnabled'], 'User mfa has not been disabled');
319+
$this->assertSame('DELETED', $deletedUser['name'], 'User name has not been deleted');
320+
}
280321
}

0 commit comments

Comments
 (0)