|
| 1 | +package uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions |
| 2 | + |
| 3 | +import jakarta.servlet.FilterChain |
| 4 | +import jakarta.servlet.http.HttpServletRequest |
| 5 | +import jakarta.servlet.http.HttpServletResponse |
| 6 | +import org.junit.jupiter.api.Test |
| 7 | +import org.mockito.Mockito.mock |
| 8 | +import org.mockito.Mockito.times |
| 9 | +import org.mockito.Mockito.verify |
| 10 | +import org.mockito.kotlin.whenever |
| 11 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.config.AuthorisationConfig |
| 12 | + |
| 13 | +class ConsumerNameExtractionFilterTest { |
| 14 | + private var authorisationConfig: AuthorisationConfig = AuthorisationConfig() |
| 15 | + private var consumerNameExtractionFilter: ConsumerNameExtractionFilter = ConsumerNameExtractionFilter() |
| 16 | + |
| 17 | + @Test |
| 18 | + fun `calls the onward chain`() { |
| 19 | + // Arrange |
| 20 | + val mockRequest = mock(HttpServletRequest::class.java) |
| 21 | + whenever(mockRequest.getAttribute("clientName")).thenReturn("consumer-name") |
| 22 | + |
| 23 | + val mockResponse = mock(HttpServletResponse::class.java) |
| 24 | + val mockChain = mock(FilterChain::class.java) |
| 25 | + |
| 26 | + // Act |
| 27 | + consumerNameExtractionFilter.doFilter(mockRequest, mockResponse, mockChain) |
| 28 | + |
| 29 | + // Assert |
| 30 | + verify(mockChain, times(1)).doFilter(mockRequest, mockResponse) |
| 31 | + } |
| 32 | + |
| 33 | +// @Test |
| 34 | +// fun `can get subject distinguished name from request and set as consumer name `() { |
| 35 | +// // Arrange |
| 36 | +// val mockRequest = mock(HttpServletRequest::class.java) |
| 37 | +// whenever(mockRequest.getHeader("subject-distinguished-name")).thenReturn("CN=consumer-name")) |
| 38 | +// whenever(mockRequest.getAttribute("clientName")).thenReturn("consumer-name") |
| 39 | +// |
| 40 | +// val mockResponse = mock(HttpServletResponse::class.java) |
| 41 | +// val mockChain = mock(FilterChain::class.java) |
| 42 | +// |
| 43 | +// // Act |
| 44 | +// consumerNameExtractionFilter.doFilter(mockRequest, mockResponse, mockChain) |
| 45 | +// |
| 46 | +// // Assert |
| 47 | +// verify(mockRequest, times(1)).setAttribute("client-name", "consumer-name") |
| 48 | +// } |
| 49 | +} |
0 commit comments