use of org.projectnessie.model.Detached in project nessie by projectnessie.
the class AbstractRestAccessCheckDetached method detachedRefAccessChecks.
@Test
public void detachedRefAccessChecks(@NessieAccessChecker Consumer<Function<AccessContext, BatchAccessChecker>> accessCheckerConsumer) throws Exception {
accessCheckerConsumer.accept(x -> newAccessChecker());
Branch main = createBranch("committerAndAuthor");
Branch merge = createBranch("committerAndAuthorMerge");
Branch transplant = createBranch("committerAndAuthorTransplant");
IcebergTable meta1 = IcebergTable.of("meep", 42, 42, 42, 42);
ContentKey key = ContentKey.of("meep");
Branch mainCommit = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("no security context").build()).operation(Put.of(key, meta1)).commit();
Branch detachedAsBranch = Branch.of(Detached.REF_NAME, mainCommit.getHash());
Tag detachedAsTag = Tag.of(Detached.REF_NAME, mainCommit.getHash());
Detached detached = Detached.of(mainCommit.getHash());
assertThat(Stream.of(detached, detachedAsBranch, detachedAsTag)).allSatisfy(ref -> assertAll(() -> assertThatThrownBy(() -> getApi().getCommitLog().reference(ref).get()).describedAs("ref='%s', getCommitLog", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(COMMITS_MSG), () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().fromRef(ref).branch(merge).merge()).describedAs("ref='%s', mergeRefIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().fromRefName(ref.getName()).hashesToTransplant(singletonList(ref.getHash())).branch(transplant).transplant()).describedAs("ref='%s', transplantCommitsIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getEntries().reference(ref).get()).describedAs("ref='%s', getEntries", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(READ_MSG), () -> assertThatThrownBy(() -> getApi().getContent().reference(ref).key(key).get()).describedAs("ref='%s', getContent", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(ENTITIES_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(ref).toRef(main).get()).describedAs("ref='%s', getDiff1", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(main).toRef(ref).get()).describedAs("ref='%s', getDiff2", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG)));
}
Aggregations