Search in sources :

Example 1 with Auth

use of io.etcd.jetcd.Auth in project jetcd by coreos.

the class ClientConnectionManagerTest method testAuthHeaders.

@Test
public void testAuthHeaders() throws InterruptedException, ExecutionException {
    final CountDownLatch latch = new CountDownLatch(1);
    Auth authClient = TestUtil.client(cluster).build().getAuthClient();
    authClient.userAdd(root, rootPass).get();
    ByteSequence role = TestUtil.bytesOf("root");
    authClient.userGrantRole(root, role).get();
    authClient.authEnable().get();
    final ClientBuilder builder = TestUtil.client(cluster).authHeader("MyAuthHeader", "MyAuthHeaderVal").header("MyHeader2", "MyHeaderVal2").user(root).password(rootPass);
    assertThat(builder.authHeaders().get(Metadata.Key.of("MyAuthHeader", Metadata.ASCII_STRING_MARSHALLER))).isEqualTo("MyAuthHeaderVal");
    try (Client client = builder.build()) {
        CompletableFuture<AuthDisableResponse> future = client.getAuthClient().authDisable();
        latch.await(10, TimeUnit.SECONDS);
        future.get();
    }
    authClient.userRevokeRole(root, role).get();
    authClient.userDelete(root).get();
}
Also used : Auth(io.etcd.jetcd.Auth) CountDownLatch(java.util.concurrent.CountDownLatch) Client(io.etcd.jetcd.Client) ByteSequence(io.etcd.jetcd.ByteSequence) ClientBuilder(io.etcd.jetcd.ClientBuilder) AuthDisableResponse(io.etcd.jetcd.auth.AuthDisableResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Auth (io.etcd.jetcd.Auth)1 ByteSequence (io.etcd.jetcd.ByteSequence)1 Client (io.etcd.jetcd.Client)1 ClientBuilder (io.etcd.jetcd.ClientBuilder)1 AuthDisableResponse (io.etcd.jetcd.auth.AuthDisableResponse)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.jupiter.api.Test)1