Skip to content

Commit 9f84432

Browse files
committed
Update tests
1 parent 4db9ab9 commit 9f84432

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

java/cbsso-opensaml/app/src/test/java/cbsso/opensaml/AuthResponseValidatorTest.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ void rejectsWrongIssuer() throws Exception {
193193
void rejectsAssertionWhoseIssuerDiffersFromTheResponseIssuer() throws Exception {
194194
Response response = buildResponse(IDP_ISSUER, StatusCode.SUCCESS);
195195
Assertion assertion = buildAssertion();
196-
// The Response Issuer still names the expected IdP, so the unsigned wrapper looks correct; only the
197-
// signed Assertion disagrees. Signed by the trusted key, so nothing but the issuer check can reject it.
196+
// The Response Issuer still names the expected IdP, so the unsigned wrapper
197+
// looks correct; only the
198+
// signed Assertion disagrees. Signed by the trusted key, so nothing but the
199+
// issuer check can reject it.
198200
assertion.setIssuer(buildIssuer("https://someone-else.example.org"));
199201
attachSignature(assertion);
200202
response.getAssertions().add(assertion);
@@ -252,7 +254,8 @@ void rejectsExpiredAssertion() throws Exception {
252254
void rejectsAssertionWithNoExpiryAnywhere() throws Exception {
253255
Response response = buildResponse(IDP_ISSUER, StatusCode.SUCCESS);
254256
Assertion assertion = buildAssertion();
255-
assertion.setConditions(null);
257+
// Keep the required audience restriction while removing both expiry bounds.
258+
assertion.setConditions(buildConditions(SP_AUDIENCE));
256259
attachSignature(assertion);
257260
response.getAssertions().add(assertion);
258261
String xml = signAndSerialize(response, assertion.getSignature());
@@ -266,7 +269,8 @@ void rejectsAssertionWithNoExpiryAnywhere() throws Exception {
266269
void acceptsAssertionWithOnlyBearerSubjectConfirmationExpiry() throws Exception {
267270
Response response = buildResponse(IDP_ISSUER, StatusCode.SUCCESS);
268271
Assertion assertion = buildAssertion();
269-
// Conditions still carry the AudienceRestriction, but no NotOnOrAfter of their own, so the bearer
272+
// Conditions still carry the AudienceRestriction, but no NotOnOrAfter of their
273+
// own, so the bearer
270274
// SubjectConfirmationData is the only source of the upper bound.
271275
assertion.setConditions(buildConditions(SP_AUDIENCE));
272276
assertion.setSubject(buildBearerSubject(Instant.now().plus(Duration.ofMinutes(5))));
@@ -402,10 +406,14 @@ void acceptsAssertionBoundToThisServiceProviderWithAnAuthnStatement() throws Exc
402406

403407
@Test
404408
void acceptsRecipientDifferingOnlyByCaseFromTheAssertionConsumerService() throws Exception {
405-
// Entra echoes the Reply URL exactly as registered, and cbsso derives the expected one through
406-
// name.lcase() - so a registration reading .../auth/MSSAML arrives against an expected
407-
// .../auth/mssaml. Both resolve to the same handler on the same host, so they are the same
408-
// endpoint, and rejecting one is a false negative that fails every login closed.
409+
// Entra echoes the Reply URL exactly as registered, and cbsso derives the
410+
// expected one through
411+
// name.lcase() - so a registration reading .../auth/MSSAML arrives against an
412+
// expected
413+
// .../auth/mssaml. Both resolve to the same handler on the same host, so they
414+
// are the same
415+
// endpoint, and rejecting one is a false negative that fails every login
416+
// closed.
409417
Response response = buildResponse(IDP_ISSUER, StatusCode.SUCCESS);
410418
Assertion assertion = buildAssertion();
411419
assertion.setSubject(buildBearerSubject(
@@ -421,7 +429,8 @@ void acceptsRecipientDifferingOnlyByCaseFromTheAssertionConsumerService() throws
421429

422430
@Test
423431
void stillRejectsARecipientForAnotherHost() throws Exception {
424-
// The case-insensitive comparison must not become a substring or host-blind one.
432+
// The case-insensitive comparison must not become a substring or host-blind
433+
// one.
425434
Response response = buildResponse(IDP_ISSUER, StatusCode.SUCCESS);
426435
Assertion assertion = buildAssertion();
427436
assertion.setSubject(buildBearerSubject(
@@ -437,7 +446,8 @@ void stillRejectsARecipientForAnotherHost() throws Exception {
437446

438447
@Test
439448
void rejectsExcessivelyNestedDocument() {
440-
// No DTD, so disallow-doctype-decl does not help here: this is the nesting-depth case from
449+
// No DTD, so disallow-doctype-decl does not help here: this is the
450+
// nesting-depth case from
441451
// OpenSAML's 13 May 2026 advisory, and the parser has to refuse it.
442452
StringBuilder nested = new StringBuilder(
443453
"<samlp:Response xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">");
@@ -449,8 +459,10 @@ void rejectsExcessivelyNestedDocument() {
449459
}
450460
nested.append("</samlp:Response>");
451461

452-
// Asserting on the parser's own complaint, not merely that it threw: without the depth limit this
453-
// document is rejected later for having no Status, so a bare assertThrows would pass either way.
462+
// Asserting on the parser's own complaint, not merely that it threw: without
463+
// the depth limit this
464+
// document is rejected later for having no Status, so a bare assertThrows would
465+
// pass either way.
454466
Exception e = assertThrows(Exception.class, () -> validator.parseAndValidateAssertion(
455467
nested.toString(), IDP_ISSUER, SP_AUDIENCE, ACS_RECIPIENT));
456468
assertTrue(e.getMessage() != null && e.getMessage().contains("maxElementDepth"), e.getMessage());
@@ -557,8 +569,10 @@ private static Response buildResponse(String issuerValue, String statusCodeValue
557569
return response;
558570
}
559571

560-
// A fully valid assertion for the expected issuer, audience and recipient. The bearer
561-
// SubjectConfirmationData deliberately carries no NotOnOrAfter so that the expiry tests can control
572+
// A fully valid assertion for the expected issuer, audience and recipient. The
573+
// bearer
574+
// SubjectConfirmationData deliberately carries no NotOnOrAfter so that the
575+
// expiry tests can control
562576
// where the upper bound comes from.
563577
private static Assertion buildAssertion() {
564578
Assertion assertion = OpenSAMLUtils.buildSAMLObject(Assertion.class);

0 commit comments

Comments
 (0)