Polish Tests
- Use test objects - Ensure assertThat is checked Issue gh-11725
This commit is contained in:
parent
e6dfb63bdf
commit
dfa67fd8a1
|
@ -51,7 +51,6 @@ import org.opensaml.saml.saml2.core.Conditions;
|
||||||
import org.opensaml.saml.saml2.core.EncryptedAssertion;
|
import org.opensaml.saml.saml2.core.EncryptedAssertion;
|
||||||
import org.opensaml.saml.saml2.core.EncryptedAttribute;
|
import org.opensaml.saml.saml2.core.EncryptedAttribute;
|
||||||
import org.opensaml.saml.saml2.core.EncryptedID;
|
import org.opensaml.saml.saml2.core.EncryptedID;
|
||||||
import org.opensaml.saml.saml2.core.Issuer;
|
|
||||||
import org.opensaml.saml.saml2.core.NameID;
|
import org.opensaml.saml.saml2.core.NameID;
|
||||||
import org.opensaml.saml.saml2.core.OneTimeUse;
|
import org.opensaml.saml.saml2.core.OneTimeUse;
|
||||||
import org.opensaml.saml.saml2.core.ProxyRestriction;
|
import org.opensaml.saml.saml2.core.ProxyRestriction;
|
||||||
|
@ -737,16 +736,7 @@ public class OpenSaml4AuthenticationProviderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void authenticateWhenResponseStatusIsNotSuccessThenOnlyReturnParentStatusCodes() {
|
public void authenticateWhenResponseStatusIsNotSuccessThenOnlyReturnParentStatusCodes() {
|
||||||
ResponseToken mockResponseToken = mock(ResponseToken.class);
|
Saml2AuthenticationToken token = TestSaml2AuthenticationTokens.token();
|
||||||
Saml2AuthenticationToken mockSamlToken = mock(Saml2AuthenticationToken.class);
|
|
||||||
given(mockResponseToken.getToken()).willReturn(mockSamlToken);
|
|
||||||
|
|
||||||
RelyingPartyRegistration mockRelyingPartyRegistration = mock(RelyingPartyRegistration.class);
|
|
||||||
given(mockSamlToken.getRelyingPartyRegistration()).willReturn(mockRelyingPartyRegistration);
|
|
||||||
|
|
||||||
RelyingPartyRegistration.AssertingPartyDetails mockAssertingPartyDetails = mock(
|
|
||||||
RelyingPartyRegistration.AssertingPartyDetails.class);
|
|
||||||
given(mockRelyingPartyRegistration.getAssertingPartyDetails()).willReturn(mockAssertingPartyDetails);
|
|
||||||
|
|
||||||
Status parentStatus = new StatusBuilder().buildObject();
|
Status parentStatus = new StatusBuilder().buildObject();
|
||||||
StatusCode parentStatusCode = new StatusCodeBuilder().buildObject();
|
StatusCode parentStatusCode = new StatusCodeBuilder().buildObject();
|
||||||
|
@ -756,40 +746,27 @@ public class OpenSaml4AuthenticationProviderTests {
|
||||||
parentStatusCode.setStatusCode(childStatusCode);
|
parentStatusCode.setStatusCode(childStatusCode);
|
||||||
parentStatus.setStatusCode(parentStatusCode);
|
parentStatus.setStatusCode(parentStatusCode);
|
||||||
|
|
||||||
Response mockResponse = mock(Response.class);
|
Response response = TestOpenSamlObjects.response();
|
||||||
given(mockResponse.getStatus()).willReturn(parentStatus);
|
response.setStatus(parentStatus);
|
||||||
Issuer mockIssuer = mock(Issuer.class);
|
response.setIssuer(TestOpenSamlObjects.issuer("mockedIssuer"));
|
||||||
given(mockIssuer.getValue()).willReturn("mockedIssuer");
|
|
||||||
given(mockResponse.getIssuer()).willReturn(mockIssuer);
|
|
||||||
|
|
||||||
given(mockResponseToken.getResponse()).willReturn(mockResponse);
|
|
||||||
|
|
||||||
Converter<ResponseToken, Saml2ResponseValidatorResult> validator = OpenSaml4AuthenticationProvider
|
Converter<ResponseToken, Saml2ResponseValidatorResult> validator = OpenSaml4AuthenticationProvider
|
||||||
.createDefaultResponseValidator();
|
.createDefaultResponseValidator();
|
||||||
Saml2ResponseValidatorResult result = validator.convert(mockResponseToken);
|
Saml2ResponseValidatorResult result = validator.convert(new ResponseToken(response, token));
|
||||||
|
|
||||||
String expectedErrorMessage = String.format("Invalid status [%s] for SAML response",
|
String expectedErrorMessage = String.format("Invalid status [%s] for SAML response",
|
||||||
parentStatusCode.getValue());
|
parentStatusCode.getValue());
|
||||||
assertThat(
|
assertThat(
|
||||||
result.getErrors().stream().anyMatch((error) -> error.getDescription().contains(expectedErrorMessage)));
|
result.getErrors().stream().anyMatch((error) -> error.getDescription().contains(expectedErrorMessage)))
|
||||||
|
.isTrue();
|
||||||
assertThat(result.getErrors()
|
assertThat(result.getErrors()
|
||||||
.stream()
|
.stream()
|
||||||
.noneMatch((error) -> error.getDescription().contains(childStatusCode.getValue())));
|
.noneMatch((error) -> error.getDescription().contains(childStatusCode.getValue()))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void authenticateWhenResponseStatusIsNotSuccessThenReturnParentAndChildStatusCode() {
|
public void authenticateWhenResponseStatusIsNotSuccessThenReturnParentAndChildStatusCode() {
|
||||||
ResponseToken mockResponseToken = mock(ResponseToken.class);
|
Saml2AuthenticationToken token = TestSaml2AuthenticationTokens.token();
|
||||||
Saml2AuthenticationToken mockSamlToken = mock(Saml2AuthenticationToken.class);
|
|
||||||
given(mockResponseToken.getToken()).willReturn(mockSamlToken);
|
|
||||||
|
|
||||||
RelyingPartyRegistration mockRelyingPartyRegistration = mock(RelyingPartyRegistration.class);
|
|
||||||
given(mockSamlToken.getRelyingPartyRegistration()).willReturn(mockRelyingPartyRegistration);
|
|
||||||
|
|
||||||
RelyingPartyRegistration.AssertingPartyDetails mockAssertingPartyDetails = mock(
|
|
||||||
RelyingPartyRegistration.AssertingPartyDetails.class);
|
|
||||||
given(mockRelyingPartyRegistration.getAssertingPartyDetails()).willReturn(mockAssertingPartyDetails);
|
|
||||||
|
|
||||||
Status parentStatus = new StatusBuilder().buildObject();
|
Status parentStatus = new StatusBuilder().buildObject();
|
||||||
StatusCode parentStatusCode = new StatusCodeBuilder().buildObject();
|
StatusCode parentStatusCode = new StatusCodeBuilder().buildObject();
|
||||||
parentStatusCode.setValue(StatusCode.REQUESTER);
|
parentStatusCode.setValue(StatusCode.REQUESTER);
|
||||||
|
@ -798,17 +775,13 @@ public class OpenSaml4AuthenticationProviderTests {
|
||||||
parentStatusCode.setStatusCode(childStatusCode);
|
parentStatusCode.setStatusCode(childStatusCode);
|
||||||
parentStatus.setStatusCode(parentStatusCode);
|
parentStatus.setStatusCode(parentStatusCode);
|
||||||
|
|
||||||
Response mockResponse = mock(Response.class);
|
Response response = TestOpenSamlObjects.response();
|
||||||
given(mockResponse.getStatus()).willReturn(parentStatus);
|
response.setStatus(parentStatus);
|
||||||
Issuer mockIssuer = mock(Issuer.class);
|
response.setIssuer(TestOpenSamlObjects.issuer("mockedIssuer"));
|
||||||
given(mockIssuer.getValue()).willReturn("mockedIssuer");
|
|
||||||
given(mockResponse.getIssuer()).willReturn(mockIssuer);
|
|
||||||
|
|
||||||
given(mockResponseToken.getResponse()).willReturn(mockResponse);
|
|
||||||
|
|
||||||
Converter<ResponseToken, Saml2ResponseValidatorResult> validator = OpenSaml4AuthenticationProvider
|
Converter<ResponseToken, Saml2ResponseValidatorResult> validator = OpenSaml4AuthenticationProvider
|
||||||
.createDefaultResponseValidator();
|
.createDefaultResponseValidator();
|
||||||
Saml2ResponseValidatorResult result = validator.convert(mockResponseToken);
|
Saml2ResponseValidatorResult result = validator.convert(new ResponseToken(response, token));
|
||||||
|
|
||||||
String expectedParentErrorMessage = String.format("Invalid status [%s] for SAML response",
|
String expectedParentErrorMessage = String.format("Invalid status [%s] for SAML response",
|
||||||
parentStatusCode.getValue());
|
parentStatusCode.getValue());
|
||||||
|
@ -816,10 +789,10 @@ public class OpenSaml4AuthenticationProviderTests {
|
||||||
childStatusCode.getValue());
|
childStatusCode.getValue());
|
||||||
assertThat(result.getErrors()
|
assertThat(result.getErrors()
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch((error) -> error.getDescription().contains(expectedParentErrorMessage)));
|
.anyMatch((error) -> error.getDescription().contains(expectedParentErrorMessage))).isTrue();
|
||||||
assertThat(result.getErrors()
|
assertThat(result.getErrors()
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch((error) -> error.getDescription().contains(expectedChildErrorMessage)));
|
.anyMatch((error) -> error.getDescription().contains(expectedChildErrorMessage))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue