1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
86
86
import static org .assertj .core .api .Assertions .assertThat ;
87
87
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
88
88
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
89
- import static org .junit .Assert .assertFalse ;
90
- import static org .junit .Assert .assertTrue ;
91
89
import static org .mockito .ArgumentMatchers .any ;
92
90
import static org .mockito .BDDMockito .given ;
93
91
import static org .mockito .Mockito .atLeastOnce ;
@@ -736,15 +734,16 @@ public void authenticateWhenCustomResponseValidatorThenUses() {
736
734
}
737
735
738
736
@ Test
739
- public void setsOnlyParentStatusCodeOnResultDescription () {
737
+ public void authenticateWhenResponseStatusIsNotSuccessThenOnlyReturnParentStatusCodes () {
740
738
ResponseToken mockResponseToken = mock (ResponseToken .class );
741
739
Saml2AuthenticationToken mockSamlToken = mock (Saml2AuthenticationToken .class );
742
740
given (mockResponseToken .getToken ()).willReturn (mockSamlToken );
743
741
744
742
RelyingPartyRegistration mockRelyingPartyRegistration = mock (RelyingPartyRegistration .class );
745
743
given (mockSamlToken .getRelyingPartyRegistration ()).willReturn (mockRelyingPartyRegistration );
746
744
747
- RelyingPartyRegistration .AssertingPartyDetails mockAssertingPartyDetails = mock (RelyingPartyRegistration .AssertingPartyDetails .class );
745
+ RelyingPartyRegistration .AssertingPartyDetails mockAssertingPartyDetails = mock (
746
+ RelyingPartyRegistration .AssertingPartyDetails .class );
748
747
given (mockRelyingPartyRegistration .getAssertingPartyDetails ()).willReturn (mockAssertingPartyDetails );
749
748
750
749
Status parentStatus = new StatusBuilder ().buildObject ();
@@ -763,24 +762,30 @@ public void setsOnlyParentStatusCodeOnResultDescription() {
763
762
764
763
given (mockResponseToken .getResponse ()).willReturn (mockResponse );
765
764
766
- Converter <ResponseToken , Saml2ResponseValidatorResult > validator = OpenSaml4AuthenticationProvider .createDefaultResponseValidator ();
765
+ Converter <ResponseToken , Saml2ResponseValidatorResult > validator = OpenSaml4AuthenticationProvider
766
+ .createDefaultResponseValidator ();
767
767
Saml2ResponseValidatorResult result = validator .convert (mockResponseToken );
768
768
769
- String expectedErrorMessage = String .format ("Invalid status [%s] for SAML response" , parentStatusCode .getValue ());
770
- assertTrue (result .getErrors ().stream ().anyMatch (error -> error .getDescription ().contains (expectedErrorMessage )));
771
- assertFalse (result .getErrors ().stream ().anyMatch (error -> error .getDescription ().contains (childStatusCode .getValue ())));
769
+ String expectedErrorMessage = String .format ("Invalid status [%s] for SAML response" ,
770
+ parentStatusCode .getValue ());
771
+ assertThat (
772
+ result .getErrors ().stream ().anyMatch ((error ) -> error .getDescription ().contains (expectedErrorMessage )));
773
+ assertThat (result .getErrors ()
774
+ .stream ()
775
+ .noneMatch ((error ) -> error .getDescription ().contains (childStatusCode .getValue ())));
772
776
}
773
777
774
778
@ Test
775
- public void setsParentAndChildStatusCodeOnResultDescription () {
779
+ public void authenticateWhenResponseStatusIsNotSuccessThenReturnParentAndChildStatusCode () {
776
780
ResponseToken mockResponseToken = mock (ResponseToken .class );
777
781
Saml2AuthenticationToken mockSamlToken = mock (Saml2AuthenticationToken .class );
778
782
given (mockResponseToken .getToken ()).willReturn (mockSamlToken );
779
783
780
784
RelyingPartyRegistration mockRelyingPartyRegistration = mock (RelyingPartyRegistration .class );
781
785
given (mockSamlToken .getRelyingPartyRegistration ()).willReturn (mockRelyingPartyRegistration );
782
786
783
- RelyingPartyRegistration .AssertingPartyDetails mockAssertingPartyDetails = mock (RelyingPartyRegistration .AssertingPartyDetails .class );
787
+ RelyingPartyRegistration .AssertingPartyDetails mockAssertingPartyDetails = mock (
788
+ RelyingPartyRegistration .AssertingPartyDetails .class );
784
789
given (mockRelyingPartyRegistration .getAssertingPartyDetails ()).willReturn (mockAssertingPartyDetails );
785
790
786
791
Status parentStatus = new StatusBuilder ().buildObject ();
@@ -799,11 +804,20 @@ public void setsParentAndChildStatusCodeOnResultDescription() {
799
804
800
805
given (mockResponseToken .getResponse ()).willReturn (mockResponse );
801
806
802
- Converter <ResponseToken , Saml2ResponseValidatorResult > validator = OpenSaml4AuthenticationProvider .createDefaultResponseValidator ();
807
+ Converter <ResponseToken , Saml2ResponseValidatorResult > validator = OpenSaml4AuthenticationProvider
808
+ .createDefaultResponseValidator ();
803
809
Saml2ResponseValidatorResult result = validator .convert (mockResponseToken );
804
810
805
- String expectedErrorMessage = String .format ("Invalid status [%s] for SAML response" , parentStatusCode .getValue () + childStatusCode .getValue ());
806
- assertTrue (result .getErrors ().stream ().anyMatch (error -> error .getDescription ().contains (expectedErrorMessage )));
811
+ String expectedParentErrorMessage = String .format ("Invalid status [%s] for SAML response" ,
812
+ parentStatusCode .getValue ());
813
+ String expectedChildErrorMessage = String .format ("Invalid status [%s] for SAML response" ,
814
+ childStatusCode .getValue ());
815
+ assertThat (result .getErrors ()
816
+ .stream ()
817
+ .anyMatch ((error ) -> error .getDescription ().contains (expectedParentErrorMessage )));
818
+ assertThat (result .getErrors ()
819
+ .stream ()
820
+ .anyMatch ((error ) -> error .getDescription ().contains (expectedChildErrorMessage )));
807
821
}
808
822
809
823
@ Test
0 commit comments