@Test public void nullScenarioEmpty() { assertThat(new ErrorFormatter(null).scenarioPrefix) .isNotNull() .isEmpty(); }
@Test public void testGeodeLogLevel() { when(parseResult.getParamValueAsString("log-level")).thenReturn("fine"); when(parseResult.getParamValueAsString("loglevel")).thenReturn("fine"); for (AbstractCliAroundInterceptor interceptor : interceptors) { result = (Result) interceptor.preExecution(parseResult); assertThat(result.nextLine()).isEmpty(); } }
@Test public void testLog4JLevel() { when(parseResult.getParamValueAsString("log-level")).thenReturn("trace"); when(parseResult.getParamValueAsString("loglevel")).thenReturn("trace"); for (AbstractCliAroundInterceptor interceptor : interceptors) { result = (Result) interceptor.preExecution(parseResult); assertThat(result.nextLine()).isEmpty(); } } }
@Test public void noScenarioEmpty() { assertThat(new ErrorFormatter("").scenarioPrefix) .isNotNull() .isEmpty(); }
@Test public void onDeleteSessionMulti() { this.resolver.expireSession(this.request, this.response); this.resolver.expireSession(this.request, this.response); assertThat(this.response.getHeaders(HEADER_X_AUTH_TOKEN).size()).isEqualTo(1); assertThat(getSessionId()).isEmpty(); }
@Test public void onDeleteSession() { this.resolver.expireSession(this.request, this.response); assertThat(getSessionId()).isEmpty(); }
@Test public void onDeleteSession() throws Exception { this.strategy.expireSession(this.request, this.response); assertThat(getSessionId()).isEmpty(); }
@Test public void testDefineNullDoesntWriteToStderr() { assertThat(h.createQuery("select true<if(defined)>broken<endif>") .define("defined", null) .mapTo(boolean.class) .findOnly()) .isEqualTo(true); assertThat(err.toString()).isEmpty(); } }
@Test public void testStartEnd() { when(parseResult.getParamValueAsString("start-time")).thenReturn("2000/01/01"); when(parseResult.getParamValueAsString("end-time")).thenReturn("2000/01/02"); result = interceptor.preExecution(parseResult); assertThat(result.nextLine()).isEmpty(); when(parseResult.getParamValueAsString("start-time")).thenReturn("2000/01/02"); when(parseResult.getParamValueAsString("end-time")).thenReturn("2000/01/01"); result = interceptor.preExecution(parseResult); assertThat(result.nextLine()).contains("start-time has to be earlier than end-time"); }
@Test public void testInclideStats() { when(parseResult.getParamValue("logs-only")).thenReturn(true); when(parseResult.getParamValue("stats-only")).thenReturn(false); result = interceptor.preExecution(parseResult); assertThat(result.nextLine()).isEmpty(); when(parseResult.getParamValue("logs-only")).thenReturn(true); when(parseResult.getParamValue("stats-only")).thenReturn(true); result = interceptor.preExecution(parseResult); assertThat(result.nextLine()).contains("logs-only and stats-only can't both be true"); } }
@Test public void shouldNotSetConfigurationWhenArtifactIdIsNotProvided() { final HashMap<Object, Object> configAttrs = new HashMap<>(); configAttrs.put(FetchPluggableArtifactTask.ARTIFACT_ID, ""); configAttrs.put(FetchPluggableArtifactTask.CONFIGURATION, Collections.singletonMap("NAME", "gocd.zip")); FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}"); task.setFetchTaskAttributes(configAttrs); Assertions.assertThat(task.getArtifactId()).isEmpty(); Assertions.assertThat(task.getConfiguration()).isEmpty(); } }
@Test public void filterWhenDefaultClientRegistrationIdThenAuthorizedClientResolved() { this.function.setDefaultClientRegistrationId(this.registration.getRegistrationId()); OAuth2RefreshToken refreshToken = new OAuth2RefreshToken("refresh-token", this.accessToken.getIssuedAt()); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, refreshToken); when(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).thenReturn(Mono.just(authorizedClient)); when(this.clientRegistrationRepository.findByRegistrationId(any())).thenReturn(Mono.just(this.registration)); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void filterWhenClientRegistrationIdThenAuthorizedClientResolved() { OAuth2RefreshToken refreshToken = new OAuth2RefreshToken("refresh-token", this.accessToken.getIssuedAt()); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, refreshToken); when(this.authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).thenReturn(Mono.just(authorizedClient)); when(this.clientRegistrationRepository.findByRegistrationId(any())).thenReturn(Mono.just(this.registration)); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(clientRegistrationId(this.registration.getRegistrationId())) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void filterWhenRefreshTokenNullThenShouldRefreshFalse() { OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void filterWhenRefreshTokenNullThenShouldRefreshFalse() { this.function = new ServletOAuth2AuthorizedClientExchangeFilterFunction(this.clientRegistrationRepository, this.authorizedClientRepository); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void filterWhenNotExpiredThenShouldRefreshFalse() { OAuth2RefreshToken refreshToken = new OAuth2RefreshToken("refresh-token", this.accessToken.getIssuedAt()); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, refreshToken); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void onDeleteSessionCustomCookieName() throws Exception { setCookieName("CUSTOM"); this.strategy.expireSession(this.request, this.response); assertThat(getSessionId()).isEmpty(); }
@Test public void filterWhenClientCredentialsTokenNotExpiredThenUseCurrentToken() { this.registration = TestClientRegistrations.clientCredentials().build(); this.function = new ServletOAuth2AuthorizedClientExchangeFilterFunction(this.clientRegistrationRepository, this.authorizedClientRepository); this.function.setClientCredentialsTokenResponseClient(this.clientCredentialsTokenResponseClient); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, null); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .attributes(authentication(this.authentication)) .build(); this.function.filter(request, this.exchange).block(); verify(this.authorizedClientRepository, never()).saveAuthorizedClient(any(), eq(this.authentication), any(), any()); verify(clientCredentialsTokenResponseClient, never()).getTokenResponse(any()); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request1 = requests.get(0); assertThat(request1.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request1.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request1.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request1)).isEmpty(); }
@Test public void filterWhenNotExpiredThenShouldRefreshFalse() { this.function = new ServletOAuth2AuthorizedClientExchangeFilterFunction(this.clientRegistrationRepository, this.authorizedClientRepository); OAuth2RefreshToken refreshToken = new OAuth2RefreshToken("refresh-token", this.accessToken.getIssuedAt()); OAuth2AuthorizedClient authorizedClient = new OAuth2AuthorizedClient(this.registration, "principalName", this.accessToken, refreshToken); ClientRequest request = ClientRequest.create(GET, URI.create("https://example.com")) .attributes(oauth2AuthorizedClient(authorizedClient)) .build(); this.function.filter(request, this.exchange).block(); List<ClientRequest> requests = this.exchange.getRequests(); assertThat(requests).hasSize(1); ClientRequest request0 = requests.get(0); assertThat(request0.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer token-0"); assertThat(request0.url().toASCIIString()).isEqualTo("https://example.com"); assertThat(request0.method()).isEqualTo(HttpMethod.GET); assertThat(getBody(request0)).isEmpty(); }
@Test public void shouldReturnEchoResponse() { final ArmeriaReactiveWebServerFactory factory = factory(); runEchoServer(factory, server -> { final HttpClient client = httpClient(server); validateEchoResponse(sendPostRequest(client)); final AggregatedHttpMessage res = client.get("/hello").aggregate().join(); assertThat(res.status()).isEqualTo(com.linecorp.armeria.common.HttpStatus.OK); assertThat(res.content().toStringUtf8()).isEmpty(); }); }