public void connection_string_with_invalid_settings_should_throw()
        {
            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?unknown=1234");
            });

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts=1234&hello=test");
            });

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts=abcd");
            });

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?discoveryInterval=abcd");
            });

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?gossipTimeout=defg");
            });

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?tlsVerifyCert=truee");
            });

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?nodePreference=blabla");
            });
        }
 public void connection_string_with_empty_path_after_host_should_not_throw()
 {
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1");
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:1234");
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/");
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1?maxDiscoverAttempts=10");
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts=10");
 }
        public void connection_string_with_duplicate_key_should_throw()
        {
            Assert.Throws <DuplicateKeyException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts=1234&MaxDiscoverAttempts=10");
            });

            Assert.Throws <DuplicateKeyException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?gossipTimeout=10&gossipTimeout=30");
            });
        }
        public void connection_string_with_invalid_key_value_pair_should_throw()
        {
            Assert.Throws <InvalidKeyValuePairException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts=12=34");
            });

            Assert.Throws <InvalidKeyValuePairException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts1234");
            });
        }
        public void with_different_node_preferences()
        {
            Assert.Equal(NodePreference.Leader, EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?nodePreference=leader").ConnectivitySettings.NodePreference);
            Assert.Equal(NodePreference.Follower, EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?nodePreference=Follower").ConnectivitySettings.NodePreference);
            Assert.Equal(NodePreference.Random, EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?nodePreference=rAndom").ConnectivitySettings.NodePreference);
            Assert.Equal(NodePreference.ReadOnlyReplica, EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?nodePreference=ReadOnlyReplica").ConnectivitySettings.NodePreference);

            Assert.Throws <InvalidSettingException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?nodePreference=invalid");
            });
        }
        public void connection_string_with_invalid_scheme_should_throw()
        {
            Assert.Throws <InvalidSchemeException>(() => {
                EventStoreClientSettings.Create("esdbwrong://");
            });

            Assert.Throws <InvalidSchemeException>(() => {
                EventStoreClientSettings.Create("wrong://");
            });

            Assert.Throws <InvalidSchemeException>(() => {
                EventStoreClientSettings.Create("badesdb://");
            });
        }
Example #7
0
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            Settings = clientSettings ?? EventStoreClientSettings.Create(ConnectionString);

            Settings.OperationOptions.TimeoutAfter = Debugger.IsAttached
                                ? new TimeSpan?()
                                : TimeSpan.FromSeconds(30);

#if GRPC_CORE
            Settings.ChannelCredentials ??= GetServerCertificate();
        public void connection_string_with_non_empty_path_should_throw()
        {
            Assert.Throws <ConnectionStringParseException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/test");
            });

            Assert.Throws <ConnectionStringParseException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/maxDiscoverAttempts=10");
            });

            Assert.Throws <ConnectionStringParseException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/hello?maxDiscoverAttempts=10");
            });
        }
        public void connection_string_with_invalid_userinfo_should_throw()
        {
            Assert.Throws <InvalidUserCredentialsException>(() => {
                EventStoreClientSettings.Create("esdb://[email protected]/");
            });

            Assert.Throws <InvalidUserCredentialsException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/");
            });

            Assert.Throws <InvalidUserCredentialsException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/");
            });
        }
        public void with_valid_cluster_connection_string()
        {
            EventStoreClientSettings settings;

            settings = EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1,127.0.0.2:3321,127.0.0.3/?maxDiscoverAttempts=13&DiscoveryInterval=37&nOdEPrEfErence=FoLLoWer&tlsVerifyCert=false");
            Assert.Equal("user", settings.DefaultCredentials.Username);
            Assert.Equal("pass", settings.DefaultCredentials.Password);
            Assert.NotEmpty(settings.ConnectivitySettings.GossipSeeds);
            Assert.NotNull(settings.ConnectivitySettings.IpGossipSeeds);
            Assert.Null(settings.ConnectivitySettings.DnsGossipSeeds);
            Assert.True(settings.ConnectivitySettings.GossipOverHttps);
            Assert.True(settings.ConnectivitySettings.IpGossipSeeds.Length == 3 &&
                        Equals(settings.ConnectivitySettings.IpGossipSeeds[0].Address, IPAddress.Parse("127.0.0.1")) &&
                        Equals(settings.ConnectivitySettings.IpGossipSeeds[0].Port, 2113) &&
                        Equals(settings.ConnectivitySettings.IpGossipSeeds[1].Address, IPAddress.Parse("127.0.0.2")) &&
                        Equals(settings.ConnectivitySettings.IpGossipSeeds[1].Port, 3321) &&
                        Equals(settings.ConnectivitySettings.IpGossipSeeds[2].Address, IPAddress.Parse("127.0.0.3")) &&
                        Equals(settings.ConnectivitySettings.IpGossipSeeds[2].Port, 2113));
            Assert.Equal(13, settings.ConnectivitySettings.MaxDiscoverAttempts);
            Assert.Equal(37, settings.ConnectivitySettings.DiscoveryInterval.TotalMilliseconds);
            Assert.Equal(NodePreference.Follower, settings.ConnectivitySettings.NodePreference);
            Assert.NotNull(settings.CreateHttpMessageHandler);


            settings = EventStoreClientSettings.Create("esdb://*****:*****@host1,host2:3321,127.0.0.3/?tls=false&maxDiscoverAttempts=13&DiscoveryInterval=37&nOdEPrEfErence=FoLLoWer&tlsVerifyCert=false");
            Assert.Equal("user", settings.DefaultCredentials.Username);
            Assert.Equal("pass", settings.DefaultCredentials.Password);
            Assert.NotEmpty(settings.ConnectivitySettings.GossipSeeds);
            Assert.Null(settings.ConnectivitySettings.IpGossipSeeds);
            Assert.NotNull(settings.ConnectivitySettings.DnsGossipSeeds);
            Assert.False(settings.ConnectivitySettings.GossipOverHttps);
            Assert.True(settings.ConnectivitySettings.DnsGossipSeeds.Length == 3 &&
                        Equals(settings.ConnectivitySettings.DnsGossipSeeds[0].Host, "host1") &&
                        Equals(settings.ConnectivitySettings.DnsGossipSeeds[0].Port, 2113) &&
                        Equals(settings.ConnectivitySettings.DnsGossipSeeds[1].Host, "host2") &&
                        Equals(settings.ConnectivitySettings.DnsGossipSeeds[1].Port, 3321) &&
                        Equals(settings.ConnectivitySettings.DnsGossipSeeds[2].Host, "127.0.0.3") &&
                        Equals(settings.ConnectivitySettings.DnsGossipSeeds[2].Port, 2113));
            Assert.Equal(13, settings.ConnectivitySettings.MaxDiscoverAttempts);
            Assert.Equal(37, settings.ConnectivitySettings.DiscoveryInterval.TotalMilliseconds);
            Assert.Equal(NodePreference.Follower, settings.ConnectivitySettings.NodePreference);
            Assert.NotNull(settings.CreateHttpMessageHandler);
        }
        public void with_default_settings()
        {
            EventStoreClientSettings settings;

            settings = EventStoreClientSettings.Create("esdb://hostname:4321/");

            Assert.Null(settings.ConnectionName);
            Assert.Equal(EventStoreClientConnectivitySettings.Default.Address.Scheme, settings.ConnectivitySettings.Address.Scheme);
            Assert.Equal(EventStoreClientConnectivitySettings.Default.DiscoveryInterval.TotalMilliseconds, settings.ConnectivitySettings.DiscoveryInterval.TotalMilliseconds);
            Assert.Null(EventStoreClientConnectivitySettings.Default.DnsGossipSeeds);
            Assert.Empty(EventStoreClientConnectivitySettings.Default.GossipSeeds);
            Assert.Equal(EventStoreClientConnectivitySettings.Default.GossipTimeout.TotalMilliseconds, settings.ConnectivitySettings.GossipTimeout.TotalMilliseconds);
            Assert.Null(EventStoreClientConnectivitySettings.Default.IpGossipSeeds);
            Assert.Equal(EventStoreClientConnectivitySettings.Default.MaxDiscoverAttempts, settings.ConnectivitySettings.MaxDiscoverAttempts);
            Assert.Equal(EventStoreClientConnectivitySettings.Default.NodePreference, settings.ConnectivitySettings.NodePreference);
            Assert.Equal(EventStoreClientConnectivitySettings.Default.GossipOverHttps, settings.ConnectivitySettings.GossipOverHttps);
            Assert.Equal(EventStoreClientOperationOptions.Default.TimeoutAfter.Value.TotalMilliseconds, settings.OperationOptions.TimeoutAfter.Value.TotalMilliseconds);
            Assert.Equal(EventStoreClientOperationOptions.Default.ThrowOnAppendFailure, settings.OperationOptions.ThrowOnAppendFailure);
        }
        public void connection_string_with_invalid_host_should_throw()
        {
            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:abc");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:abc/");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:1234,127.0.0.2:abc,127.0.0.3:4321");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:1234,127.0.0.2:abc,127.0.0.3:4321/");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:abc:def");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1:abc:def/");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@localhost:1234,127.0.0.2:abc:def,127.0.0.3:4321");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@localhost:1234,127.0.0.2:abc:def,127.0.0.3:4321/");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@localhost:1234,,127.0.0.3:4321");
            });

            Assert.Throws <InvalidHostException>(() => {
                EventStoreClientSettings.Create("esdb://*****:*****@localhost:1234,,127.0.0.3:4321/");
            });
        }
        public void with_valid_single_node_connection_string()
        {
            EventStoreClientSettings settings;

            settings = EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/?maxDiscoverAttempts=13&DiscoveryInterval=37&gossipTimeout=33&nOdEPrEfErence=FoLLoWer&tlsVerifyCert=false");
            Assert.Equal("user", settings.DefaultCredentials.Username);
            Assert.Equal("pass", settings.DefaultCredentials.Password);
            Assert.Equal("https://127.0.0.1:2113/", settings.ConnectivitySettings.Address.ToString());
            Assert.Empty(settings.ConnectivitySettings.GossipSeeds);
            Assert.Null(settings.ConnectivitySettings.IpGossipSeeds);
            Assert.Null(settings.ConnectivitySettings.DnsGossipSeeds);
            Assert.Equal(13, settings.ConnectivitySettings.MaxDiscoverAttempts);
            Assert.Equal(37, settings.ConnectivitySettings.DiscoveryInterval.TotalMilliseconds);
            Assert.Equal(33, settings.ConnectivitySettings.GossipTimeout.TotalMilliseconds);
            Assert.Equal(NodePreference.Follower, settings.ConnectivitySettings.NodePreference);
            Assert.NotNull(settings.CreateHttpMessageHandler);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1?connectionName=test&maxDiscoverAttempts=13&DiscoveryInterval=37&nOdEPrEfErence=FoLLoWer&tls=true&tlsVerifyCert=true&operationTimeout=330&throwOnAppendFailure=faLse");
            Assert.Null(settings.DefaultCredentials);
            Assert.Equal("test", settings.ConnectionName);
            Assert.Equal("https://127.0.0.1:2113/", settings.ConnectivitySettings.Address.ToString());
            Assert.Empty(settings.ConnectivitySettings.GossipSeeds);
            Assert.Null(settings.ConnectivitySettings.IpGossipSeeds);
            Assert.Null(settings.ConnectivitySettings.DnsGossipSeeds);
            Assert.True(settings.ConnectivitySettings.GossipOverHttps);
            Assert.Equal(13, settings.ConnectivitySettings.MaxDiscoverAttempts);
            Assert.Equal(37, settings.ConnectivitySettings.DiscoveryInterval.TotalMilliseconds);
            Assert.Equal(NodePreference.Follower, settings.ConnectivitySettings.NodePreference);
            Assert.Null(settings.CreateHttpMessageHandler);
            Assert.Equal(330, settings.OperationOptions.TimeoutAfter.Value.TotalMilliseconds);
            Assert.False(settings.OperationOptions.ThrowOnAppendFailure);

            settings = EventStoreClientSettings.Create("esdb://hostname:4321/?tls=false");
            Assert.Null(settings.DefaultCredentials);
            Assert.Equal("http://hostname:4321/", settings.ConnectivitySettings.Address.ToString());
            Assert.Empty(settings.ConnectivitySettings.GossipSeeds);
            Assert.Null(settings.ConnectivitySettings.IpGossipSeeds);
            Assert.Null(settings.ConnectivitySettings.DnsGossipSeeds);
            Assert.True(settings.ConnectivitySettings.GossipOverHttps);
            Assert.Null(settings.CreateHttpMessageHandler);
        }
