use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class SerializingStoreDumpTest method testCorruptionRemoval.
/**
* Tests if entries with corrupted are removed from the store if configured so.
* The dump itself is not testet.
*/
@Test
public void testCorruptionRemoval() {
log.info("This test will throw some warnings from the SerializingStore.");
// Set config to remove corrupt entries
config.setRemoveUnreadableFromStore(true);
{
// Open a store and insert a valid key-value pair (UserId & User)
SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
store.add(new UserId("testU1"), user);
}
{
// Insert two corrupt entries. One with a corrupt key and the other one with a
// corrupt value
{
SerializingStore<String, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), String.class, QueryDescription.class));
store.add("not a valid conquery Id", cQuery);
}
{
SerializingStore<UserId, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), UserId.class, QueryDescription.class));
store.add(new UserId("testU2"), cQuery);
}
}
{
// Reopen the store with correct configuration and try to iterate over all
// entries (this triggers the dump or removal of invalid entries)
SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
IterationStatistic expectedResult = new IterationStatistic();
expectedResult.setTotalProcessed(3);
expectedResult.setFailedKeys(1);
expectedResult.setFailedValues(1);
// Iterate (do nothing with the entries themselves)
IterationStatistic result = store.forEach((k, v, s) -> {
});
assertThat(result).isEqualTo(expectedResult);
}
{
// Reopen again to check that the corrupted values have been removed previously
SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
IterationStatistic expectedResult = new IterationStatistic();
expectedResult.setTotalProcessed(1);
expectedResult.setFailedKeys(0);
expectedResult.setFailedValues(0);
// Iterate (do nothing with the entries themselves)
IterationStatistic result = store.forEach((k, v, s) -> {
});
assertThat(result).isEqualTo(expectedResult);
}
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class SerializationTests method testApiTokenData.
@Test
public void testApiTokenData() throws JSONException, IOException {
final CharArrayBuffer buffer = new CharArrayBuffer(5);
buffer.append("testtest");
final ApiToken apiToken = new ApiToken(buffer);
final ApiTokenData apiTokenData = new ApiTokenData(UUID.randomUUID(), apiToken.hashToken(), "tokenName", new UserId("tokenUser"), LocalDate.now(), LocalDate.now().plus(1, ChronoUnit.DAYS), EnumSet.of(Scopes.DATASET), STORAGE);
SerializationTestUtil.forType(ApiTokenData.class).injectables(STORAGE).test(apiTokenData);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class IntrospectionDelegatingRealmTest method tokenIntrospectionGroupedUserRemoveGroupMapping.
@Test
public void tokenIntrospectionGroupedUserRemoveGroupMapping() {
STORAGE.addUser(USER_3);
GROUP_1_EXISTING.addMember(USER_3);
assertThat(STORAGE.getGroup(new GroupId(GROUPNAME_1)).getMembers()).contains(new UserId(USER_3_NAME));
AuthenticationInfo info = REALM.doGetAuthenticationInfo(USER_3_TOKEN_WRAPPED);
assertThat(info).usingRecursiveComparison().ignoringFields(ConqueryAuthenticationInfo.Fields.credentials).isEqualTo(new ConqueryAuthenticationInfo(USER_3, USER_3_TOKEN_WRAPPED, REALM, true));
assertThat(STORAGE.getAllUsers()).containsOnly(USER_3);
// Pre-existing group
assertThat(STORAGE.getAllGroups()).hasSize(1);
assertThat(STORAGE.getGroup(new GroupId(GROUPNAME_1)).getMembers()).doesNotContain(new UserId(USER_3_NAME));
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenMissingCustomClaim.
@Test
void falsifyTokenMissingCustomClaim() {
// Setup the expected user id
UserId expected = new UserId("Test");
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, 1);
String token = JWT.create().withIssuer(HTTP_REALM_URL).withAudience(AUDIENCE).withSubject(expected.getName()).withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
Aggregations