Skip to content

Add the session management test to the TestNG XML configuration#27362

Open
DilshanSenarath wants to merge 2 commits intowso2:masterfrom
DilshanSenarath:session-mgt-test
Open

Add the session management test to the TestNG XML configuration#27362
DilshanSenarath wants to merge 2 commits intowso2:masterfrom
DilshanSenarath:session-mgt-test

Conversation

@DilshanSenarath
Copy link
Copy Markdown
Contributor

@DilshanSenarath DilshanSenarath commented Mar 31, 2026

$subject

Summary by CodeRabbit

  • Tests
    • Re-enabled session management tests in the suite.
    • Added detailed timestamped logging and cookie diagnostics to session tests and helper flows.
    • Made test checks more explicit and added defensive handling in login/check flows to improve reliability and test output clarity.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Re-enabled the TestNG session-management <test> block and added timestamped System.out.println diagnostics and cookie-state prints across session tests and their shared test base; a minor boolean refactor in session activity detection and defensive handling of missing redirect headers were also added.

Changes

Cohort / File(s) Summary
Test Suite Configuration
modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml
Uncommented / re-activated the is-test-session-mgt <test> block so SessionMgtTest and SessionMgtFailureTest run in the suite.
Session Management Test
modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java
Inserted multiple System.out.println timestamped markers and elapsed-time prints around login, sleeps, and session checks; added timestamps for start/end of test checks. No control-flow or assertions changed.
Session Test Base Utilities
modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java
Added System.out.println debug output in updateServerConfiguration, performLogin, and checkSessionActive (including cookie descriptions), made checkSessionActive compute and return an active boolean variable (logged), and added defensive handling when Location header is missing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in with prints and time,
Ticking ticks and cookies' rhyme.
Tests awake from commented sleep,
Small logs now gather what they keep.
A joyful hop — the suite will leap! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the primary change: re-enabling the session management test block in the TestNG XML configuration file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DilshanSenarath DilshanSenarath force-pushed the session-mgt-test branch 2 times, most recently from 3787fe5 to 61ff3c3 Compare April 1, 2026 18:01
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java (1)

420-433: Refactor the array filtering logic and add null safety.

The current pattern of reassigning configs within a for-each loop is confusing and inefficient (creates a new array on each removal). While it technically works because Java captures the array reference at the start of for-each, a cleaner approach using streams would be more readable and efficient.

Additionally, there are potential null pointer issues:

  • getFederatedAuthenticatorConfigs() may return null
  • cfg.getName() may return null
