use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class SerializingStoreDumpTest method testCorruptKeyDump.
/**
* Tests if entries with corrupted keys are dumped.
*/
@Test
public void testCorruptKeyDump() throws IOException {
// Set dump directory to this tests temp-dir
config.setUnreadableDataDumpDirectory(tmpDir);
{
// 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);
}
{
// Open that store again, with a different config to insert a corrupt entry
// (String & ManagedQuery)
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);
}
{
// Reopen the store with the initial value 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(2);
expectedResult.setFailedKeys(1);
expectedResult.setFailedValues(0);
// Iterate (do nothing with the entries themselves)
IterationStatistic result = store.forEach((k, v, s) -> {
});
assertThat(result).isEqualTo(expectedResult);
}
// Test if the correct number of dumpfiles was generated
Condition<File> dumpFileCond = new Condition<>(f -> f.getName().endsWith(SerializingStore.DUMP_FILE_EXTENTION), "dump file");
assertThat(tmpDir.listFiles()).areExactly(1, dumpFileCond);
// Test if the dump is correct
File dumpFile = getDumpFile(dumpFileCond);
assertThat((QueryDescription) Jackson.MAPPER.readerFor(QueryDescription.class).readValue(dumpFile)).isEqualTo(cQuery);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class IntrospectionDelegatingRealmTest method tokenIntrospectionGroupedUser.
@Test
public void tokenIntrospectionGroupedUser() {
STORAGE.addUser(USER_2);
AuthenticationInfo info = REALM.doGetAuthenticationInfo(USER_2_TOKEN_WRAPPED);
final ConqueryAuthenticationInfo expected = new ConqueryAuthenticationInfo(USER_2, USER_2_TOKEN_WRAPPED, REALM, true);
assertThat(info).usingRecursiveComparison().isEqualTo(expected);
assertThat(STORAGE.getAllUsers()).containsOnly(USER_2);
// Pre-existing group and a second group that has been added in the process
assertThat(STORAGE.getAllGroups()).hasSize(2);
assertThat(STORAGE.getGroup(new GroupId(GROUPNAME_1)).getMembers()).contains(new UserId(USER_2_NAME));
assertThat(STORAGE.getGroup(new GroupId(GROUPNAME_2)).getMembers()).contains(new UserId(USER_2_NAME));
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenOutdated.
@Test
void falsifyTokenOutdated() {
// Setup the expected user id
UserId expected = new UserId("Test");
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, -2);
String token = JWT.create().withIssuer(HTTP_REALM_URL).withSubject(expected.getName()).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenWrongIssuer.
@Test
void falsifyTokenWrongIssuer() {
// 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("wrong_iss").withAudience(AUDIENCE).withSubject(expected.getName()).withIssuedAt(issueDate).withExpiresAt(expDate).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
use of com.bakdata.conquery.models.identifiable.ids.specific.UserId in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenWrongAudience.
@Test
void falsifyTokenWrongAudience() {
// 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("wrong_aud").withSubject(expected.getName()).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
Aggregations