mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-11 17:52:15 +01:00
Add password check to users.destroy and organizations.destroy
This commit is contained in:
committed by
Constantin Graf
parent
24c94af952
commit
6a197f7f34
@@ -649,7 +649,9 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
Passport::actingAs($otherData->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', $data->user->getKey()));
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', $data->user->getKey()), [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertForbidden();
|
||||
@@ -674,13 +676,15 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', 'not-valid'));
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', 'not-valid'), [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_delete_removes_user(): void
|
||||
public function test_delete_fails_without_password(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
@@ -689,6 +693,40 @@ class UserEndpointTest extends ApiEndpointTestAbstract
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', $data->user->getKey()));
|
||||
|
||||
// Assert
|
||||
$response->assertUnprocessable();
|
||||
$response->assertJsonValidationErrors(['password']);
|
||||
$this->assertDatabaseHas(User::class, ['id' => $data->user->getKey()]);
|
||||
}
|
||||
|
||||
public function test_delete_fails_with_wrong_password(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', $data->user->getKey()), [
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertUnprocessable();
|
||||
$response->assertJsonValidationErrors(['password']);
|
||||
$this->assertDatabaseHas(User::class, ['id' => $data->user->getKey()]);
|
||||
}
|
||||
|
||||
public function test_delete_removes_user(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->deleteJson(route('api.v1.users.destroy', $data->user->getKey()), [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing(User::class, ['id' => $data->user->getKey()]);
|
||||
|
||||
Reference in New Issue
Block a user