Skip to content

Commit 3b583ed

Browse files
committed
Add tests for user logouts when user is removed
1 parent 129ef9e commit 3b583ed

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

features/bootstrap/DoctrineContext.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,16 @@ public function theIsAComponentInARouteWithPath(string $resource, string $path):
828828
$this->manager->flush();
829829
}
830830

831+
/**
832+
* @Given The resource :name is removed
833+
*/
834+
public function theUserUsernameIsRemoved(string $name): void
835+
{
836+
$resource = $this->iriConverter->getResourceFromIri($this->restContext->resources[$name]);
837+
$this->manager->remove($resource);
838+
$this->manager->flush();
839+
}
840+
831841
/**
832842
* @Given /I have a refresh token(?: which expires at "([^"]*)"|)?$/
833843
*/

features/user/security.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ Feature: Prevent disabled users from logging in
107107
| Get |
108108
| Post |
109109

110+
@loginUser
111+
Scenario: I can logout even if I have no refresh token
112+
When I send a "POST" request to "/logout"
113+
Then the response status code should be 200
114+
And 1 refresh tokens should exist
115+
And all the refresh tokens should be expired
116+
And the response should have a "api_components" cookie
117+
And the response should have a "api_components" cookie with max age less than 2
118+
And the response should have a "api_components" cookie with the value "x.x.x"
119+
And the response should have a "mercureAuthorization" cookie
120+
And the mercure cookie should not contain draft resource topics
121+
122+
@loginUser
123+
Scenario: I can logout even if the user has been deleted while logged in
124+
Given the resource "login_user" is removed
125+
When I send a "POST" request to "/logout"
126+
Then the response status code should be 200
127+
And 0 refresh tokens should exist
128+
And the response should have a "api_components" cookie
129+
And the response should have a "api_components" cookie with max age less than 2
130+
And the response should have a "api_components" cookie with the value "x.x.x"
131+
And the response should have a "mercureAuthorization" cookie
132+
And the mercure cookie should not contain draft resource topics
133+
110134
@loginUser
111135
Scenario: JWT tokens that are invalid should be removed from a user's cookie store in the response headers
112136
Given I have an invalid JWT token

tests/Functional/TestBundle/Entity/RefreshToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
class RefreshToken extends AbstractRefreshToken
2525
{
2626
#[ORM\ManyToOne(targetEntity: User::class)]
27-
#[ORM\JoinColumn(nullable: false)]
27+
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
2828
protected ?UserInterface $user = null;
2929
}

0 commit comments

Comments
 (0)