Ejemplo n.º 1
0
        public void TestTlsClientAuthOverBinaryProtocol()
        {
            _output.WriteLine($"-- Starting 'TestTlsClientAuthOverBinaryProtocol' test --");

            InternalSetUpForNamespace();

            // Test 1 - Using TLS on binary protocol without sending certs - expect failure
            InternalSetUpForClient(false, "pulsar.BrokerServiceUrlTls");
            try
            {
                _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsClientAuthOverBinaryProtocol", "my-subscriber-name")); //pulsarClient.newConsumer().topic("persistent://my-property/use/my-ns/my-topic1").subscriptionName("my-subscriber-name").subscriptionType(SubscriptionType.Exclusive).subscribe();
                //Assert.fail("Server should have failed the TLS handshake since client didn't .");
            }
            catch (Exception)
            {
                // OK
            }

            // Test 2 - Using TLS on binary protocol - sending certs
            InternalSetUpForClient(true, "pulsar.BrokerServiceUrlTls");
            try
            {
                _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsClientAuthOverBinaryProtocol", "my-subscriber-name")); //pulsarClient.newConsumer().topic("persistent://my-property/use/my-ns/my-topic1").subscriptionName("my-subscriber-name").subscriptionType(SubscriptionType.Exclusive).subscribe();
            }
            catch (Exception)
            {
                //Assert.fail("Should not fail since certs are sent.");
            }
        }
Ejemplo n.º 2
0
        public void TestTlsCertsFromDynamicStreamExpiredAndRenewCert()
        {
            AtomicInteger       certIndex    = new AtomicInteger(1);
            AtomicInteger       keyIndex     = new AtomicInteger(0);
            MemoryStream        certStream   = CreateByteInputStream(TlsClientCertFilePath);
            MemoryStream        keyStream    = CreateByteInputStream(TlsClientKeyFilePath);
            Func <MemoryStream> certProvider = () => GetStream(certIndex, certStream, keyStream);
            Func <MemoryStream> keyProvider  = () => GetStream(keyIndex, keyStream);
            AuthenticationTls   auth         = new AuthenticationTls(certProvider, keyProvider);

            _common.GetPulsarSystem(auth, 1000, enableTls: true, brokerService: "pulsar.BrokerServiceUrlTls");


            _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsCertsFromDynamicStreamExpiredAndRenewCert", "my-subscriber-name"));


            certIndex.SetValue(0);
            _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsCertsFromDynamicStreamExpiredAndRenewCert", "my-subscriber-name"));
        }
Ejemplo n.º 3
0
        public void TestTlsCertsFromDynamicStream()
        {
            string topicName = "persistent://my-property/use/my-ns/my-topic1";

            AtomicInteger index = new AtomicInteger(0);

            MemoryStream certStream = CreateByteInputStream(TlsClientCertFilePath);
            MemoryStream keyStream  = CreateByteInputStream(TlsClientKeyFilePath);

            Func <MemoryStream> certProvider = () => GetStream(index, certStream);
            Func <MemoryStream> keyProvider  = () => GetStream(index, keyStream);
            AuthenticationTls   auth         = new AuthenticationTls(certProvider, keyProvider);

            _common.GetPulsarSystem(auth, 1000, enableTls: true, brokerService: "pulsar.BrokerServiceUrlTls");


            _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), topicName, "TestTlsCertsFromDynamicStream", "my-subscriber-name"));

            // unload the topic so, new connection will be made and read the cert streams again

            var producer = _common.PulsarSystem.PulsarProducer(_common.CreateProducer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", ""));

            for (int i = 0; i < 10; i++)
            {
                var send = new Send(("test" + i).GetBytes(), ImmutableDictionary <string, object> .Empty);
                _common.PulsarSystem.Send(send, producer.Producer);
            }

            ConsumedMessage msg = null;

            for (var i = 0; i < 10; i++)
            {
                msg = _common.PulsarSystem.Receive("TestTlsCertsFromDynamicStream", 5000);
                var exepctedMsg = "test" + i;
                var data        = (byte[])(object)msg.Message.Data;
                Assert.Equal(exepctedMsg.GetBytes(), data);
            }
            // Acknowledge the consumption of all messages at once
            _common.PulsarSystem.AcknowledgeCumulative(msg);
        }
Ejemplo n.º 4
0
 public void TestBytesSchemaOf()
 {
     TestBytesSchema(BytesSchema.Of());
 }
Ejemplo n.º 5
0
        public void TestTlsLargeSizeMessage()
        {
            _output.WriteLine($"-- Starting 'TestTlsLargeSizeMessage' test --");

            const int messageSize = 16 * 1024 + 1;

            InternalSetUpForClient(true, "pulsar.BrokerServiceUrlTls");
            InternalSetUpForNamespace();

            var consumer = _common.PulsarSystem.PulsarConsumer(_common.CreateConsumer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsLargeSizeMessage", "my-subscriber-name"));

            var producer = _common.PulsarSystem.PulsarProducer(_common.CreateProducer(BytesSchema.Of(), "persistent://my-property/use/my-ns/my-topic1", "TestTlsLargeSizeMessage"));

            for (int i = 0; i < 10; i++)
            {
                var message = new byte[messageSize];
                Array.Fill(message, (byte)i);
                var send = new Send(message, ImmutableDictionary <string, object> .Empty);
                _common.PulsarSystem.Send(send, producer.Producer);
            }

            ConsumedMessage msg = null;

            for (int i = 0; i < 10; i++)
            {
                msg = _common.PulsarSystem.Receive("", 5000);
                var expected = new byte[messageSize];
                Array.Fill(expected, (byte)i);
                var data = (byte[])(object)msg.Message.Data;
                Assert.Equal(expected, data);
            }
            // Acknowledge the consumption of all messages at once
            _common.PulsarSystem.AcknowledgeCumulative(msg);
            _output.WriteLine($"-- Exiting 'TestTlsLargeSizeMessage' test --");
        }