-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
antonio.torre
committed
Jun 6, 2024
1 parent
673e71e
commit 3273092
Showing
6 changed files
with
92 additions
and
7 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
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
14 changes: 13 additions & 1 deletion
14
src/main/java/it/gov/pagopa/payhub/auth/service/logout/LogoutServiceImpl.java
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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
package it.gov.pagopa.payhub.auth.service.logout; | ||
|
||
import it.gov.pagopa.payhub.auth.service.TokenStoreService; | ||
import it.gov.pagopa.payhub.auth.service.exchange.ValidateExternalTokenService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class LogoutServiceImpl implements LogoutService { | ||
|
||
private final ValidateExternalTokenService validateExternalTokenService; | ||
private final TokenStoreService tokenStoreService; | ||
|
||
public LogoutServiceImpl(ValidateExternalTokenService validateExternalTokenService, TokenStoreService tokenStoreService) { | ||
this.validateExternalTokenService = validateExternalTokenService; | ||
this.tokenStoreService = tokenStoreService; | ||
} | ||
|
||
@Override | ||
public void logout(String clientId, String token) { | ||
// TODO | ||
validateExternalTokenService.validateClient(clientId); | ||
tokenStoreService.delete(token); | ||
} | ||
} |
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
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
57 changes: 57 additions & 0 deletions
57
src/test/java/it/gov/pagopa/payhub/auth/service/logout/LogoutServiceTest.java
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,57 @@ | ||
package it.gov.pagopa.payhub.auth.service.logout; | ||
|
||
import it.gov.pagopa.payhub.auth.exception.custom.InvalidExchangeClientException; | ||
import it.gov.pagopa.payhub.auth.service.TokenStoreService; | ||
import it.gov.pagopa.payhub.auth.service.exchange.ValidateExternalTokenService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class LogoutServiceTest { | ||
|
||
@Mock | ||
private ValidateExternalTokenService validateExternalTokenServiceMock; | ||
@Mock | ||
private TokenStoreService tokenStoreServiceMock; | ||
|
||
private LogoutService service; | ||
|
||
@BeforeEach | ||
void init(){ | ||
service = new LogoutServiceImpl(validateExternalTokenServiceMock, tokenStoreServiceMock); | ||
} | ||
|
||
@Test | ||
void givenInvalidClientIdWhenLogoutThenInvalidClientException(){ | ||
// Given | ||
String clientId = "clientId"; | ||
String token = "token"; | ||
|
||
InvalidExchangeClientException expectedException = new InvalidExchangeClientException(""); | ||
Mockito.doThrow(expectedException) | ||
.when(validateExternalTokenServiceMock).validateClient(clientId); | ||
|
||
// When, Then | ||
InvalidExchangeClientException exception = Assertions.assertThrows(InvalidExchangeClientException.class, () -> service.logout(clientId, token)); | ||
Assertions.assertSame(expectedException, exception); | ||
} | ||
|
||
@Test | ||
void givenCompleteRequestWhenLogoutThenOk(){ | ||
// Given | ||
String clientId = "clientId"; | ||
String token = "token"; | ||
|
||
// When | ||
service.logout(clientId, token); | ||
|
||
// Then | ||
Mockito.verify(validateExternalTokenServiceMock).validateClient(clientId); | ||
Mockito.verify(tokenStoreServiceMock).delete(token); | ||
} | ||
} |