Skip to content

Commit 2267fc8

Browse files
committed
Francisco review
1 parent 2b84f00 commit 2267fc8

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/java/org/apache/cassandra/service/snapshot/SnapshotOptions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,11 @@ private void validateTag(String tag)
250250
// The remaining S3-safe characters (! * ' ( )) are intentionally excluded as they are
251251
// shell-significant and error-prone in paths, and the path separator '/' is excluded too,
252252
// which is what blocks traversal attempts such as "../../mysnapshot"
253-
if (!SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotName).matches())
253+
if (type == SnapshotType.USER && !SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotName).matches())
254254
{
255-
throw new IllegalArgumentException("Snapshot name contains illegal characters: " + resolvedSnapshotName);
255+
throw new IllegalArgumentException("Snapshot name contains illegal characters: " + resolvedSnapshotName + ". " +
256+
"Allowed characters must match the pattern: " + SAFE_SNAPSHOT_NAME.pattern() +
257+
" with a maximum of length of " + FILENAME_LENGTH + " characters.");
256258
}
257259
}
258260

test/unit/org/apache/cassandra/service/snapshot/SnapshotOptionsTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,24 @@ public void testSnapshotNameValidation()
7474
// The shell-significant S3 "safe" characters (! * ' ( )) are deliberately NOT allowed.
7575
assertThatThrownBy(() -> validate("important!", USER))
7676
.isInstanceOf(IllegalArgumentException.class)
77-
.hasMessage("Snapshot name contains illegal characters: important!");
77+
.hasMessageContaining("Snapshot name contains illegal characters: important!");
7878
assertThatThrownBy(() -> validate("backup*", USER))
7979
.isInstanceOf(IllegalArgumentException.class)
80-
.hasMessage("Snapshot name contains illegal characters: backup*");
80+
.hasMessageContaining("Snapshot name contains illegal characters: backup*");
8181
assertThatThrownBy(() -> validate("o'snap", USER))
8282
.isInstanceOf(IllegalArgumentException.class)
83-
.hasMessage("Snapshot name contains illegal characters: o'snap");
83+
.hasMessageContaining("Snapshot name contains illegal characters: o'snap");
8484
assertThatThrownBy(() -> validate("snap(1)", USER))
8585
.isInstanceOf(IllegalArgumentException.class)
86-
.hasMessage("Snapshot name contains illegal characters: snap(1)");
86+
.hasMessageContaining("Snapshot name contains illegal characters: snap(1)");
8787

8888
// Other characters outside the allowed set must still be rejected.
8989
assertThatThrownBy(() -> validate("a tag", USER))
9090
.isInstanceOf(IllegalArgumentException.class)
91-
.hasMessage("Snapshot name contains illegal characters: a tag");
91+
.hasMessageContaining("Snapshot name contains illegal characters: a tag");
9292
assertThatThrownBy(() -> validate("a:tag", USER))
9393
.isInstanceOf(IllegalArgumentException.class)
94-
.hasMessage("Snapshot name contains illegal characters: a:tag");
94+
.hasMessageContaining("Snapshot name contains illegal characters: a:tag");
9595

9696
// "." and ".." pass the charset check but resolve to the snapshots/ dir itself
9797
// and its parent (the live table dir) respectively, so they must be rejected as reserved.
@@ -102,6 +102,14 @@ public void testSnapshotNameValidation()
102102
assertThatThrownBy(() -> validate("..", USER))
103103
.isInstanceOf(IllegalArgumentException.class)
104104
.hasMessage("Snapshot name '..' is reserved");
105+
106+
// snapshot name contains "+" which might be present in a Cassandra version
107+
// the usage of "+" is forbidden for USER snapshots
108+
validate("this_is_system_snapshot-7.0.0+abc123", SnapshotType.UPGRADE);
109+
110+
assertThatThrownBy(() -> validate("this_is_snapshot-7.0.0+abc123", USER))
111+
.isInstanceOf(IllegalArgumentException.class)
112+
.hasMessageContaining("Snapshot name contains illegal characters: this_is_snapshot-7.0.0+abc123");
105113
}
106114

107115
try (WithProperties p = new WithProperties().set(CassandraRelevantProperties.SNAPSHOT_NAME_VALIDATION, false))

0 commit comments

Comments
 (0)