Skip to content

npe guard on missing session attribute - #13871

Open
DaanHoogland wants to merge 2 commits into
4.20from
ghi13815-NPEwhileSkippingSSOcheck
Open

npe guard on missing session attribute#13871
DaanHoogland wants to merge 2 commits into
4.20from
ghi13815-NPEwhileSkippingSSOcheck

Conversation

@DaanHoogland

Copy link
Copy Markdown
Contributor

Description

This PR...

Fixes: #13815

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.27%. Comparing base (549daae) to head (0ab78ce).

Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #13871   +/-   ##
=========================================
  Coverage     16.26%   16.27%           
- Complexity    13434    13439    +5     
=========================================
  Files          5667     5667           
  Lines        500731   500731           
  Branches      60803    60803           
=========================================
+ Hits          81455    81476   +21     
+ Misses       410172   410151   -21     
  Partials       9104     9104           
Flag Coverage Δ
uitests 4.14% <ø> (ø)
unittests 17.12% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DaanHoogland
DaanHoogland requested review from vishesh92 and a lite review from Copilot August 14, 2026 08:59
@DaanHoogland

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a null-safe guard when reading the 2FA verification flag from the HTTP session to avoid NPEs when the attribute is missing, and updates unit tests accordingly.

Changes:

  • Make skip2FAcheckForUser resilient to absent IS_2FA_VERIFIED session attribute.
  • Update Mockito usage in tests (static when import) and add a regression test for the missing-attribute scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
server/src/main/java/com/cloud/api/ApiServlet.java Makes 2FA verification flag retrieval null-safe via Boolean.TRUE.equals(...).
server/src/test/java/com/cloud/api/ApiServletTest.java Refactors some Mockito stubbing and adds a test covering absent 2FA session attribute.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +346 to 351
ConfigKey<Boolean> enableUserTwoFactorAuthentication = Mockito.mock(ConfigKey.class);
AccountManagerImpl.enableUserTwoFactorAuthentication = enableUserTwoFactorAuthentication;
when(enableUserTwoFactorAuthentication.valueIn(1L)).thenReturn(false);

boolean result = servlet.skip2FAcheckForUser(session);
Assert.assertEquals(true, result);
@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18859

@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.

NullPointerException in ApiServlet.skip2FAcheckForUser for SAML SSO sessions when 2FA is not enabled

4 participants