Beispiel #1
0
        public void ShouldNotThrowExceptionWhenDisposingMultipleTimes()
        {
            // given
            var zeebeClient = ZeebeClient.Builder()
                              .UseGatewayAddress("localhost:26500")
                              .UsePlainText()
                              .Build();

            // when
            zeebeClient.Dispose();

            // then
            Assert.DoesNotThrow(() => zeebeClient.Dispose());
        }
 /// <summary>
 /// Adds the Zeebe builders to the IServiceCollection
 /// </summary>
 /// <param name="services">the collection where the zeebe services are appended</param>
 /// <returns>the service collection</returns>
 public static IServiceCollection AddZeebeBuilders(this IServiceCollection services)
 {
     services.AddTransient(serviceProvider =>
     {
         var loggerFactory = serviceProvider.GetService <ILoggerFactory>();
         return(ZeebeClient.Builder().UseLoggerFactory(loggerFactory));
     });
     services.AddTransient(serviceProvider =>
     {
         var loggerFactory = serviceProvider.GetService <ILoggerFactory>();
         return(CamundaCloudTokenProvider.Builder().UseLoggerFactory(loggerFactory));
     });
     return(services);
 }
Beispiel #3
0
        public async Task ShouldFailOnWrongCert()
        {
            // given
            GrpcEnvironment.SetLogger(new ConsoleLogger());

            var keyCertificatePairs = new List <KeyCertificatePair>();
            var serverCert          = File.ReadAllText(ServerCertPath);

            keyCertificatePairs.Add(new KeyCertificatePair(serverCert, File.ReadAllText(ServerKeyPath)));
            var channelCredentials = new SslServerCredentials(keyCertificatePairs);

            var server = new Server();

            server.Ports.Add(new ServerPort("0.0.0.0", 26505, channelCredentials));

            var testService       = new GatewayTestService();
            var serviceDefinition = Gateway.BindService(testService);

            server.Services.Add(serviceDefinition);
            server.Start();


            // client
            var zeebeClient = ZeebeClient.Builder()
                              .UseGatewayAddress("0.0.0.0:26505")
                              .UseTransportEncryption(WrongCertPath)
                              .Build();

            // when
            try
            {
                await zeebeClient
                .NewPublishMessageCommand()
                .MessageName("messageName")
                .CorrelationKey("p-1")
                .Send();

                Assert.Fail();
            }
            catch (RpcException rpcException)
            {
                // expected
                Assert.AreEqual(rpcException.Status.StatusCode, StatusCode.Unavailable);
            }
        }
Beispiel #4
0
        public async Task ShouldUseAccessTokenSupplier()
        {
            // given
            GrpcEnvironment.SetLogger(new ConsoleLogger());

            var keyCertificatePairs = new List <KeyCertificatePair>();
            var serverCert          = File.ReadAllText(ServerCertPath);

            keyCertificatePairs.Add(new KeyCertificatePair(serverCert, File.ReadAllText(ServerKeyPath)));
            var channelCredentials = new SslServerCredentials(keyCertificatePairs);

            var server = new Server();

            server.Ports.Add(new ServerPort("0.0.0.0", 26505, channelCredentials));

            var testService       = new GatewayTestService();
            var serviceDefinition = Gateway.BindService(testService);

            server.Services.Add(serviceDefinition);
            server.Start();


            // client
            var accessTokenSupplier = new SimpleAccessTokenSupplier();
            var zeebeClient         = ZeebeClient.Builder()
                                      .UseGatewayAddress("0.0.0.0:26505")
                                      .UseTransportEncryption(ClientCertPath)
                                      .UseAccessTokenSupplier(accessTokenSupplier)
                                      .Build();

            // when
            await zeebeClient.TopologyRequest().Send();

            await zeebeClient.TopologyRequest().Send();

            var topology = await zeebeClient.TopologyRequest().Send();

            // then
            Assert.NotNull(topology);
            Assert.AreEqual(3, accessTokenSupplier.Count);
        }
Beispiel #5
0
        public void ShouldThrowExceptionAfterDispose()
        {
            // given
            var zeebeClient = ZeebeClient.Builder()
                              .UseGatewayAddress("localhost:26500")
                              .UsePlainText()
                              .Build();

            // when
            zeebeClient.Dispose();

            // then
            var aggregateException = Assert.Throws <AggregateException>(
                () => zeebeClient.TopologyRequest().Send().Wait());

            Assert.AreEqual(1, aggregateException.InnerExceptions.Count);

            var catchedExceptions = aggregateException.InnerExceptions[0];

            Assert.IsTrue(catchedExceptions.Message.Contains("ZeebeClient was already disposed."));
            Assert.IsInstanceOf(typeof(ObjectDisposedException), catchedExceptions);
        }
Beispiel #6
0
        public async Task ShouldUseTransportEncryptionWithServerCert()
        {
            // given
            GrpcEnvironment.SetLogger(new ConsoleLogger());

            var keyCertificatePairs = new List <KeyCertificatePair>();
            var serverCert          = File.ReadAllText(ServerCertPath);

            keyCertificatePairs.Add(new KeyCertificatePair(serverCert, File.ReadAllText(ServerKeyPath)));
            var channelCredentials = new SslServerCredentials(keyCertificatePairs);

            var server = new Server();

            server.Ports.Add(new ServerPort("0.0.0.0", 26505, channelCredentials));

            var testService       = new GatewayTestService();
            var serviceDefinition = Gateway.BindService(testService);

            server.Services.Add(serviceDefinition);
            server.Start();


            // client
            var zeebeClient = ZeebeClient.Builder()
                              .UseGatewayAddress("0.0.0.0:26505")
                              .UseTransportEncryption(ServerCertPath)
                              .Build();

            // when
            var publishMessageResponse = await zeebeClient
                                         .NewPublishMessageCommand()
                                         .MessageName("messageName")
                                         .CorrelationKey("p-1")
                                         .Send();

            // then
            Assert.NotNull(publishMessageResponse);
        }