51
51
import org .opensaml .saml .saml2 .core .EncryptedAssertion ;
52
52
import org .opensaml .saml .saml2 .core .EncryptedAttribute ;
53
53
import org .opensaml .saml .saml2 .core .EncryptedID ;
54
- import org .opensaml .saml .saml2 .core .Issuer ;
55
54
import org .opensaml .saml .saml2 .core .NameID ;
56
55
import org .opensaml .saml .saml2 .core .OneTimeUse ;
57
56
import org .opensaml .saml .saml2 .core .ProxyRestriction ;
@@ -737,16 +736,7 @@ public void authenticateWhenCustomResponseValidatorThenUses() {
737
736
738
737
@ Test
739
738
public void authenticateWhenResponseStatusIsNotSuccessThenOnlyReturnParentStatusCodes () {
740
- ResponseToken mockResponseToken = mock (ResponseToken .class );
741
- Saml2AuthenticationToken mockSamlToken = mock (Saml2AuthenticationToken .class );
742
- given (mockResponseToken .getToken ()).willReturn (mockSamlToken );
743
-
744
- RelyingPartyRegistration mockRelyingPartyRegistration = mock (RelyingPartyRegistration .class );
745
- given (mockSamlToken .getRelyingPartyRegistration ()).willReturn (mockRelyingPartyRegistration );
746
-
747
- RelyingPartyRegistration .AssertingPartyDetails mockAssertingPartyDetails = mock (
748
- RelyingPartyRegistration .AssertingPartyDetails .class );
749
- given (mockRelyingPartyRegistration .getAssertingPartyDetails ()).willReturn (mockAssertingPartyDetails );
739
+ Saml2AuthenticationToken token = TestSaml2AuthenticationTokens .token ();
750
740
751
741
Status parentStatus = new StatusBuilder ().buildObject ();
752
742
StatusCode parentStatusCode = new StatusCodeBuilder ().buildObject ();
@@ -756,40 +746,27 @@ public void authenticateWhenResponseStatusIsNotSuccessThenOnlyReturnParentStatus
756
746
parentStatusCode .setStatusCode (childStatusCode );
757
747
parentStatus .setStatusCode (parentStatusCode );
758
748
759
- Response mockResponse = mock (Response .class );
760
- given (mockResponse .getStatus ()).willReturn (parentStatus );
761
- Issuer mockIssuer = mock (Issuer .class );
762
- given (mockIssuer .getValue ()).willReturn ("mockedIssuer" );
763
- given (mockResponse .getIssuer ()).willReturn (mockIssuer );
764
-
765
- given (mockResponseToken .getResponse ()).willReturn (mockResponse );
749
+ Response response = TestOpenSamlObjects .response ();
750
+ response .setStatus (parentStatus );
751
+ response .setIssuer (TestOpenSamlObjects .issuer ("mockedIssuer" ));
766
752
767
753
Converter <ResponseToken , Saml2ResponseValidatorResult > validator = OpenSaml4AuthenticationProvider
768
754
.createDefaultResponseValidator ();
769
- Saml2ResponseValidatorResult result = validator .convert (mockResponseToken );
755
+ Saml2ResponseValidatorResult result = validator .convert (new ResponseToken ( response , token ) );
770
756
771
757
String expectedErrorMessage = String .format ("Invalid status [%s] for SAML response" ,
772
758
parentStatusCode .getValue ());
773
759
assertThat (
774
- result .getErrors ().stream ().anyMatch ((error ) -> error .getDescription ().contains (expectedErrorMessage )));
760
+ result .getErrors ().stream ().anyMatch ((error ) -> error .getDescription ().contains (expectedErrorMessage )))
761
+ .isTrue ();
775
762
assertThat (result .getErrors ()
776
763
.stream ()
777
- .noneMatch ((error ) -> error .getDescription ().contains (childStatusCode .getValue ())));
764
+ .noneMatch ((error ) -> error .getDescription ().contains (childStatusCode .getValue ()))). isTrue () ;
778
765
}
779
766
780
767
@ Test
781
768
public void authenticateWhenResponseStatusIsNotSuccessThenReturnParentAndChildStatusCode () {
782
- ResponseToken mockResponseToken = mock (ResponseToken .class );
783
- Saml2AuthenticationToken mockSamlToken = mock (Saml2AuthenticationToken .class );
784
- given (mockResponseToken .getToken ()).willReturn (mockSamlToken );
785
-
786
- RelyingPartyRegistration mockRelyingPartyRegistration = mock (RelyingPartyRegistration .class );
787
- given (mockSamlToken .getRelyingPartyRegistration ()).willReturn (mockRelyingPartyRegistration );
788
-
789
- RelyingPartyRegistration .AssertingPartyDetails mockAssertingPartyDetails = mock (
790
- RelyingPartyRegistration .AssertingPartyDetails .class );
791
- given (mockRelyingPartyRegistration .getAssertingPartyDetails ()).willReturn (mockAssertingPartyDetails );
792
-
769
+ Saml2AuthenticationToken token = TestSaml2AuthenticationTokens .token ();
793
770
Status parentStatus = new StatusBuilder ().buildObject ();
794
771
StatusCode parentStatusCode = new StatusCodeBuilder ().buildObject ();
795
772
parentStatusCode .setValue (StatusCode .REQUESTER );
@@ -798,28 +775,24 @@ public void authenticateWhenResponseStatusIsNotSuccessThenReturnParentAndChildSt
798
775
parentStatusCode .setStatusCode (childStatusCode );
799
776
parentStatus .setStatusCode (parentStatusCode );
800
777
801
- Response mockResponse = mock (Response .class );
802
- given (mockResponse .getStatus ()).willReturn (parentStatus );
803
- Issuer mockIssuer = mock (Issuer .class );
804
- given (mockIssuer .getValue ()).willReturn ("mockedIssuer" );
805
- given (mockResponse .getIssuer ()).willReturn (mockIssuer );
806
-
807
- given (mockResponseToken .getResponse ()).willReturn (mockResponse );
778
+ Response response = TestOpenSamlObjects .response ();
779
+ response .setStatus (parentStatus );
780
+ response .setIssuer (TestOpenSamlObjects .issuer ("mockedIssuer" ));
808
781
809
782
Converter <ResponseToken , Saml2ResponseValidatorResult > validator = OpenSaml4AuthenticationProvider
810
783
.createDefaultResponseValidator ();
811
- Saml2ResponseValidatorResult result = validator .convert (mockResponseToken );
784
+ Saml2ResponseValidatorResult result = validator .convert (new ResponseToken ( response , token ) );
812
785
813
786
String expectedParentErrorMessage = String .format ("Invalid status [%s] for SAML response" ,
814
787
parentStatusCode .getValue ());
815
788
String expectedChildErrorMessage = String .format ("Invalid status [%s] for SAML response" ,
816
789
childStatusCode .getValue ());
817
790
assertThat (result .getErrors ()
818
791
.stream ()
819
- .anyMatch ((error ) -> error .getDescription ().contains (expectedParentErrorMessage )));
792
+ .anyMatch ((error ) -> error .getDescription ().contains (expectedParentErrorMessage ))). isTrue () ;
820
793
assertThat (result .getErrors ()
821
794
.stream ()
822
- .anyMatch ((error ) -> error .getDescription ().contains (expectedChildErrorMessage )));
795
+ .anyMatch ((error ) -> error .getDescription ().contains (expectedChildErrorMessage ))). isTrue () ;
823
796
}
824
797
825
798
@ Test
0 commit comments