Skip to content

Commit

Permalink
tests for wildcard matches
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Mar 11, 2024
1 parent 06e1cf7 commit 51b64e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.github.danthe1st.httpsintercept.config.HostMatcherConfig;
import org.checkerframework.checker.nullness.qual.NonNull;

public final class HostMatcher<@NonNull T> {
public final class HostMatcher<T> {
private final Map<String, List<@NonNull T>> exactHosts;
private final Map<String, List<@NonNull T>> hostParts;
private final Map<Pattern, List<@NonNull T>> hostRegexes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,47 @@ void testNoMatchWithoutConfig() {
expectNoMatches(matcher, "example.com");
}

// TODO wildcard
@Test
void testWildcard() {
HostMatcher<Object> matcher = new HostMatcher<>(
List.of(
Map.entry(
new HostMatcherConfig(null, null, null), 1
)
), true
);
expectSingleMatch(matcher, "localhost");
expectSingleMatch(matcher, "");
}

void testWildcardAndNoWildcard() {
HostMatcher<Object> matcher = new HostMatcher<>(
List.of(
Map.entry(
new HostMatcherConfig(Set.of("example.com"), null, null), 1
),
Map.entry(
new HostMatcherConfig(null, null, null), 2
)
), true
);
expectMatches(matcher, "example.com", 1, 2);
expectMatches(matcher, "localhost", 2);
}

@Test
void testNoWildcardWithAllowedWildcard() {
HostMatcher<Object> matcher = new HostMatcher<>(
List.of(
Map.entry(
new HostMatcherConfig(Set.of("example.com"), null, null), 1
)
), true
);
expectSingleMatch(matcher, "example.com");
expectNoMatches(matcher, "localhost");
expectNoMatches(matcher, "");
}

private HostMatcher<Object> createMatcher(Set<String> exactHosts, Set<String> hostParts, Set<String> hostRegexes) {
return new HostMatcher<>(List.of(Map.entry(new HostMatcherConfig(exactHosts, hostParts, hostRegexes), 1)), false);
Expand Down

0 comments on commit 51b64e4

Please sign in to comment.