Skip to content

fix(auth): ensure endpoint-mode login after server list refresh + add regression test (#728)#856

Draft
ljluestc wants to merge 2 commits intonacos-group:masterfrom
ljluestc:test/endpoint-auth-login-728
Draft

fix(auth): ensure endpoint-mode login after server list refresh + add regression test (#728)#856
ljluestc wants to merge 2 commits intonacos-group:masterfrom
ljluestc:test/endpoint-auth-login-728

Conversation

@ljluestc
Copy link

@ljluestc ljluestc commented Nov 8, 2025

This PR fixes and tests endpoint/address-mode authentication.

Problem (#728): In endpoint mode, login could return false if the discovered serverList was not present at login time, causing 403 on instance registration.

Changes:

  • fix(nacos_server): Trigger security login immediately after endpoint server list updates (in refreshServerSrvIfNeed) to ensure access token is acquired promptly.
  • test(nacos_server): Add regression test (TestEndpointMode_LoginAndInjectToken) that:
    • Mocks address server discovery to return a server node.
    • Verifies login hits /v1/auth/users/login on the discovered node.
    • Verifies accessToken is injected into subsequent naming requests.

Why this is safe:

  • Login is idempotent; called after unlocking to avoid holding locks during network I/O.
  • Only affects endpoint/address mode when the list changes.

How to verify:

  • GOTOOLCHAIN=go1.21.5 go test ./common/nacos_server -run TestEndpointMode_LoginAndInjectToken -v
  • Or: GOTOOLCHAIN=go1.21.5 go test ./... -v

Fixes #728

…nacos-group#728)\n\n- Mocks address server discovery\n- Verifies login uses discovered server list\n- Ensures accessToken is injected into subsequent requests
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

…es (nacos-group#728)\n\n- Call securityLogin.Login() right after UpdateServerList in refresh\n- Ensures token is acquired promptly in endpoint/address mode
@ljluestc ljluestc changed the title test: add endpoint-mode auth/login regression test (#728) fix(auth): ensure endpoint-mode login after server list refresh + add regression test (#728) Nov 8, 2025
@ljluestc ljluestc marked this pull request as draft November 8, 2025 18:06
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.

endpoint寻址模式下login会直接返回false,导致实例注册失败(权限校验失败)

2 participants