Skip to content

Commit

Permalink
Add namespace validation for rename operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat committed Oct 31, 2023
1 parent e5457c6 commit 05eba77
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ as necessary. Empty sections will not end in the release notes.

### Fixes

- Add namespace validation for rename operation.

### Commits

## [0.73.0] Release (2023-10-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ private void commitAddPut(
// Check for a Delete-op in the same commit, representing a rename operation.
UUID expectedContentID = UUID.fromString(putValueId);
deletedKey = deleted.remove(expectedContentID);
// consider a content as new content for rename operation to consider for namespace validation
newContent.put(putKey, putValue);
}
if (storeKeyExists && putValueId == null && deleted.containsValue(storeKey)) {
// Check for a Delete-op with same key in the same commit, representing a re-add operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.projectnessie.error.ReferenceConflicts;
import org.projectnessie.model.Conflict;
import org.projectnessie.model.Content;
import org.projectnessie.model.ContentKey;
import org.projectnessie.model.Namespace;
import org.projectnessie.versioned.BranchName;
Expand Down Expand Up @@ -509,4 +510,33 @@ void deleteHierarchy() throws Exception {
.collect(Collectors.toList())))
.doesNotThrowAnyException();
}

@Test
void renameWithNonExistingNamespace() throws Exception {
BranchName branch = BranchName.of("renameWithNonExistingNamespace");
store().create(branch, Optional.empty());

ContentKey key1 = ContentKey.of("table");
ContentKey key2 = ContentKey.of(Namespace.of("non_existing"), "tbl");

store()
.commit(
branch,
Optional.empty(),
fromMessage("create a table"),
singletonList(Put.of(key1, newOnRef("value"))));

Content table = store().getValue(branch, key1).content();

soft.assertThatThrownBy(
() ->
store()
.commit(
branch,
Optional.empty(),
fromMessage("rename table"),
asList(Delete.of(key1), Put.of(key2, table))))
.isInstanceOf(ReferenceConflictException.class)
.hasMessage("Namespace 'non_existing' must exist.");
}
}

0 comments on commit 05eba77

Please sign in to comment.