Skip to content

Commit

Permalink
Add more tests for OicSecurityRealm#maybeOpenIdLogoutEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
eva-mueller-coremedia committed Dec 23, 2024
1 parent 2ed9d87 commit f77f277
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/test/java/org/jenkinsci/plugins/oic/OicSecurityRealmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import hudson.util.Secret;

import java.io.IOException;
import java.util.Map;
import java.util.Set;
import org.acegisecurity.AuthenticationManager;
Expand All @@ -23,6 +21,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class OicSecurityRealmTest {
Expand Down Expand Up @@ -159,6 +158,33 @@ public void testGetCustomLoginParameters() throws Exception {
}

@Test
@WithoutJenkins
public void testMaybeOpenIdLogoutEndpoint() throws Exception {
TestRealm realm = new TestRealm.Builder(wireMockRule)
.WithMinimalDefaults()
.WithLogout(Boolean.FALSE, "https://endpoint")
.build();
assertNull(realm.maybeOpenIdLogoutEndpoint("my-id-token", null, "https://localhost"));

realm = new TestRealm.Builder(wireMockRule)
.WithMinimalDefaults().WithLogout(Boolean.TRUE, null).build();
assertNull(realm.maybeOpenIdLogoutEndpoint("my-id-token", null, "https://localhost"));

realm = new TestRealm.Builder(wireMockRule)
.WithMinimalDefaults().WithLogout(Boolean.FALSE, null).build();
assertNull(realm.maybeOpenIdLogoutEndpoint("my-id-token", null, "https://localhost"));

realm = new TestRealm.Builder(wireMockRule)
.WithMinimalDefaults()
.WithLogout(Boolean.TRUE, "https://endpoint?query-param-1=test")
.build();
assertEquals(
"https://endpoint?query-param-1=test&id_token_hint=my-id-token&post_logout_redirect_uri=https%3A%2F%2Flocalhost",
realm.maybeOpenIdLogoutEndpoint("my-id-token", null, "https://localhost"));
}

@Test
@WithoutJenkins
public void testMaybeOpenIdLogoutEndpointWithNoCustomLogoutQueryParameters() throws Exception {
TestRealm realm = new TestRealm.Builder(wireMockRule)
.WithMinimalDefaults().WithLogout(true, "https://endpoint").build();
Expand All @@ -171,17 +197,20 @@ public void testMaybeOpenIdLogoutEndpointWithNoCustomLogoutQueryParameters() thr
assertEquals(
"https://endpoint?id_token_hint=my-id-token&state=test&post_logout_redirect_uri=https%3A%2F%2Flocalhost",
realm.maybeOpenIdLogoutEndpoint("my-id-token", "test", "https://localhost"));
assertEquals("https://endpoint", realm.maybeOpenIdLogoutEndpoint(null, null, null));
}

@Test
@WithoutJenkins
public void testMaybeOpenIdLogoutEndpointWithCustomLogoutQueryParameters() throws Exception {
TestRealm realm = new TestRealm.Builder(wireMockRule)
.WithMinimalDefaults()
.WithLogoutQueryParameters(
"key1=value1&=drop-me&key2 = with-spaces &param-only&id_token_hint=overwrite-test-1&post_logout_redirect_uri=overwrite-test-2&state=overwrite-test-3")
"key1=value1&=drop-me&key2 = with-spaces &&param-only&id_token_hint=overwrite-test-1&post_logout_redirect_uri=overwrite-test-2&state=overwrite-test-3")
.WithLogout(true, "https://endpoint")
.build();
String result = realm.maybeOpenIdLogoutEndpoint("my-id-token", "test", "https://localhost");
assertNotNull(result);
assertFalse(result.contains("drop-me"));
assertFalse(result.contains("overwrite-test"));
assertEquals(
Expand All @@ -192,9 +221,9 @@ public void testMaybeOpenIdLogoutEndpointWithCustomLogoutQueryParameters() throw
@Test
@WithoutJenkins
public void testEncodeIfUrl() throws Exception {
TestRealm realm = new TestRealm.Builder(wireMockRule).build();
assertEquals("https%3A%2F%2Fwww.test.de", realm.encodeIfUrl("https://www.test.de"));
assertEquals("http%3A%2F%2Fwww.test.de", realm.encodeIfUrl("http://www.test.de"));
assertEquals("not-an-url", realm.encodeIfUrl("not-an-url"));
TestRealm realm = new TestRealm.Builder(wireMockRule).build();
assertEquals("https%3A%2F%2Fwww.test.de", realm.encodeIfUrl("https://www.test.de"));
assertEquals("http%3A%2F%2Fwww.test.de", realm.encodeIfUrl("http://www.test.de"));
assertEquals("not-an-url", realm.encodeIfUrl("not-an-url"));
}
}

0 comments on commit f77f277

Please sign in to comment.