|
4 | 4 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
5 | 5 | import hudson.util.Secret;
|
6 | 6 | import java.io.IOException;
|
| 7 | +import java.net.MalformedURLException; |
| 8 | + |
7 | 9 | import org.acegisecurity.AuthenticationManager;
|
8 | 10 | import org.acegisecurity.BadCredentialsException;
|
9 | 11 | import org.acegisecurity.GrantedAuthority;
|
|
16 | 18 |
|
17 | 19 | import static org.junit.Assert.assertEquals;
|
18 | 20 | import static org.junit.Assert.assertNotNull;
|
| 21 | +import static org.junit.Assert.assertThrows; |
19 | 22 |
|
20 | 23 | public class OicSecurityRealmTest {
|
21 | 24 |
|
@@ -83,4 +86,17 @@ public void testShouldSetNullClientSecretWhenSecretIsNone() throws IOException {
|
83 | 86 | .build();
|
84 | 87 | assertEquals("none", Secret.toString(realm.getClientSecret()));
|
85 | 88 | }
|
| 89 | + |
| 90 | + @Test |
| 91 | + public void testGetValidRedirectUrl() throws IOException { |
| 92 | + String rootUrl = "http://localhost:" + wireMockRule.port() + "/jenkins/"; |
| 93 | + |
| 94 | + TestRealm realm = new TestRealm.Builder(wireMockRule) |
| 95 | + .WithMinimalDefaults().build(); |
| 96 | + assertEquals(rootUrl + "foo", realm.getValidRedirectUrl("/foo")); |
| 97 | + assertEquals(rootUrl + "bar", realm.getValidRedirectUrl(rootUrl + "bar")); |
| 98 | + assertEquals(rootUrl, realm.getValidRedirectUrl(null)); |
| 99 | + assertEquals(rootUrl, realm.getValidRedirectUrl("")); |
| 100 | + assertThrows(MalformedURLException.class, () -> realm.getValidRedirectUrl("foobar")); |
| 101 | + } |
86 | 102 | }
|
0 commit comments