-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-auth-server): added test for online_access scope implementa…
…tion #3012
- Loading branch information
Showing
3 changed files
with
105 additions
and
2 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
102 changes: 102 additions & 0 deletions
102
jans-auth-server/server/src/test/java/io/jans/as/server/service/GrantServiceTest.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,102 @@ | ||
package io.jans.as.server.service; | ||
|
||
import io.jans.as.model.config.StaticConfiguration; | ||
import io.jans.as.model.configuration.AppConfiguration; | ||
import io.jans.as.server.model.ldap.TokenEntity; | ||
import io.jans.as.server.model.ldap.TokenType; | ||
import io.jans.orm.PersistenceEntryManager; | ||
import io.jans.service.CacheService; | ||
import io.jans.service.cache.CacheConfiguration; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.slf4j.Logger; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
@Listeners(MockitoTestNGListener.class) | ||
public class GrantServiceTest { | ||
|
||
@InjectMocks | ||
private GrantService grantService; | ||
|
||
@Mock | ||
private Logger log; | ||
|
||
@Mock | ||
private PersistenceEntryManager persistenceEntryManager; | ||
|
||
@Mock | ||
private ClientService clientService; | ||
|
||
@Mock | ||
private CacheService cacheService; | ||
|
||
@Mock | ||
private StaticConfiguration staticConfiguration; | ||
|
||
@Mock | ||
private AppConfiguration appConfiguration; | ||
|
||
@Mock | ||
private CacheConfiguration cacheConfiguration; | ||
|
||
@Test | ||
public void filterOutRefreshTokenFromDeletion_forTokenWithoutOnlineAccess_shouldFilterOut() { | ||
Mockito.doReturn(false).when(appConfiguration).getRemoveRefreshTokensForClientOnLogout(); | ||
|
||
TokenEntity token = new TokenEntity(); | ||
token.setTokenTypeEnum(TokenType.REFRESH_TOKEN); | ||
token.getAttributes().setOnlineAccess(false); | ||
|
||
List<TokenEntity> tokens = new ArrayList<>(); | ||
tokens.add(token); | ||
|
||
grantService.filterOutRefreshTokenFromDeletion(tokens); | ||
assertTrue(tokens.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void filterOutRefreshTokenFromDeletion_forTokenWithOnlineAccess_shouldNotFilterOut() { | ||
Mockito.doReturn(false).when(appConfiguration).getRemoveRefreshTokensForClientOnLogout(); | ||
|
||
TokenEntity token = new TokenEntity(); | ||
token.setTokenTypeEnum(TokenType.REFRESH_TOKEN); | ||
token.getAttributes().setOnlineAccess(true); | ||
|
||
List<TokenEntity> tokens = new ArrayList<>(); | ||
tokens.add(token); | ||
|
||
grantService.filterOutRefreshTokenFromDeletion(tokens); | ||
assertFalse(tokens.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void filterOutRefreshTokenFromDeletion_whenConfigurationRemoveRefreshTokensForClientOnLogoutIsTrue_shouldNotFilterOut() { | ||
Mockito.doReturn(true).when(appConfiguration).getRemoveRefreshTokensForClientOnLogout(); | ||
|
||
TokenEntity token = new TokenEntity(); | ||
token.setTokenTypeEnum(TokenType.REFRESH_TOKEN); | ||
token.getAttributes().setOnlineAccess(false); | ||
|
||
TokenEntity another = new TokenEntity(); | ||
another.setTokenTypeEnum(TokenType.REFRESH_TOKEN); | ||
another.getAttributes().setOnlineAccess(true); | ||
|
||
List<TokenEntity> tokens = new ArrayList<>(); | ||
tokens.add(token); | ||
tokens.add(another); | ||
|
||
grantService.filterOutRefreshTokenFromDeletion(tokens); | ||
assertEquals(tokens.size(), 2); | ||
} | ||
} |
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