Example #14
0
        protected EventStoreClientFixtureBase(EventStoreClientSettings?clientSettings,
                                              IDictionary <string, string>?env = null)
        {
            _disposables = new List <IDisposable>();
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            var connectionString = GlobalEnvironment.UseCluster ? ConnectionStringCluster : ConnectionStringSingle;

            Settings = clientSettings ?? EventStoreClientSettings.Create(connectionString);

            Settings.OperationOptions.TimeoutAfter = Debugger.IsAttached
                                ? new TimeSpan?()
                                : TimeSpan.FromSeconds(30);

            var hostCertificatePath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory,
                                                                    "..", "..", "..", "..", GlobalEnvironment.UseCluster ? "certs-cluster" : "certs"));

#if GRPC_CORE
            Settings.ChannelCredentials ??= GetServerCertificate();

            SslCredentials GetServerCertificate() => new SslCredentials(
                File.ReadAllText(Path.Combine(hostCertificatePath, "ca", "ca.crt")), null, _ => true);
#endif

            Settings.LoggerFactory ??= new SerilogLoggerFactory();

            Settings.ConnectivitySettings.MaxDiscoverAttempts = 20;
            Settings.ConnectivitySettings.DiscoveryInterval   = TimeSpan.FromSeconds(1);

            if (GlobalEnvironment.UseExternalServer)
            {
                TestServer = new EventStoreTestServerExternal();
            }
            else
            {
                TestServer = GlobalEnvironment.UseCluster
                                        ? (IEventStoreTestServer) new EventStoreTestServerCluster(hostCertificatePath, Settings.ConnectivitySettings.Address, env)
                                        : new EventStoreTestServer(hostCertificatePath, Settings.ConnectivitySettings.Address, env);
            }
        }
        public void with_different_tls_verify_cert_settings()
        {
            EventStoreClientSettings settings;

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1/");
            Assert.Null(settings.CreateHttpMessageHandler);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1/?tlsVerifyCert=TrUe");
            Assert.Null(settings.CreateHttpMessageHandler);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1/?tlsVerifyCert=FaLsE");
            Assert.NotNull(settings.CreateHttpMessageHandler);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1,127.0.0.2:3321,127.0.0.3/");
            Assert.Null(settings.CreateHttpMessageHandler);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1,127.0.0.2:3321,127.0.0.3/?tlsVerifyCert=true");
            Assert.Null(settings.CreateHttpMessageHandler);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1,127.0.0.2:3321,127.0.0.3/?tlsVerifyCert=false");
            Assert.NotNull(settings.CreateHttpMessageHandler);
        }
        public void with_different_tls_settings()
        {
            EventStoreClientSettings settings;

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1/");
            Assert.Equal(Uri.UriSchemeHttps, settings.ConnectivitySettings.Address.Scheme);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1?tls=true");
            Assert.Equal(Uri.UriSchemeHttps, settings.ConnectivitySettings.Address.Scheme);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1/?tls=FaLsE");
            Assert.Equal(Uri.UriSchemeHttp, settings.ConnectivitySettings.Address.Scheme);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1,127.0.0.2:3321,127.0.0.3/");
            Assert.True(settings.ConnectivitySettings.GossipOverHttps);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1,127.0.0.2:3321,127.0.0.3?tls=true");
            Assert.True(settings.ConnectivitySettings.GossipOverHttps);

            settings = EventStoreClientSettings.Create("esdb://127.0.0.1,127.0.0.2:3321,127.0.0.3/?tls=fAlSe");
            Assert.False(settings.ConnectivitySettings.GossipOverHttps);
        }
 public void connection_string_with_no_schema()
 {
     Assert.Throws <NoSchemeException>(() => {
         EventStoreClientSettings.Create(":so/mething/random");
     });
 }
 public void connection_string_with_no_key_value_pairs_specified_should_not_throw()
 {
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1");
     EventStoreClientSettings.Create("esdb://*****:*****@127.0.0.1/");
 }