Skip to content

SecurityMockServerConfigurers.mockOAuth2Login() keeps returning 401 #18782

@blacelle

Description

@blacelle

Describe the bug
While migrating from SpringBoot 3.5.11 to SpringBoot 4.0.3, I can not succeed migrating tests related to oauth2 login.

I observe 401 while I expected to get 200.

I tested various things:

  • with and without .oauth2Login(oauth2 -> {})
  • with and without BASIC
  • with bindToApplicationContext
  • and various other configuration suggested by LLMs.

At the opposite of the test-tooling spectrum (i.e. bare-hand setup and mocking), I also added UserControllerTest (from some LLM) which has proper mocked authentication. But at the cost of skipping manually implicit configuration (e.g. from annotations).

To Reproduce
Run bug_report.oauth2.TestSecurity_WithOAuth2_asOAuth2User.testLoginJson() in provided github reproduction repository.

Expected behavior
I expect a 200, as I expect the call to be authenticated, with the test based on @SpringBootTest, @AutoConfigureWebTestClient and SecurityMockServerConfigurers.mockOAuth2Login().

Sample

See https://github.com/solven-eu/sb4-oauth2-migration_issue

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions