diff --git a/CHANGELOG.md b/CHANGELOG.md index be07af59595..5b7b6658c58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/versioned/storage/store/src/main/java/org/projectnessie/versioned/storage/versionstore/CommitImpl.java b/versioned/storage/store/src/main/java/org/projectnessie/versioned/storage/versionstore/CommitImpl.java index 172c28f590e..324d42b7df1 100644 --- a/versioned/storage/store/src/main/java/org/projectnessie/versioned/storage/versionstore/CommitImpl.java +++ b/versioned/storage/store/src/main/java/org/projectnessie/versioned/storage/versionstore/CommitImpl.java @@ -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. diff --git a/versioned/tests/src/main/java/org/projectnessie/versioned/tests/AbstractNamespaceValidation.java b/versioned/tests/src/main/java/org/projectnessie/versioned/tests/AbstractNamespaceValidation.java index ccbab482dc9..cc091933941 100644 --- a/versioned/tests/src/main/java/org/projectnessie/versioned/tests/AbstractNamespaceValidation.java +++ b/versioned/tests/src/main/java/org/projectnessie/versioned/tests/AbstractNamespaceValidation.java @@ -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; @@ -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."); + } }