Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,10 @@ private static boolean matchServer(String server, String name) {
int off = server.length() - tail.length();
if (off < 1)
return false;
// if tail matches and is preceeded by "."
// the wildcard matches a single leftmost label only, so the
// tail must be preceeded by "." with no earlier "." in server
return server.charAt(off - 1) == '.' &&
server.lastIndexOf('.', off - 2) < 0 &&
server.regionMatches(true, off, tail, 0, tail.length());
} else {
return server.equalsIgnoreCase(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ public final class SocketFetcherTest {
@Rule
public Timeout deadlockTimeout = Timeout.seconds(20);

private static boolean matchServer(String server, String name)
throws Exception {
Class<?> c = Class.forName(
"org.eclipse.angus.mail.util.SocketFetcher$MailHostnameVerifier");
java.lang.reflect.Method m =
c.getDeclaredMethod("matchServer", String.class, String.class);
m.setAccessible(true);
return (Boolean) m.invoke(null, server, name);
}

/**
* A wildcard certificate name matches a single leftmost label only.
*/
@Test
public void testWildcardMatchesSingleLabel() throws Exception {
assertTrue(matchServer("foo.example.com", "*.example.com"));
assertTrue(matchServer("FOO.EXAMPLE.COM", "*.example.com"));
assertFalse(matchServer("a.b.example.com", "*.example.com"));
assertFalse(matchServer("example.com", "*.example.com"));
assertTrue(matchServer("example.com", "example.com"));
}

/**
* Test connecting with proxy host and port.
*/
Expand Down