InterceptingBrowser extends Region implements ChangeListener<String> { static boolean matchesRedirection(final String expectedRedirectUriString, final String actualUriString) { if (actualUriString == null) { return false; } final URI actualUri = URI.create(actualUriString); final URI expectedUri = URI.create(expectedRedirectUriString); if (!StringHelper.equalIgnoringCase(expectedUri.getScheme(), actualUri.getScheme())) { return false; } if (!StringHelper.equalIgnoringCase(expectedUri.getHost(), actualUri.getHost())) { return false; } if (expectedUri.getPort() != actualUri.getPort()) { return false; } final String actualPath = actualUri.getPath(); final String expectedPath = expectedUri.getPath(); if (actualPath != null) { if (expectedPath == null) { return false; } if (!actualPath.startsWith(expectedPath)) { return false; } } else { if (expectedPath != null) { return false; } } if (actualUri.getScheme().equals("urn") && !actualUriString.startsWith(expectedRedirectUriString)) { return false; } return true; } InterceptingBrowser(); WebEngine getWebEngine(); @Override String toString(); @Override void changed(final ObservableValue<? extends String> observable, final String oldValue, final String newValue); void sendRequest(final URI destinationUri, final URI redirectUri); AuthorizationResponse waitForResponse(); void cancel();  }
@Test public void matchesRedirection_typical() throws Exception { final String redirectUriString = "https: final String actualUriString = "https: final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(true, actual); }
@Test public void matchesRedirection_hostIsCaseInsensitive() throws Exception { final String redirectUriString = "https: final String actualUriString = "https: final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(true, actual); }
@Test public void matchesRedirection_pathIsCaseSensitive() throws Exception { final String redirectUriString = "https: final String actualUriString = "https: final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(false, actual); }
@Test public void matchesRedirection_expectedContainsQuery() throws Exception { final String redirectUriString = "https: final String actualUriString = "https: final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(true, actual); }
@Test public void matchesRedirection_pathWithoutSlash() throws Exception { final String redirectUriString = "https: final String actualUriString = "https: final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(true, actual); }
@Test public void matchesRedirection_urnSchemeWithNativeAppRedirect() throws Exception { final String redirectUriString = "urn:ietf:wg:oauth:2.0:oob"; final String actualUriString = "urn:ietf:wg:oauth:2.0:oob?code=abc&stat=123"; final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(true, actual); }
@Test public void matchesRedirection_urnSchemeCaseSensitive() throws Exception { final String redirectUriString = "urn:ietf:wg:oauth:2.0:oob"; final String actualUriString = "urn:IETF:wg:oauth:2.0:oob?code=abc&stat=123"; final boolean actual = InterceptingBrowser.matchesRedirection(redirectUriString, actualUriString); Assert.assertEquals(false, actual); }