summaryrefslogtreecommitdiffstats
path: root/security-utils/src/test/java/com/yahoo/security/tls/UriGlobPatternTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'security-utils/src/test/java/com/yahoo/security/tls/UriGlobPatternTest.java')
-rw-r--r--security-utils/src/test/java/com/yahoo/security/tls/UriGlobPatternTest.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/security-utils/src/test/java/com/yahoo/security/tls/UriGlobPatternTest.java b/security-utils/src/test/java/com/yahoo/security/tls/UriGlobPatternTest.java
new file mode 100644
index 00000000000..4d89d71cf85
--- /dev/null
+++ b/security-utils/src/test/java/com/yahoo/security/tls/UriGlobPatternTest.java
@@ -0,0 +1,37 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.security.tls;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * @author bjorncs
+ */
+class UriGlobPatternTest {
+
+ @Test
+ void matches_correctly() {
+ assertMatches("scheme://hostname/*", "scheme://hostname/mypath");
+ assertMatches("scheme://hostname/*/segment2", "scheme://hostname/segment1/segment2");
+ assertMatches("scheme://hostname/segment1/*", "scheme://hostname/segment1/segment2");
+ assertNotMatches("scheme://hostname/*", "scheme://hostname/segment1/segment2");
+ assertMatches("scheme://*/segment1/segment2", "scheme://hostname/segment1/segment2");
+ assertMatches("scheme://*.name/", "scheme://host.name/");
+ assertNotMatches("scheme://*", "scheme://hostname/");
+ assertMatches("scheme://hostname/mypath?query=value", "scheme://hostname/mypath?query=value");
+ assertNotMatches("scheme://hostname/?", "scheme://hostname/p");
+ }
+
+ private void assertMatches(String pattern, String value) {
+ assertTrue(new UriGlobPattern(pattern).matches(value),
+ () -> String.format("Expected '%s' to match '%s'", pattern, value));
+ }
+
+ private void assertNotMatches(String pattern, String value) {
+ assertFalse(new UriGlobPattern(pattern).matches(value),
+ () -> String.format("Expected '%s' to not match '%s'", pattern, value));
+ }
+
+}