Search in sources :

Example 6 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class DelegationTokenTest method testBatchClientDelegationTokenRenewal.

/**
 * This test verifies that a batch client continues to read events as a result of automatic delegation token
 * renewal, after the initial delegation token it uses expires.
 * <p>
 * We use an extraordinarily high test timeout and read timeouts to account for any inordinate delays that may be
 * encountered in testing environments.
 */
@Test(timeout = 50000)
public void testBatchClientDelegationTokenRenewal() throws InterruptedException {
    // Delegation token renewal threshold is 5 seconds, so we are using 6 seconds as Token TTL so that token doesn't
    // get renewed before each use.
    @Cleanup ClusterWrapper pravegaCluster = ClusterWrapper.builder().authEnabled(true).tokenTtlInSeconds(6).build();
    pravegaCluster.start();
    final String scope = "testscope";
    final String streamName = "teststream";
    final ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(pravegaCluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build();
    log.debug("Done creating client config.");
    // Create Scope and Stream.
    createScopeStream(scope, streamName, 1, clientConfig);
    // write ten Events.
    writeTenEvents(scope, streamName, clientConfig);
    // Now, read the events from the stream using Batch client.
    @Cleanup BatchClientFactory batchClientFactory = BatchClientFactory.withScope(scope, clientConfig);
    List<SegmentRange> segmentRanges = Lists.newArrayList(batchClientFactory.getSegments(Stream.of(scope, streamName), StreamCut.UNBOUNDED, StreamCut.UNBOUNDED).getIterator());
    assertEquals("The number of segments in the stream is 1", 1, segmentRanges.size());
    SegmentIterator<String> segmentIterator = batchClientFactory.readSegment(segmentRanges.get(0), new JavaSerializer<>());
    int eventReadCount = 0;
    while (segmentIterator.hasNext()) {
        // We are keeping sleep time relatively large, just to make sure that the delegation token expires
        // midway.
        Thread.sleep(500);
        String event = segmentIterator.next();
        log.debug("Done reading event {}", event);
        eventReadCount++;
    }
    // Assert that we end up reading 10 events even though delegation token must have expired midway.
    // 
    // To look for evidence of delegation token renewal check the logs for the following message:
    // - "Token is nearing expiry, so refreshing it"
    assertEquals(10, eventReadCount);
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) SegmentRange(io.pravega.client.batch.SegmentRange) ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) BatchClientFactory(io.pravega.client.BatchClientFactory) ClientConfig(io.pravega.client.ClientConfig) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 7 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class ControllerGrpcListStreamsTest method testListStreamsReturnsAuthorizedStreamsOnly.

@Test
public void testListStreamsReturnsAuthorizedStreamsOnly() {
    // Arrange
    Map<String, String> passwordInputFileEntries = new HashMap<>();
    passwordInputFileEntries.put("admin", "prn::*,READ_UPDATE");
    passwordInputFileEntries.put("user", "prn::/scope:scope1,READ;prn::/scope:scope1/stream:stream1,READ");
    @Cleanup ClusterWrapper cluster = ClusterWrapper.builder().authEnabled(true).passwordAuthHandlerEntries(this.preparePasswordInputFileEntries(passwordInputFileEntries)).build();
    cluster.start();
    String scopeName = "scope1";
    this.createStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build(), scopeName, Arrays.asList("stream1", "stream2", "stream3"));
    // Act
    Set<Stream> streams = listStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "user")).build(), scopeName);
    // Assert
    assertEquals(1, streams.size());
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) HashMap(java.util.HashMap) ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) Stream(io.pravega.client.stream.Stream) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 8 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class ControllerGrpcListStreamsTest method testListStreamsReturnsAllStreamsWhenAuthIsDisabled.

@Test
public void testListStreamsReturnsAllStreamsWhenAuthIsDisabled() {
    // Arrange
    @Cleanup ClusterWrapper cluster = ClusterWrapper.builder().build();
    cluster.start();
    String scopeName = "test-scope";
    ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).build();
    this.createStreams(clientConfig, scopeName, Arrays.asList("stream1", "stream2"));
    // Act
    Set<Stream> streams = listStreams(clientConfig, scopeName);
    // Assert
    assertEquals(4, streams.size());
}
Also used : ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) Stream(io.pravega.client.stream.Stream) ClientConfig(io.pravega.client.ClientConfig) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 9 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class ControllerGrpcListStreamsTest method testListStreamsReturnsAuthorizedStreamsForCustomPlugin.

@Test
public void testListStreamsReturnsAuthorizedStreamsForCustomPlugin() {
    ClusterWrapper cluster = null;
    try {
        // Arrange
        cluster = ClusterWrapper.builder().authEnabled(true).build();
        cluster.start();
        String scopeName = "test-scope";
        this.createStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build(), scopeName, Arrays.asList("stream1", "stream2"));
        // Act
        System.setProperty("pravega.client.auth.loadDynamic", "true");
        System.setProperty("pravega.client.auth.method", TestAuthHandler.METHOD);
        System.setProperty("pravega.client.auth.token", TestAuthHandler.TOKEN);
        Set<Stream> streams = listStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).build(), scopeName);
        // Assert
        assertEquals(4, streams.size());
    } finally {
        System.clearProperty("pravega.client.auth.loadDynamic");
        System.clearProperty("pravega.client.auth.method");
        System.clearProperty("pravega.client.auth.token");
        if (cluster != null) {
            cluster.close();
        }
    }
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) Stream(io.pravega.client.stream.Stream) Test(org.junit.Test)

Example 10 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class ControllerGrpcListStreamsTest method testListStreamsReturnsAllStreamsForPrivilegedUserWhenAuthIsEnabled.

@Test
public void testListStreamsReturnsAllStreamsForPrivilegedUserWhenAuthIsEnabled() {
    // Arrange
    @Cleanup ClusterWrapper cluster = ClusterWrapper.builder().authEnabled(true).tokenTtlInSeconds(600).build();
    cluster.start();
    String scopeName = "test-scope";
    ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build();
    this.createStreams(clientConfig, scopeName, Arrays.asList("stream1", "stream2"));
    // Act
    Set<Stream> streams = listStreams(clientConfig, scopeName);
    // Assert
    assertEquals(4, streams.size());
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) Stream(io.pravega.client.stream.Stream) ClientConfig(io.pravega.client.ClientConfig) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

ClusterWrapper (io.pravega.test.integration.demo.ClusterWrapper)12 Cleanup (lombok.Cleanup)11 ClientConfig (io.pravega.client.ClientConfig)10 Test (org.junit.Test)10 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)9 Stream (io.pravega.client.stream.Stream)4 HashMap (java.util.HashMap)4 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)3 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)2 SneakyThrows (lombok.SneakyThrows)2 BatchClientFactory (io.pravega.client.BatchClientFactory)1 SegmentRange (io.pravega.client.batch.SegmentRange)1 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)1 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)1 KeyStore (java.security.KeyStore)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 Invocation (javax.ws.rs.client.Invocation)1 WebTarget (javax.ws.rs.client.WebTarget)1