### Question:
JwtTokenRetriever { static List<JwtToken> retrieveUnvalidatedTokens(MultiIssuerConfiguration config, HttpRequest request) { return Stream.concat( getTokensFromHeader(config, request).stream(), getTokensFromCookies(config, request).stream()) .collect(Collectors.toList()); }    }### Answer:
@Test void testRetrieveTokensInHeader() throws URISyntaxException, MalformedURLException { MultiIssuerConfiguration config = new MultiIssuerConfiguration(createIssuerPropertiesMap("issuer1", "cookie1"), new NoopResourceRetriever()); String issuer1Token = createJWT("issuer1"); when(request.getHeader("Authorization")).thenReturn("Bearer " + issuer1Token); assertEquals("issuer1", JwtTokenRetriever.retrieveUnvalidatedTokens(config, request).get(0).getIssuer()); }
@Test void testRetrieveTokensInHeaderIssuerNotConfigured() throws URISyntaxException, MalformedURLException { MultiIssuerConfiguration config = new MultiIssuerConfiguration(createIssuerPropertiesMap("issuer1", "cookie1"), new NoopResourceRetriever()); String issuer1Token = createJWT("issuerNotConfigured"); when(request.getHeader("Authorization")).thenReturn("Bearer " + issuer1Token); assertEquals(0, JwtTokenRetriever.retrieveUnvalidatedTokens(config, request).size()); }
@Test void testRetrieveTokensInCookie() throws URISyntaxException, MalformedURLException { MultiIssuerConfiguration config = new MultiIssuerConfiguration(createIssuerPropertiesMap("issuer1", "cookie1"), new NoopResourceRetriever()); String issuer1Token = createJWT("issuer1"); when(request.getCookies()).thenReturn(new Cookie[] { new Cookie("cookie1", issuer1Token) }); assertEquals("issuer1", JwtTokenRetriever.retrieveUnvalidatedTokens(config, request).get(0).getIssuer()); }
@Test void testRetrieveTokensWhenCookieNameNotConfigured() throws URISyntaxException, MalformedURLException { MultiIssuerConfiguration config = new MultiIssuerConfiguration(createIssuerPropertiesMap("issuer1", null), new NoopResourceRetriever()); String issuer1Token = createJWT("issuer1"); when(request.getCookies()).thenReturn(new Cookie[] { new Cookie("cookie1", "somerandomcookie") }); when(request.getHeader("Authorization")).thenReturn("Bearer " + issuer1Token); assertEquals("issuer1", JwtTokenRetriever.retrieveUnvalidatedTokens(config, request).get(0).getIssuer()); }
@Test void testRetrieveTokensMultipleIssuersWithSameCookieName() throws URISyntaxException, MalformedURLException { Map<String, IssuerProperties> issuerPropertiesMap = createIssuerPropertiesMap("issuer1", "cookie1"); issuerPropertiesMap.putAll(createIssuerPropertiesMap("issuer2", "cookie1")); MultiIssuerConfiguration config = new MultiIssuerConfiguration(issuerPropertiesMap, new NoopResourceRetriever()); String issuer1Token = createJWT("issuer1"); when(request.getCookies()).thenReturn(new Cookie[] { new Cookie("cookie1", issuer1Token) }); assertEquals(1, JwtTokenRetriever.retrieveUnvalidatedTokens(config, request).size()); assertEquals("issuer1", JwtTokenRetriever.retrieveUnvalidatedTokens(config, request).get(0).getIssuer()); }