Azure-Samples/azure-spring-boot-samples

[FEATURE REQ] Add unit testing for Azure AD samples

arranbartish opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
This is described as a complete example.

learn.microsft.com

For a complete sample demonstrating this scenario, see spring-cloud-azure-starter-active-directory sample: aad-resource-server.

however there is an aspect missing, unit testing. When using @WebMvcTest we discover that the AadResourceServerWebSecurityConfigurerAdapter needs a properties bean AadResourceServerProperties that doesn't seem to be initialized with the slim context.

Describe the solution you'd like

I would like a set of simple tests using @WebMvcTest that would exercise the mappings using the spring security test mechanisms of @WithMockUser, @WithUserDetails, and/or @WithSecurityContext

Describe alternatives you've considered
I am trying to write these now.

I also have a full integration version which exposes a random port and uses the TestRestTemplate to make a call with a custom SecurityContextRepository, however we should be able to easily apply the slim @WebMvcTest context as well.

Additional context
IMHO the appropriate approach to testing is a critical part of a complete example.

Information Checklist

  • Description Added
  • Expected solution specified

Thanks @arranbartish that is exactly what I was looking for.
Do you have sample code of how you setup the Integration tests? I am currently stuck at this point.

I do.

I'll fork and PR back. The integration test was really a last resort for me. It would be better if we could get @WebMvcTest to work.