azure-spring-boot-samples icon indicating copy to clipboard operation
azure-spring-boot-samples copied to clipboard

[FEATURE REQ] Add unit testing for Azure AD samples

Open arranbartish opened this issue 2 years ago • 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

  • [x] Description Added
  • [x] Expected solution specified

arranbartish avatar Jan 31 '23 19:01 arranbartish

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.

nb-git avatar Feb 09 '23 14:02 nb-git

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.

arranbartish avatar Feb 09 '23 15:02 arranbartish