Пример #1
0
        /*public void Connect()
         * {
         *  PlainTextAuthProvider auth = new PlainTextAuthProvider(login, pass);
         *
         *  cluster = Cluster.Builder().AddContactPoint(server).WithAuthProvider(auth).Build();
         *  session = cluster.Connect(keyspace);
         * }
         */
        public void Connect()
        {
            PlainTextAuthProvider auth = new PlainTextAuthProvider(login, pass);
            RemoteCertificateValidationCallback remoteCertificateValidationCallback = new RemoteCertificateValidationCallback(
                (object sender,
                 X509Certificate certificate,
                 X509Chain chain,
                 SslPolicyErrors sslPolicyErrors) =>
            {
                if (sslPolicyErrors != SslPolicyErrors.None)
                {
                    if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            });
            SSLOptions opt = new SSLOptions(System.Security.Authentication.SslProtocols.Tls, false, remoteCertificateValidationCallback);

            cluster = Cluster.Builder().AddContactPoint(server).WithAuthProvider(auth).WithSSL(opt).Build();
            session = cluster.Connect(keyspace);
        }
        public void Cassandra20OrAbove_PasswordAuthenticator()
        {
            var authProvider           = new PlainTextAuthProvider("username", "password");
            var authProvideMockWrapper = new Mock <IAuthProvider>();

            authProvideMockWrapper
            .Setup(a => a.NewAuthenticator(It.IsAny <IPAddress>()))
            .Returns <IPAddress>(authProvider.NewAuthenticator)
            .Verifiable();
            using (var cluster = Cluster
                                 .Builder()
                                 .AddContactPoint(ContactPoint)
                                 .WithAuthProvider(authProvideMockWrapper.Object)
                                 .Build())
            {
                var session = cluster.Connect();
                var rs      = session.Execute("SELECT * FROM system.schema_keyspaces");
                Assert.Greater(rs.Count(), 0);
            }

            authProvideMockWrapper.Verify();
        }