use of com.bakdata.conquery.models.auth.entities.User 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.auth.entities.User in project conquery by bakdata.
the class SerializationTests method user.
/*
* Only way to add permission without a storage.
*/
@Test
public void user() throws IOException, JSONException {
User user = new User("user", "user", STORAGE);
user.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("test")));
user.addPermission(ExecutionPermission.onInstance(Ability.READ, new ManagedExecutionId(new DatasetId("dataset"), UUID.randomUUID())));
Role role = new Role("company", "company", STORAGE);
user.addRole(role);
CentralRegistry registry = new CentralRegistry();
registry.register(role);
SerializationTestUtil.forType(User.class).registry(registry).injectables(STORAGE).test(user);
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class CopyUserTest method testUserCopy.
@Test
void testUserCopy() {
final DatasetRegistry registry = new DatasetRegistry(0);
MetaStorage storage = new NonPersistentStoreFactory().createMetaStorage();
registry.setMetaStorage(storage);
// Create test role
Role role = new Role("role", "role", storage);
storage.addRole(role);
role.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset0")));
// Create test group
Group group = new Group("group", "group", storage);
storage.addGroup(group);
group.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset1")));
// Create original user with role and group mapping
User originUser = new User("user", "user", storage);
storage.addUser(originUser);
originUser.addRole(role);
group.addMember(originUser);
// Do copy
User copy = AuthorizationController.flatCopyUser(originUser, "copytest", storage);
// Check that it is not the same user
assertThat(copy).usingRecursiveComparison().isNotEqualTo(originUser);
// Check that the copy does not have any mappings
assertThat(group.containsMember(copy)).isFalse();
assertThat(copy.getRoles()).isEmpty();
// Check that the flat map worked
assertThat(copy.getPermissions()).containsExactlyInAnyOrderElementsOf(originUser.getEffectivePermissions());
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class LocalAuthRealmTest method setupEach.
@BeforeEach
public void setupEach() {
// Create User in Realm
user1 = new User("TestUser", "Test User", storage);
PasswordCredential user1Password = new PasswordCredential("testPassword".toCharArray());
storage.addUser(user1);
realm.addUser(user1, List.of(user1Password));
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method verifyTokenInLeeway.
@Test
void verifyTokenInLeeway() {
// Setup the expected user id
User expected = new User("Test", "Test", STORAGE);
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).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThat(REALM.doGetAuthenticationInfo(accessToken).getPrincipals().getPrimaryPrincipal()).isEqualTo(expected);
}
Aggregations