Search in sources :

Example 16 with User

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Validators(io.dropwizard.jersey.validation.Validators) Environments(jetbrains.exodus.env.Environments) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) StoreMappings(com.bakdata.conquery.io.storage.StoreMappings) Environment(jetbrains.exodus.env.Environment) Files(com.google.common.io.Files) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) Validator(javax.validation.Validator) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) User(com.bakdata.conquery.models.auth.entities.User) File(java.io.File) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Slf4j(lombok.extern.slf4j.Slf4j) AfterEach(org.junit.jupiter.api.AfterEach) Condition(org.assertj.core.api.Condition) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) Jackson(com.bakdata.conquery.io.jackson.Jackson) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Condition(org.assertj.core.api.Condition) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) IterationStatistic(com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 17 with User

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);
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) User(com.bakdata.conquery.models.auth.entities.User) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 18 with 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());
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Group(com.bakdata.conquery.models.auth.entities.Group) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) Test(org.junit.jupiter.api.Test)

Example 19 with User

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));
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) PasswordCredential(com.bakdata.conquery.apiv1.auth.PasswordCredential) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with User

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);
}
Also used : User(com.bakdata.conquery.models.auth.entities.User) BearerToken(org.apache.shiro.authc.BearerToken) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.bakdata.conquery.models.auth.entities.User)49 Test (org.junit.jupiter.api.Test)17 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)14 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)14 Dataset (com.bakdata.conquery.models.datasets.Dataset)11 UserId (com.bakdata.conquery.models.identifiable.ids.specific.UserId)10 Group (com.bakdata.conquery.models.auth.entities.Group)8 Role (com.bakdata.conquery.models.auth.entities.Role)8 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)8 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)7 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)5 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)5 ConqueryAuthenticationInfo (com.bakdata.conquery.models.auth.ConqueryAuthenticationInfo)5 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ConqueryPermission (com.bakdata.conquery.models.auth.permissions.ConqueryPermission)4 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Query (com.bakdata.conquery.apiv1.query.Query)3 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)3