use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method verifyTokenAlternativeId.
@Test
void verifyTokenAlternativeId() {
// Setup the expected user id
User expected = new User("Test", "Test", STORAGE);
STORAGE.updateUser(expected);
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, 1);
final String primId = UUID.randomUUID().toString();
String token = JWT.create().withIssuer(HTTP_REALM_URL).withAudience(AUDIENCE).withSubject(primId).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).withClaim(ALTERNATIVE_ID_CLAIM, expected.getName()).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThat(REALM.doGetAuthenticationInfo(accessToken).getPrincipals().getPrimaryPrincipal()).isEqualTo(expected);
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class PermissionCleanupTaskTest method doDeletePermissionsOfOwnedReference.
@Test
void doDeletePermissionsOfOwnedReference() {
assertThat(STORAGE.getAllExecutions()).isEmpty();
// Created owned execution
final ManagedQuery managedQueryOwned = createManagedQuery();
// Setup user
User user = new User("test", "test", STORAGE);
User user2 = new User("test2", "test2", STORAGE);
STORAGE.updateUser(user);
user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQueryOwned.getId()));
managedQueryOwned.setOwner(user);
STORAGE.updateExecution(managedQueryOwned);
// Created not owned execution
final ManagedQuery managedQueryNotOwned = createManagedQuery();
// Setup user
user.addPermission(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
// Set owner
managedQueryNotOwned.setOwner(user2);
STORAGE.updateExecution(managedQueryNotOwned);
deletePermissionsOfOwnedInstances(STORAGE, ExecutionPermission.DOMAIN.toLowerCase(), ManagedExecutionId.Parser.INSTANCE, STORAGE::getExecution);
assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class PermissionCleanupTaskTest method doDeletePartialPermissionWithInvalidReference.
@Test
void doDeletePartialPermissionWithInvalidReference() {
assertThat(STORAGE.getAllExecutions()).isEmpty();
final ManagedQuery managedQuery1 = createManagedQuery();
final ManagedQuery managedQuery2 = createManagedQuery();
// Removing the second execution
STORAGE.removeExecution(managedQuery2.getId());
User user = new User("test", "test", STORAGE);
STORAGE.updateUser(user);
user.addPermission(// Build a permission with multiple instances
new WildcardPermission(List.of(Set.of(ExecutionPermission.DOMAIN), Set.of(Ability.READ.toString().toLowerCase()), Set.of(managedQuery1.getId().toString(), managedQuery2.getId().toString())), Instant.now()));
deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQuery1.getId()));
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class PermissionCleanupTaskTest method doDeletePermissionInvalidReference.
@Test
void doDeletePermissionInvalidReference() {
assertThat(STORAGE.getAllExecutions()).isEmpty();
final ManagedQuery managedQuery = createManagedQuery();
// Removing the execution
STORAGE.removeExecution(managedQuery.getId());
User user = new User("test", "test", STORAGE);
STORAGE.updateUser(user);
user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQuery.getId()));
deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
assertThat(user.getPermissions()).isEmpty();
}
use of com.bakdata.conquery.models.auth.entities.User in project conquery by bakdata.
the class IdRefrenceTest method testListReferences.
@Test
public void testListReferences() throws IOException {
CentralRegistry registry = new CentralRegistry();
Dataset dataset = new Dataset();
dataset.setName("dataset");
Table table = new Table();
table.setDataset(dataset);
table.setName("table");
registry.register(dataset);
registry.register(table);
final CentralRegistry metaRegistry = new CentralRegistry();
User user = new User("usermail", "userlabel", mock(MetaStorage.class));
metaRegistry.register(user);
String json = Jackson.MAPPER.writeValueAsString(new ListHolder(Collections.singletonList(table), Collections.singletonList(user)));
assertThat(json).contains("\"user.usermail\"").contains("\"dataset.table\"");
ListHolder holder = new SingletonNamespaceCollection(registry, metaRegistry).injectIntoNew(Jackson.MAPPER.readerFor(ListHolder.class)).readValue(json);
assertThat(holder.getUsers().get(0)).isSameAs(user);
assertThat(holder.getTables().get(0)).isSameAs(table);
}
Aggregations