Skip to content

Commit

Permalink
Test validity
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Nov 16, 2023
1 parent 21aaf09 commit e28d7b5
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/test/java/oidc/secure/ResourceCleanerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import oidc.AbstractIntegrationTest;
import oidc.SeedUtils;
import oidc.endpoints.OidcEndpoint;
import oidc.model.AccessToken;
import oidc.model.AuthenticationRequest;
import oidc.model.AuthorizationCode;
import oidc.model.OpenIDClient;
import oidc.model.RefreshToken;
import oidc.model.User;
import oidc.model.UserConsent;
import oidc.repository.AccessTokenRepository;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -20,14 +22,12 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.UUID;
import java.util.*;
import java.util.stream.Stream;

import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {
Expand All @@ -36,11 +36,14 @@
"cron.node-cron-job-responsible=true"
})
@SuppressWarnings("unchecked")
public class ResourceCleanerTest extends AbstractIntegrationTest implements SeedUtils {
public class ResourceCleanerTest extends AbstractIntegrationTest implements SeedUtils, OidcEndpoint {

@Autowired
private ResourceCleaner subject;

@Autowired
private AccessTokenRepository accessTokenRepository;

@Test
public void clean() throws URISyntaxException {
Class[] classes = {User.class, UserConsent.class, AccessToken.class, RefreshToken.class, AuthorizationCode.class, AuthenticationRequest.class};
Expand All @@ -62,6 +65,26 @@ public void clean() throws URISyntaxException {
Stream.of(classes).forEach(clazz -> assertEquals(0, mongoTemplate.findAll(clazz).size()));
}

@Test
public void cleanEagerNegative() {
String jwtId = UUID.randomUUID().toString();
coCleanEager(jwtId, -5, false);
}

@Test
public void cleanEagerPositive() {
String jwtId = UUID.randomUUID().toString();
coCleanEager(jwtId, 15, true);
}

private void coCleanEager(String jwtId, int validity, boolean present) {
AccessToken accessToken = accessToken(jwtId, tokenValidity(validity));
accessTokenRepository.insert(accessToken);
subject.clean();
Optional<AccessToken> optionalAccessToken = accessTokenRepository.findByJwtId(jwtId);
assertEquals(present, optionalAccessToken.isPresent());
}

private UserConsent userConsent() {
UserConsent userConsent = new UserConsent(new User("sub", "unspecifiedNameId", "http://mockidp",
"clientId", Collections.emptyMap(), Collections.emptyList()), Arrays.asList("openid", "profile"), new OpenIDClient());
Expand Down

0 comments on commit e28d7b5

Please sign in to comment.