GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][test] Use non-expiring tokens in AuthenticationProviderListTest.testAuthenticateHttpRequest by merlimat · Pull Request #27400 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Motivation

AuthenticationProviderListTest.testAuthenticateHttpRequest fails its first attempt in about 1 of 12 "CI - Unit - Other"
runs (2 of 23 on 2026-11-05: apache/pulsar runs 41993860927 and 42086241938). Each time it took 3.0 s and failed with:

java.lang.NullPointerException: Cannot invoke "org.apache.pulsar.broker.authentication.metrics.AuthenticationMetrics.recordFailure(String, String, String)" because "metrics" is null

The test authenticates with expiringTokenAA, expiringTokenAB, expiringTokenBA and expiringTokenBB, which
setUp creates with a 3 s expiry:

this.expiringTokenAA = AuthTokenUtils.createToken(privateKeyA, SUBJECT_A,
    Optional.of(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3))));

The JWT exp claim is truncated to whole seconds, so the tokens actually expire 2 to 3 s after setUp. The test
method creates the class's first Mockito mock (mock(HttpServletRequest.class)). That takes about 0.35 s locally,
against 0.02 s for the other methods, and it took 3.0 s on a loaded CI runner. By the time the first request was
authenticated, the token had expired. Both token providers rejected it, so AuthenticationProviderList recorded the
failure:

// AuthenticationProviderList.applyAuthProcessor
metrics.recordFailure(AuthenticationProviderList.class.getSimpleName(),
        "authentication-provider-list", errorCode);

metrics is the list's authenticationMetrics, which only initialize() sets. The test builds the list with
new AuthenticationProviderList(...) and never initializes it, because it initializes the two token providers with
different settings prefixes. So the expired token showed up as a NullPointerException, not as an authentication
failure.

This is a test bug. AuthenticationService, which is the only production code that creates an
AuthenticationProviderList, always calls initialize() before using it.

Modifications

testAuthenticateHttpRequest checks HTTP authentication through the provider list, not token expiry, so it now
uses tokenAA, tokenAB, tokenBA and tokenBB. setUp already creates these tokens without an expiry. The test
no longer depends on how long the runner takes to reach each request.

Verifying this change

  • Reproduced the CI failure deterministically by adding a temporary Thread.sleep(3100) at the top of the method.
    Without the fix it fails with the exact NPE above, at AuthenticationProviderList.java:88. With the fix and the
    same pause it passes in 3.6 s. The pause is not committed.
  • ./gradlew :pulsar-broker-common:test --tests 'org.apache.pulsar.broker.authentication.AuthenticationProviderListTest'
    passes all 5 methods, and ./gradlew quickCheck passes.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@merlimat
[fix][test] Use non-expiring tokens in AuthenticationProviderListTest…
1c7aab3
….testAuthenticateHttpRequest

testAuthenticateHttpRequest authenticated with tokens that setUp creates
with a 3 s expiry (2-3 s after the JWT exp is cut to whole seconds). The
method creates the class's first Mockito mock, which takes ~0.35 s locally
and took 3.0 s on a loaded CI runner. Once the tokens had expired, both
providers rejected them and AuthenticationProviderList recorded the
failure on its metrics, which are null because the test never initializes
the list, so the test failed with a NullPointerException.

The test checks HTTP authentication through the list, not expiry, so use
the tokens without an expiry that setUp already creates.
@merlimat merlimat added the area/test label Nov 6, 2026
codelipenghui
codelipenghui approved these changes Nov 6, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Code Review approval for commit 1c7aab3.

Summary:

No actionable findings identified within the reviewed scope.

The four substitutions remove an irrelevant expiry deadline while preserving HTTP authentication assertions and production behavior. Seven focused tests passed. A controlled delay reproduced the old NPE and passed with the fix; all temporary edits were removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codelipenghui
codelipenghui merged commit aee0854 into apache:master Nov 6, 2026
43 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@merlimat
merlimat deleted the mmerli/auth-provider-list-metrics-npe branch November 6, 2026 18:15
lhotari pushed a commit that referenced this pull request Nov 9, 2026
@merlimat @lhotari
[fix][test] Use non-expiring tokens in AuthenticationProviderListTest…
e1f801b
….testAuthenticateHttpRequest (#27400)

(cherry picked from commit aee0854)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 9, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Use non-expiring tokens in AuthenticationProviderListTest…
29fcedc
….testAuthenticateHttpRequest (apache#27400)

(cherry picked from commit aee0854)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][test] Use non-expiring tokens in AuthenticationProviderListTest…
38a1974
….testAuthenticateHttpRequest (apache#27400)

(cherry picked from commit aee0854)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area/test cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@merlimat @codelipenghui @lhotari
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.