Add created date to api key

This commit is contained in:
René Pfeuffer
2020-10-01 13:01:23 +02:00
parent 1def884779
commit 20345c895f
6 changed files with 30 additions and 7 deletions

View File

@@ -53,12 +53,12 @@ import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import static com.google.inject.util.Providers.of;
import static java.time.Instant.now;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
@@ -229,7 +229,10 @@ public class MeResourceTest {
@Test
public void shouldGetAllApiKeys() throws URISyntaxException, UnsupportedEncodingException {
when(apiKeyService.getKeys()).thenReturn(Arrays.asList(new ApiKey("1", "key 1", "READ"), new ApiKey("2", "key 2", "WRITE")));
when(apiKeyService.getKeys())
.thenReturn(asList(
new ApiKey("1", "key 1", "READ", now()),
new ApiKey("2", "key 2", "WRITE", now())));
MockHttpRequest request = MockHttpRequest.get("/" + MeResource.ME_PATH_V2 + "api_keys");
dispatcher.invoke(request, response);
@@ -244,7 +247,10 @@ public class MeResourceTest {
@Test
public void shouldGetSingleApiKey() throws URISyntaxException, UnsupportedEncodingException {
when(apiKeyService.getKeys()).thenReturn(Arrays.asList(new ApiKey("1", "key 1", "READ"), new ApiKey("2", "key 2", "WRITE")));
when(apiKeyService.getKeys())
.thenReturn(asList(
new ApiKey("1", "key 1", "READ", now()),
new ApiKey("2", "key 2", "WRITE", now())));
MockHttpRequest request = MockHttpRequest.get("/" + MeResource.ME_PATH_V2 + "api_keys/1");
dispatcher.invoke(request, response);

View File

@@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test;
import java.util.Optional;
import static java.time.Instant.now;
import static org.assertj.core.api.Assertions.assertThat;
class ApiKeyTokenHandlerTest {
@@ -37,7 +38,7 @@ class ApiKeyTokenHandlerTest {
@Test
void shouldSerializeAndDeserializeToken() {
final String tokenString = handler.createToken("dent", new ApiKey("42", "hg2g", "READ"), "some secret");
final String tokenString = handler.createToken("dent", new ApiKey("42", "hg2g", "READ", now()), "some secret");
System.out.println(tokenString);