RealmContextFilterTest.java revision 16682c615640da7d54591f86528a5eb562e0ab97
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
public class RealmContextFilterTest {
private RealmContextFilter filter;
@Mock
private CoreWrapper coreWrapper;
@Mock
private RestRealmValidator realmValidator;
@Mock
@SuppressWarnings("unchecked")
initMocks(this);
.willThrow(IdRepoException.class);
}
@Test
public void filterShouldConsumeRealmFromRequest() throws Exception {
//Given
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithDnsAlias() throws Exception {
//Given
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithInvalidDnsAlias() throws Exception {
//Given
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithUriRealm() throws Exception {
//Given
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithUriRealmAlias() throws Exception {
//Given
//When
//Then
}
@Test
public void filterShouldFailToConsumeRealmFromRequestWithInvalidUriRealm() throws Exception {
//Given
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndUriRealm() throws Exception {
//Given
mockRealmAlias("/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM, "/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM);
//When
//Then
}
@Test
public void filterShouldFailToConsumeRealmFromRequestWithDnsAliasAndUriRealmAlias() throws Exception {
//Given
mockRealmAlias("/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM_ALIAS, "/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM);
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithOverrideRealm() throws Exception {
//Given
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM + "/");
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithOverrideRealmAlias() throws Exception {
//Given
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM_ALIAS);
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm() throws Exception {
//Given
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + INVALID_OVERRIDE_REALM);
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndOverrideRealm() throws Exception {
//Given
Request request = createRequest(DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithUriRealmAndOverrideRealm() throws Exception {
//Given
Request request = createRequest(HOSTNAME, SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithUriRealmAliasAndOverrideRealm() throws Exception {
//Given
Request request = createRequest(HOSTNAME, SUB_REALM_ALIAS + "/" + ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
//When
//Then
}
@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndUriRealmAndOverrideRealm() throws Exception {
//Given
Request request = createRequest(DNS_ALIAS_HOSTNAME, SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
mockRealmAlias("/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM, "/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM);
//When
//Then
verifyRealmContext(contextCaptor.getValue(), "/" + DNS_ALIS_SUB_REALM, "/" + SUB_REALM, OVERRIDE_REALM);
}
@Test
public void filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName() throws Exception {
//Given
//When
//Then
}
return new UriRouterContext(new RootContext(), JSON_PATH_ELEMENT, remainingUri, EMPTY_VARIABLE_MAP);
}
}
}
}
}
}
if (expectedDnsAliasRealm.isEmpty()) {
} else {
}
assertThat(realmContext.getRelativeRealm()).isEqualTo(expectedRelativeRealm.isEmpty() ? "/" : expectedRelativeRealm);
if (expectedOverrideRealm == null) {
assertThat(realmContext.getResolvedRealm()).isEqualTo(expectedDnsAliasRealm + expectedRelativeRealm);
} else {
}
}
if (matchedUri.isEmpty()) {
} else {
}
}
}
private void verifyInvalidRealmResponse(Response response, String expectedInvalidRealm) throws IOException {
}
}