Search in sources :

Example 76 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class TestAuthorizationRules method testCanCommitButNotUpdateOrDeleteEntity.

@Test
// test_user2 has all permissions on a Branch, but not permissions on a Key
@TestSecurity(user = "test_user2")
void testCanCommitButNotUpdateOrDeleteEntity() throws BaseNessieClientServerException {
    String role = "test_user2";
    ContentKey key = ContentKey.of("allowed", "some");
    String branchName = "allowedBranchForTestUser2";
    createBranch(Branch.of(branchName, null), role, false);
    listAllReferences(branchName, false);
    final Branch branch = retrieveBranch(branchName, role, false);
    assertThatThrownBy(() -> api().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("add stuff")).operation(Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, "cid-foo"))).commit()).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(String.format("'UPDATE_ENTITY' is not allowed for role '%s' on content '%s'", role, key.toPathString()));
    readContent(branchName, key, role, true);
    final Branch b = retrieveBranch(branchName, role, false);
    assertThatThrownBy(() -> api().commitMultipleOperations().branch(b).commitMeta(CommitMeta.fromMessage("delete stuff")).operation(Delete.of(key)).commit()).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(String.format("'DELETE_ENTITY' is not allowed for role '%s' on content '%s'", role, key.toPathString()));
    deleteBranch(branch, role, false);
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) NessieForbiddenException(org.projectnessie.error.NessieForbiddenException) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 77 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class TestAuthorizationRules method testAllOps.

private void testAllOps(String branchName, String role, boolean shouldFail) throws BaseNessieClientServerException {
    boolean isAdmin = role.equals("admin_user");
    ContentKey key = ContentKey.of("allowed", "x");
    if (shouldFail) {
        branchName = "disallowedBranchForTestUser";
        key = ContentKey.of("disallowed", "x");
    }
    createBranch(Branch.of(branchName, null), role, shouldFail);
    Branch branchWithInvalidHash = Branch.of(branchName, "1234567890123456");
    Branch branch = shouldFail ? branchWithInvalidHash : retrieveBranch(branchName, role, shouldFail);
    listAllReferences(branchName, shouldFail);
    String cid = "cid-foo-" + UUID.randomUUID();
    addContent(branch, Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, cid)), role, shouldFail);
    if (!shouldFail) {
        // These requests cannot succeed, because "disallowedBranchForTestUser" could not be created
        getCommitLog(branchName, role, shouldFail);
        getEntriesFor(branchName, role, shouldFail);
        readContent(branchName, key, role, shouldFail);
    }
    branch = shouldFail ? branchWithInvalidHash : retrieveBranch(branchName, role, shouldFail);
    deleteContent(branch, Delete.of(key), role, shouldFail);
    branch = shouldFail ? branchWithInvalidHash : retrieveBranch(branchName, role, shouldFail);
    deleteBranch(branch, role, shouldFail);
    getRefLog(role, !isAdmin);
    Branch defaultBranch = api().getDefaultBranch();
    deleteBranch(defaultBranch, role, !isAdmin);
    if (isAdmin) {
        // need to recreate the default branch, so the test can continue normally
        api().createReference().reference(Branch.of(defaultBranch.getName(), null)).create();
    }
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch)

Example 78 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class TestAuthorizationRules method testCanReadTargetBranchDuringTransplant.

@Test
@TestSecurity(user = "admin_user")
void testCanReadTargetBranchDuringTransplant() throws BaseNessieClientServerException {
    String role = "admin_user";
    String branchName = "adminCanReadWhenTransplanting";
    String targetBranchName = "targetBranchForTransplant";
    createBranch(Branch.of(branchName, null), role, false);
    Branch branch = retrieveBranch(branchName, role, false);
    createBranch(Branch.of(targetBranchName, null), role, false);
    Branch targetBranch = retrieveBranch(targetBranchName, role, false);
    addContent(branch, Put.of(ContentKey.of("allowed", "x"), IcebergTable.of("foo", 42, 42, 42, 42, UUID.randomUUID().toString())), role, false);
    branch = retrieveBranch(branchName, role, false);
    api().transplantCommitsIntoBranch().fromRefName(branch.getName()).hashesToTransplant(api().getCommitLog().reference(branch).get().getLogEntries().stream().map(e -> e.getCommitMeta().getHash()).collect(Collectors.toList())).branch(targetBranch).transplant();
    targetBranch = retrieveBranch(targetBranch.getName(), role, false);
    assertThat(api().getCommitLog().reference(targetBranch).get().getLogEntries()).isNotEmpty();
}
Also used : Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 79 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class TestAuthorizationRules method testCanReadTargetBranchDuringAssign.

