Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace validation for rename operation #7650

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.");
}
}