public Mono<List<JWK>> get(JWKSelector jwkSelector) { return this.cachedJWKSet.get() .switchIfEmpty(getJWKSet()) .flatMap(jwkSet -> get(jwkSelector, jwkSet)) .switchIfEmpty(getJWKSet().map(jwkSet -> jwkSelector.select(jwkSet))); }
@Test public void getWhenNoMatchAndNoKeyIdThenEmpty() { when(this.matcher.matches(any())).thenReturn(false); when(this.matcher.getKeyIDs()).thenReturn(Collections.emptySet()); assertThat(this.source.get(this.selector).block()).isEmpty(); }
public Mono<List<JWK>> get(JWKSelector jwkSelector) { return this.cachedJWKSet.get() .switchIfEmpty(getJWKSet()) .flatMap(jwkSet -> get(jwkSelector, jwkSet)) .switchIfEmpty(getJWKSet().map(jwkSet -> jwkSelector.select(jwkSet))); }
@Test public void getWhenNoMatchAndKeyIdMatchThenEmpty() { when(this.matcher.matches(any())).thenReturn(false); when(this.matcher.getKeyIDs()).thenReturn(Collections.singleton("7ddf54d3032d1f0d48c3618892ca74c1ac30ad77")); assertThat(this.source.get(this.selector).block()).isEmpty(); } }
@Test public void getWhenNoMatchAndKeyIdNotMatchThenRefreshAndFoundThenFound() { this.server.enqueue(new MockResponse().setBody(this.keys2)); when(this.matcher.matches(any())).thenReturn(false, false, true); when(this.matcher.getKeyIDs()).thenReturn(Collections.singleton("rotated")); List<JWK> keys = this.source.get(this.selector).block(); assertThat(keys).hasSize(1); assertThat(keys.get(0).getKeyID()).isEqualTo("rotated"); }
@Test public void getWhenNoMatchAndKeyIdNotMatchThenRefreshAndNotFoundThenEmpty() { this.server.enqueue(new MockResponse().setBody(this.keys2)); when(this.matcher.matches(any())).thenReturn(false, false, false); when(this.matcher.getKeyIDs()).thenReturn(Collections.singleton("rotated")); List<JWK> keys = this.source.get(this.selector).block(); assertThat(keys).isEmpty(); }
@Test public void getWhenMatchThenCreatesKeys() { when(this.matcher.matches(any())).thenReturn(true); List<JWK> keys = this.source.get(this.selector).block(); assertThat(keys).hasSize(2); JWK key1 = keys.get(0); assertThat(key1.getKeyID()).isEqualTo("1923397381d9574bb873202a90c32b7ceeaed027"); assertThat(key1.getAlgorithm().getName()).isEqualTo("RS256"); assertThat(key1.getKeyType()).isEqualTo(KeyType.RSA); assertThat(key1.getKeyUse()).isEqualTo(KeyUse.SIGNATURE); JWK key2 = keys.get(1); assertThat(key2.getKeyID()).isEqualTo("7ddf54d3032d1f0d48c3618892ca74c1ac30ad77"); assertThat(key2.getAlgorithm().getName()).isEqualTo("RS256"); assertThat(key2.getKeyType()).isEqualTo(KeyType.RSA); assertThat(key2.getKeyUse()).isEqualTo(KeyUse.SIGNATURE); }