@Test
@TestSecurity(user = "admin_user")
void testCanReadTargetBranchDuringAssign() throws BaseNessieClientServerException {
    String role = "admin_user";
    String branchName = "adminCanReadWhenAssigning";
    String targetBranchName = "targetBranchForAssign";
    createBranch(Branch.of(branchName, null), role, false);
    Branch branch = retrieveBranch(branchName, role, false);
    createBranch(Branch.of(targetBranchName, null), role, false);
    Branch targetBranch = retrieveBranch(targetBranchName, role, false);
    addContent(targetBranch, Put.of(ContentKey.of("allowed", "x"), IcebergTable.of("foo", 42, 42, 42, 42, UUID.randomUUID().toString())), role, false);
    targetBranch = retrieveBranch(targetBranchName, role, false);
    api().assignBranch().branch(branch).assignTo(targetBranch).assign();
    branch = retrieveBranch(branchName, role, false);
    assertThat(branch.getHash()).isEqualTo(targetBranch.getHash());
}
Also used : Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 80 with Branch

use of org.projectnessie.model.Branch in project nessie by projectnessie.

the class NessieViewOperations method drop.

@Override
public void drop(String viewIdentifier) {
    reference.checkMutable();
    IcebergView existingView = view(toCatalogTableIdentifier(viewIdentifier));
    if (existingView == null) {
        return;
    }
    CommitMultipleOperationsBuilder commitBuilderBase = api.commitMultipleOperations().commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg delete view %s", viewIdentifier), catalogOptions)).operation(Operation.Delete.of(NessieUtil.toKey(toCatalogTableIdentifier(viewIdentifier))));
    // We try to drop the view. Simple retry after ref update.
    try {
        Tasks.foreach(commitBuilderBase).retry(5).stopRetryOn(NessieNotFoundException.class).throwFailureWhenFinished().onFailure((o, exception) -> refresh()).run(commitBuilder -> {
            Branch branch = commitBuilder.branch(reference.getAsBranch()).commit();
            reference.updateReference(branch);
        }, BaseNessieClientServerException.class);
    } catch (NessieConflictException e) {
        LOG.error("Cannot drop view: failed after retry (update ref and retry)", e);
    } catch (NessieNotFoundException e) {
        LOG.error("Cannot drop view: ref is no longer valid.", e);
    } catch (BaseNessieClientServerException e) {
        LOG.error("Cannot drop view: unknown error", e);
    }
}
Also used : ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) CommitStateUnknownException(org.apache.iceberg.exceptions.CommitStateUnknownException) LoggerFactory(org.slf4j.LoggerFactory) HttpClientException(org.projectnessie.client.http.HttpClientException) NessieConflictException(org.projectnessie.error.NessieConflictException) ViewVersionMetadata(org.apache.iceberg.view.ViewVersionMetadata) ImmutableCommitMeta(org.projectnessie.model.ImmutableCommitMeta) Map(java.util.Map) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) Content(org.projectnessie.model.Content) CommitFailedException(org.apache.iceberg.exceptions.CommitFailedException) Operation(org.projectnessie.model.Operation) Logger(org.slf4j.Logger) TableIdentifier(org.apache.iceberg.catalog.TableIdentifier) Predicate(java.util.function.Predicate) Branch(org.projectnessie.model.Branch) NessieApiV1(org.projectnessie.client.api.NessieApiV1) IcebergView(org.projectnessie.model.IcebergView) Tasks(org.apache.iceberg.util.Tasks) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) ViewUtils.toCatalogTableIdentifier(org.apache.iceberg.view.ViewUtils.toCatalogTableIdentifier) FileIO(org.apache.iceberg.io.FileIO) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) BaseMetastoreViewOperations(org.apache.iceberg.view.BaseMetastoreViewOperations) CommitMultipleOperationsBuilder(org.projectnessie.client.api.CommitMultipleOperationsBuilder) Branch(org.projectnessie.model.Branch) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) NessieConflictException(org.projectnessie.error.NessieConflictException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException)

Aggregations

Branch (org.projectnessie.model.Branch)81 Test (org.junit.jupiter.api.Test)56 IcebergTable (org.projectnessie.model.IcebergTable)30 ContentKey (org.projectnessie.model.ContentKey)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 LogResponse (org.projectnessie.model.LogResponse)19 Reference (org.projectnessie.model.Reference)19 CommitMeta (org.projectnessie.model.CommitMeta)18 Instant (java.time.Instant)16 LogEntry (org.projectnessie.model.LogResponse.LogEntry)13 List (java.util.List)12 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Tag (org.projectnessie.model.Tag)12 Collectors (java.util.stream.Collectors)11 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)11 Content (org.projectnessie.model.Content)11 Entry (org.projectnessie.model.EntriesResponse.Entry)10 Put (org.projectnessie.model.Operation.Put)10 IcebergView (org.projectnessie.model.IcebergView)9 Map (java.util.Map)8