use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.
the class BasicAuthFunctionalTest method shouldNotBeAbleToUseCliWithInvalidPassword.
@Test
public void shouldNotBeAbleToUseCliWithInvalidPassword() {
// Given:
final BasicCredentials wrongPassword = BasicCredentials.of(USER_NO_ACCESS.username(), "wrong");
// Then:
assertThat(canMakeCliRequest(wrongPassword), is(ERROR_CODE_UNAUTHORIZED));
}
use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.
the class HighAvailabilityTestUtil method waitForStreamsMetadataToInitialize.
static void waitForStreamsMetadataToInitialize(final TestKsqlRestApp restApp, List<KsqlHostInfoEntity> hosts, final Optional<BasicCredentials> credentials) {
while (true) {
ClusterStatusResponse clusterStatusResponse = HighAvailabilityTestUtil.sendClusterStatusRequest(restApp, credentials);
List<KsqlHostInfoEntity> initialized = hosts.stream().filter(hostInfo -> Optional.ofNullable(clusterStatusResponse.getClusterStatus().get(hostInfo)).map(hostStatusEntity -> hostStatusEntity.getActiveStandbyPerQuery().isEmpty()).isPresent()).collect(Collectors.toList());
if (initialized.size() == hosts.size())
break;
}
try {
Thread.sleep(200);
} catch (final Exception e) {
// Meh
}
}
use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.
the class RestIntegrationTestUtil method rawRestRequest.
static VertxCompletableFuture<Void> rawRestRequest(final TestKsqlRestApp restApp, final HttpVersion httpVersion, final HttpMethod method, final String uri, final Object requestBody, final String mediaType, final Consumer<Buffer> chunkConsumer, final Optional<BasicCredentials> credentials) {
final byte[] bytes;
try {
bytes = ApiJsonMapper.INSTANCE.get().writeValueAsBytes(requestBody);
} catch (Exception e) {
throw new RuntimeException(e);
}
HttpClientOptions options = new HttpClientOptions().setDefaultPort(restApp.getHttpListener().getPort()).setDefaultHost(restApp.getHttpListener().getHost()).setVerifyHost(false);
if (httpVersion == HttpVersion.HTTP_2) {
options.setProtocolVersion(HttpVersion.HTTP_2);
}
final Vertx vertx = Vertx.vertx();
final HttpClient httpClient = vertx.createHttpClient(options);
final VertxCompletableFuture<Void> vcf = new VertxCompletableFuture<>();
final HttpClientRequest httpClientRequest = httpClient.request(method, uri, resp -> {
resp.handler(buffer -> {
try {
chunkConsumer.accept(buffer);
} catch (final Throwable t) {
vcf.completeExceptionally(t);
}
});
resp.endHandler(v -> {
chunkConsumer.accept(null);
vcf.complete(null);
});
}).exceptionHandler(vcf::completeExceptionally);
httpClientRequest.putHeader("Accept", mediaType);
credentials.ifPresent(basicCredentials -> httpClientRequest.putHeader("Authorization", createBasicAuthHeader(basicCredentials)));
Buffer bodyBuffer = Buffer.buffer(bytes);
httpClientRequest.end(bodyBuffer);
// cleanup
vcf.handle((v, throwable) -> {
httpClient.close();
vertx.close();
return null;
});
return vcf;
}
use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.
the class TestKsqlRestApp method closePersistentQueries.
public void closePersistentQueries(final Optional<BasicCredentials> credentials) {
try (final KsqlRestClient client = buildKsqlClient(credentials)) {
// Filter source tables queries because they cannot be terminated manually
final Set<String> queriesToTerminate = getPersistentQueries(client).stream().filter(query -> !query.getQueryString().startsWith("CREATE SOURCE TABLE")).map(RunningQuery::getId).map(QueryId::toString).collect(Collectors.toSet());
terminateQueries(queriesToTerminate, client);
}
}
use of io.confluent.ksql.rest.client.BasicCredentials in project ksql by confluentinc.
the class BasicAuthFunctionalTest method shouldNotBeAbleToUseWsWithInvalidPassword.
@Test
public void shouldNotBeAbleToUseWsWithInvalidPassword() throws Exception {
// Given:
final BasicCredentials wrongPassword = BasicCredentials.of(USER_NO_ACCESS.username(), "wrong");
// Then:
assertThat(makeWsRequest(Optional.of(wrongPassword)), is(UNAUTHORIZED.code()));
}
Aggregations