♻️ Proposed refactor using streams with null safety
     protected void resetResidentIDPCache() throws Exception {

         IdentityProviderMgtServiceClient idpMgtClient = new IdentityProviderMgtServiceClient(sessionCookie, backendURL);
         IdentityProvider residentIdp = idpMgtClient.getResidentIdP();

         FederatedAuthenticatorConfig[] configs = residentIdp.getFederatedAuthenticatorConfigs();
-        for (FederatedAuthenticatorConfig cfg : configs) {
-            if (!cfg.getName().equalsIgnoreCase("samlsso")) {
-                configs = (FederatedAuthenticatorConfig[]) ArrayUtils.removeElement(configs, cfg);
-            }
+        if (configs != null) {
+            FederatedAuthenticatorConfig[] filteredConfigs = java.util.Arrays.stream(configs)
+                    .filter(cfg -> cfg != null && "samlsso".equalsIgnoreCase(cfg.getName()))
+                    .toArray(FederatedAuthenticatorConfig[]::new);
+            residentIdp.setFederatedAuthenticatorConfigs(filteredConfigs);
         }
-        residentIdp.setFederatedAuthenticatorConfigs(configs);
         idpMgtClient.updateResidentIdP(residentIdp);
     }

Note: If using streams, the ArrayUtils import on line 24 can be removed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java`
around lines 420 - 433, The loop in resetResidentIDPCache currently mutates the
configs array inside a for-each and lacks null checks; refactor to safely handle
nulls by retrieving the resident IDP via
IdentityProviderMgtServiceClient.getResidentIdP(), then call
getFederatedAuthenticatorConfigs() and if it is non-null, filter the
FederatedAuthenticatorConfig[] to only keep entries whose getName() is non-null
and equalsIgnoreCase("samlsso") (use
Arrays.stream(...).filter(...).toArray(FederatedAuthenticatorConfig[]::new) or
equivalent), set the filtered array back on residentIdp via
setFederatedAuthenticatorConfigs(...) and call updateResidentIdP(residentIdp);
remove the ArrayUtils-based removal logic and add null-safety for both the
configs array and cfg.getName().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java`:
- Around line 420-433: The loop in resetResidentIDPCache currently mutates the
configs array inside a for-each and lacks null checks; refactor to safely handle
nulls by retrieving the resident IDP via
IdentityProviderMgtServiceClient.getResidentIdP(), then call
getFederatedAuthenticatorConfigs() and if it is non-null, filter the
FederatedAuthenticatorConfig[] to only keep entries whose getName() is non-null
and equalsIgnoreCase("samlsso") (use
Arrays.stream(...).filter(...).toArray(FederatedAuthenticatorConfig[]::new) or
equivalent), set the filtered array back on residentIdp via
setFederatedAuthenticatorConfigs(...) and call updateResidentIdP(residentIdp);
remove the ArrayUtils-based removal logic and add null-safety for both the
configs array and cfg.getName().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 43bec908-820f-4dc7-9765-90b544c0655f

📥 Commits

Reviewing files that changed from the base of the PR and between 38d900c and 61ff3c3.

📒 Files selected for processing (2)
  • modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java
  • modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java
✅ Files skipped from review due to trivial changes (1)
  • modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java (2)

35-38: Consider importing java.time.Duration for consistency.

Instant is imported, but java.time.Duration is used with its fully qualified name on lines 121, 132, and 143. Import it alongside Instant for consistency.

Suggested fix
 import java.time.Instant;
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.logging.Logger;

Then update the usages:

-        + " | elapsed since login=" + java.time.Duration.between(loginCompletedAt, check1At).toMillis() + "ms");
+        + " | elapsed since login=" + Duration.between(loginCompletedAt, check1At).toMillis() + "ms");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java`
around lines 35 - 38, The test class SessionMgtTest imports java.time.Instant
but uses java.time.Duration with fully qualified names; add an import for
java.time.Duration and replace the fully qualified usages (e.g.,
java.time.Duration.ofSeconds(...) calls found in the test methods) with the
simple Duration identifier to keep imports consistent and shorten the calls.

156-173: Consider adding similar logging to other session timeout tests.

Only testSessionExtensionWithIdleTimeout has detailed timestamped logging. If these tests are also prone to timing-related flakiness, consider adding consistent logging to testSessionWithRememberMe, testMaximumSessionTimeoutWithIdleTimeout, and testMaximumSessionTimeoutWithRememberMe for easier debugging.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java`
around lines 156 - 173, The other timing-sensitive tests
(testSessionWithRememberMe, testMaximumSessionTimeoutWithIdleTimeout,
testMaximumSessionTimeoutWithRememberMe) lack the timestamped logging present in
testSessionExtensionWithIdleTimeout; add similar detailed, timestamped debug/log
statements before and after sleeps and before each checkSessionActive call in
these methods so test runs record when login, waits, and session checks occur
(use the same logging format and logger used in
testSessionExtensionWithIdleTimeout to keep output consistent for debugging).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java`:
- Around line 35-38: The test class SessionMgtTest imports java.time.Instant but
uses java.time.Duration with fully qualified names; add an import for
java.time.Duration and replace the fully qualified usages (e.g.,
java.time.Duration.ofSeconds(...) calls found in the test methods) with the
simple Duration identifier to keep imports consistent and shorten the calls.
- Around line 156-173: The other timing-sensitive tests
(testSessionWithRememberMe, testMaximumSessionTimeoutWithIdleTimeout,
testMaximumSessionTimeoutWithRememberMe) lack the timestamped logging present in
testSessionExtensionWithIdleTimeout; add similar detailed, timestamped debug/log
statements before and after sleeps and before each checkSessionActive call in
these methods so test runs record when login, waits, and session checks occur
(use the same logging format and logger used in
testSessionExtensionWithIdleTimeout to keep output consistent for debugging).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90285e20-36fd-4fc5-bf1c-d3924ea2e76f

📥 Commits

Reviewing files that changed from the base of the PR and between 61ff3c3 and eafdbd1.

📒 Files selected for processing (2)
  • modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTest.java
  • modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/session/SessionMgtTestBase.java

@DilshanSenarath DilshanSenarath force-pushed the session-mgt-test branch 3 times, most recently from 80d4108 to bbd4ea9 Compare April 3, 2026 10:48
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2026

@DilshanSenarath
Copy link
Copy Markdown
Contributor Author

Integration Test Runner (Sequential - All Tests)

@wso2 wso2 deleted a comment from jenkins-is-staging Apr 4, 2026
@wso2 wso2 deleted a comment from jenkins-is-staging Apr 4, 2026
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.

1 participant