Skip to content

Commit

Permalink
namespaces: allow '=' and ';' in names (#1936)
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
  • Loading branch information
mobuchowski authored Apr 7, 2022
1 parent b583633 commit ef063d7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/marquez/common/models/NamespaceName.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public final class NamespaceName {
private static final int MIN_SIZE = 1;
private static final int MAX_SIZE = 1024;
private static final Pattern PATTERN =
Pattern.compile(String.format("^[a-zA-Z:/0-9_\\-\\.]{%d,%d}$", MIN_SIZE, MAX_SIZE));
Pattern.compile(String.format("^[a-zA-Z:;=/0-9_\\-\\.]{%d,%d}$", MIN_SIZE, MAX_SIZE));

@Getter private final String value;

public NamespaceName(@NonNull final String value) {
checkArgument(
PATTERN.matcher(value).matches(),
"namespace '%s' must contain only letters (a-z, A-Z), numbers (0-9), "
+ "underscores (_), dashes (-), colons (:), slashes (/) or dots (.) with a maximum "
+ "length of %s characters.",
+ "underscores (_), dashes (-), colons (:), equals (=), semicolons (;), slashes (/) "
+ "or dots (.) with a maximum length of %s characters.",
value,
MAX_SIZE);
this.value = value;
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/java/marquez/OpenLineageIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static List<String> data() {

@Test
public void testSendOpenLineageBadArgument() throws IOException {
// Namespaces can't have semi-colons, so this will get rejected
// Namespaces can't have emojis, so this will get rejected
String badNamespace =
"sqlserver://myhost:3342;user=auser;password=XXXXXXXXXX;database=TheDatabase";
"sqlserver://myhost:3342;user=auser;password=\uD83D\uDE02\uD83D\uDE02\uD83D\uDE02;database=TheDatabase";
LineageEvent event =
new LineageEvent(
"COMPLETE",
Expand Down
31 changes: 31 additions & 0 deletions api/src/test/java/marquez/common/models/NamespaceNameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package marquez.common.models;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@org.junit.jupiter.api.Tag("UnitTests")
public class NamespaceNameTest {

@ParameterizedTest
@ValueSource(
strings = {
"DEFAULT",
"database://localhost:1234",
"s3://bucket",
"bigquery:",
"sqlserver://synapse-test-test001.sql.azuresynapse.net;databaseName=TESTPOOL1;",
"\u003D"
})
void testValidNamespaceName(String name) {
assertThat(NamespaceName.of(name).getValue()).isEqualTo(name);
}

@ParameterizedTest
@ValueSource(strings = {"@@@", "\uD83D\uDE02", "!", ""})
void testInvalidNamespaceName(String name) {
Assertions.assertThrows(IllegalArgumentException.class, () -> NamespaceName.of(name));
}
}

0 comments on commit ef063d7

Please sign in to comment.