Updated Third Party Issuer Service unit tests.
parent
8c8aeeb892
commit
0e777917d3
|
@ -28,6 +28,8 @@ import org.mitre.openid.connect.client.model.IssuerServiceResponse;
|
|||
import org.mockito.Mockito;
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* @author wkim
|
||||
*
|
||||
|
@ -36,62 +38,91 @@ public class TestThirdPartyIssuerService {
|
|||
|
||||
// Test fixture:
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
private String iss = "https://server.example.org";
|
||||
private String login_hint = "I'm not telling you nothin!";
|
||||
private String target_link_uri = "https://www.example.com";
|
||||
private String redirect_uri = "https://www.example.com";
|
||||
|
||||
|
||||
private String accountChooserUrl = "https://www.example.com/account";
|
||||
|
||||
|
||||
private ThirdPartyIssuerService service = new ThirdPartyIssuerService();
|
||||
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
|
||||
|
||||
service.setAccountChooserUrl(accountChooserUrl);
|
||||
|
||||
|
||||
request = Mockito.mock(HttpServletRequest.class);
|
||||
Mockito.when(request.getParameter("iss")).thenReturn(iss);
|
||||
Mockito.when(request.getParameter("login_hint")).thenReturn(login_hint);
|
||||
Mockito.when(request.getParameter("target_link_uri")).thenReturn(target_link_uri);
|
||||
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer(redirect_uri));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getIssuer_hasIssuer() {
|
||||
|
||||
|
||||
IssuerServiceResponse response = service.getIssuer(request);
|
||||
|
||||
|
||||
assertThat(response.getIssuer(), equalTo(iss));
|
||||
assertThat(response.getLoginHint(), equalTo(login_hint));
|
||||
assertThat(response.getTargetLinkUri(), equalTo(target_link_uri));
|
||||
|
||||
|
||||
assertThat(response.getRedirectUrl(), nullValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getIssuer_noIssuer() {
|
||||
|
||||
|
||||
Mockito.when(request.getParameter("iss")).thenReturn(null);
|
||||
|
||||
|
||||
IssuerServiceResponse response = service.getIssuer(request);
|
||||
|
||||
|
||||
assertThat(response.getIssuer(), nullValue());
|
||||
assertThat(response.getLoginHint(), nullValue());
|
||||
assertThat(response.getTargetLinkUri(), nullValue());
|
||||
|
||||
String expectedRedirectUrl = accountChooserUrl + "?redirect_uri=" +
|
||||
"https%3A%2F%2Fwww.example.com"; // url-encoded string of the request url
|
||||
|
||||
String expectedRedirectUrl = accountChooserUrl + "?redirect_uri=" + "https%3A%2F%2Fwww.example.com"; // url-encoded string of the request url
|
||||
assertThat(response.getRedirectUrl(), equalTo(expectedRedirectUrl));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getIssuer_isWhitelisted() {
|
||||
|
||||
service.setWhitelist(Sets.newHashSet(iss));
|
||||
|
||||
IssuerServiceResponse response = service.getIssuer(request);
|
||||
|
||||
assertThat(response.getIssuer(), equalTo(iss));
|
||||
assertThat(response.getLoginHint(), equalTo(login_hint));
|
||||
assertThat(response.getTargetLinkUri(), equalTo(target_link_uri));
|
||||
|
||||
assertThat(response.getRedirectUrl(), nullValue());
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationServiceException.class)
|
||||
public void getIssuer_notWhitelisted() {
|
||||
|
||||
service.setWhitelist(Sets.newHashSet("some.other.site"));
|
||||
|
||||
service.getIssuer(request);
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationServiceException.class)
|
||||
public void getIssuer_blacklisted() {
|
||||
|
||||
service.setBlacklist(Sets.newHashSet(iss));
|
||||
|
||||
service.getIssuer(request);
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationServiceException.class)
|
||||
public void getIssuer_badUri() {
|
||||
|
||||
|
||||
Mockito.when(request.getParameter("iss")).thenReturn(null);
|
||||
service.setAccountChooserUrl("e=mc^2");
|
||||
|
||||
|
||||
service.getIssuer(request);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue