Skip to content

Add Testcontainers integration tests for SAML newslist flow#161

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/add-test-cases-newslist
Draft

Add Testcontainers integration tests for SAML newslist flow#161
Copilot wants to merge 2 commits into
mainfrom
copilot/add-test-cases-newslist

Conversation

Copy link
Copy Markdown

Copilot AI commented May 14, 2026

Summary

Adds end-to-end integration tests using Testcontainers and HtmlUnit that exercise the full SAML 2.0 SSO login flow of the newslist application.

A real SimpleSAMLphp IdP is started in Docker (jamedjo/test-saml-idp, the same image used in the demo docker-compose.yml) alongside the Spring Boot application. HtmlUnit drives a headless browser through the complete SSO flow.

Changes

build.gradle

  • Replace net.sourceforge.htmlunit:htmlunit (legacy, unmaintained) with org.htmlunit:htmlunit managed by the Spring Boot 4 BOM (version 4.17.0).
  • Add org.testcontainers:testcontainers and org.testcontainers:testcontainers-junit-jupiter (version 2.0.5, managed by the Spring Boot 4 BOM).

src/test/resources/news/

Two minimal CSV news files are added:

File Key Content
News Item 1.csv 1 Your first test news item
News Item 2.csv 1 Your second test news item

Both entries use key 1, which matches the uid attribute of user1 in the test IdP. user2 (uid 2) has no entries and sees an empty list.

src/test/java/…/NewsListIntegrationTest.java

Five test cases covering the main flows:

Test Description
unauthenticatedUserIsRedirectedToSamlLogin Unauthenticated GET / is redirected to the SimpleSAMLphp login page
authenticatedUserWithMatchingNewsSeesTheirItems user1 logs in and sees both news items
authenticatedUserWithoutMatchingNewsSeesEmptyList user2 logs in and sees no news items
emailAddressFromSamlAttributeIsDisplayed The email SAML attribute is shown on the index page
newsItemTitleIsDisplayedCorrectly The news item title is derived from the CSV filename

How the chicken-and-egg port problem is solved: A free port is pre-allocated via ServerSocket(0) in a static initialiser before the Testcontainers @Container is created. The IdP is configured with the SP ACS URL using that port, and @DynamicPropertySource injects server.port so Spring Boot binds to the same port.

.github/workflows/build.yml

Adds a gradle test step so the new tests run in CI.

Copilot AI and others added 2 commits May 14, 2026 08:23
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants