Add rest resource for api keys

This commit is contained in:
René Pfeuffer
2020-09-29 11:08:36 +02:00
parent 4129f55f27
commit 905fc4158a
18 changed files with 401 additions and 38 deletions

View File

@@ -49,12 +49,14 @@ import static org.mockito.Mockito.when;
class ApiKeyServiceTest {
int nextKey = 1;
int nextId = 1;
PasswordService passwordService = mock(PasswordService.class);
Supplier<String> keyGenerator = () -> Integer.toString(nextKey++);
Supplier<String> passphraseGenerator = () -> Integer.toString(nextKey++);
KeyGenerator keyGenerator = () -> Integer.toString(nextId++);
ConfigurationEntryStoreFactory storeFactory = new InMemoryConfigurationEntryStoreFactory();
ConfigurationEntryStore<ApiKeyCollection> store = storeFactory.withType(ApiKeyCollection.class).withName("apiKeys").build();
ApiKeyService service = new ApiKeyService(storeFactory, passwordService, keyGenerator);
ApiKeyService service = new ApiKeyService(storeFactory, passwordService, keyGenerator, passphraseGenerator);
@BeforeEach
@@ -128,7 +130,7 @@ class ApiKeyServiceTest {
assertThat(service.check("dent", "1", firstKey)).contains("READ");
assertThat(service.check("dent", "2", secondKey)).contains("WRITE");
assertThat(service.getKeys()).extracting("name").contains("1", "2");
assertThat(service.getKeys()).extracting("id").contains("1", "2");
}
@Test