private URLEndpointListenerConfiguration CreateListenerConfig(bool tls = true, bool useDynamicPort = true,
                                                                      IListenerAuthenticator auth = null, TLSIdentity id = null, bool stopListener = true)
        {
            if (stopListener)
            {
                _listener?.Stop();
            }

            var config = new URLEndpointListenerConfiguration(OtherDb);

            if (useDynamicPort)
            {
                config.Port = 0;
            }
            else
            {
                config.Port = tls ? WssPort : WsPort;
            }

            config.DisableTLS    = !tls;
            config.Authenticator = auth;
            config.TlsIdentity   = id;

            return(config);
        }
        private URLEndpointListener Listen(URLEndpointListenerConfiguration config,
                                           int expectedErrCode = 0, CouchbaseLiteErrorType expectedErrDomain = 0)
        {
            _listener?.Stop();

            _listener = new URLEndpointListener(config);

            _listener.Port.Should().Be(0, "Listener's port should be 0 because the listener has not yet started.");
            _listener.Urls.Count.Should().Be(0, "Listener's Urls count should be 0 because the listener has not yet started.");
            _listener.TlsIdentity.Should().BeNull("Listener's TlsIdentity should be null because the listener has not yet started.");
            _listener.Status.ConnectionCount.Should().Be(0, "Listener's connection count should be 0 because the listener has not yet started.");
            _listener.Status.ActiveConnectionCount.Should().Be(0, "Listener's active connection count should be 0 because the listener has not yet started.");

            try {
                _listener.Start();
            } catch (CouchbaseLiteException e) {
                if (expectedErrCode == 0)
                {
                    throw;
                }

                e.Domain.Should().Be(expectedErrDomain);
                e.Error.Should().Be(expectedErrCode);
            } catch (CouchbaseNetworkException ne) {
                if (expectedErrCode == 0)
                {
                    throw;
                }

                ne.Domain.Should().Be(expectedErrDomain);
                ne.Error.Should().Be(expectedErrCode);
            }

            return(_listener);
        }
Ejemplo n.º 3
0
        private URLEndpointListener CreateNewListener()
        {
            var config   = new URLEndpointListenerConfiguration(OtherDb);
            var listener = new URLEndpointListener(config);

            listener.Start();
            return(_listener);
        }
Ejemplo n.º 4
0
        internal void CreateListener()
        {
            //tag::InitListener[]
            var listenerConfig = new URLEndpointListenerConfiguration(_db); // <1>

            listenerConfig.NetworkInterface = GetLocalIPv4(NetworkInterfaceType.Wireless80211) ?? GetLocalIPv4(NetworkInterfaceType.Ethernet);
            listenerConfig.Port             = 0; // Dynamic port

            switch (CoreApp.ListenerTLSMode)     // <2>
            //tag::TLSDisabled[]
            {
            case LISTENER_TLS_MODE.DISABLED:
                listenerConfig.DisableTLS  = true;
                listenerConfig.TlsIdentity = null;
                //end::TLSDisabled[]
                break;

            //tag::TLSWithAnonymousAuth[]
            case LISTENER_TLS_MODE.WITH_ANONYMOUS_AUTH:
                listenerConfig.DisableTLS  = false;    // Use with anonymous self signed cert if TlsIdentity is null
                listenerConfig.TlsIdentity = null;
                //end::TLSWithAnonymousAuth[]
                break;

            //tag::TLSWithBundledCert[]
            case LISTENER_TLS_MODE.WITH_BUNDLED_CERT:
                listenerConfig.DisableTLS  = false;
                listenerConfig.TlsIdentity = ImportTLSIdentityFromPkc12(ListenerCertLabel);
                //end::TLSWithBundledCert[]
                break;

            //tag::TLSWithGeneratedSelfSignedCert[]
            case LISTENER_TLS_MODE.WITH_GENERATED_SELF_SIGNED_CERT:
                listenerConfig.DisableTLS  = false;
                listenerConfig.TlsIdentity = CreateIdentityWithCertLabel(ListenerCertLabel);
                //end::TLSWithGeneratedSelfSignedCert[]
                break;
            }

            listenerConfig.EnableDeltaSync = true; // <3>

            if (CoreApp.RequiresUserAuth)          // <4>
            {
                listenerConfig.Authenticator = new ListenerPasswordAuthenticator((sender, username, password) =>
                {
                    // ** This is only a sample app to use an existing users credential shared cross platforms.
                    //    Developers should use SecureString password properly.
                    var found = CoreApp.AllowedUsers.Where(u => username == u.Username && new NetworkCredential(string.Empty, password).Password == u.Password).SingleOrDefault();
                    return(found != null);
                });
            }

            _urlEndpointListener = new URLEndpointListener(listenerConfig);
            //end::InitListener[]
        }
        private URLEndpointListener CreateNewListener()
        {
            var config = new URLEndpointListenerConfiguration(OtherDb);

            config.Port       = 0;
            config.DisableTLS = false;

            var listener = new URLEndpointListener(config);

            listener.Start();
            return(_listener);
        }
Ejemplo n.º 6
0
        private URLEndpointListener CreateListener(bool tls = true, bool useDynamicPort = true, IListenerAuthenticator auth = null)
        {
            _listener?.Stop();

            var config = new URLEndpointListenerConfiguration(OtherDb)
            {
                Port          = useDynamicPort ? (ushort)0 : tls ? WssPort : WsPort,//In order to get the test to pass on Linux, Port needs to be 0.
                DisableTLS    = !tls,
                Authenticator = auth
            };

            return(Listen(config));
        }
Ejemplo n.º 7
0
        private URLEndpointListenerConfiguration CreateListenerConfig(bool tls = true, bool useDynamicPort = true,
                                                                      IListenerAuthenticator auth = null, TLSIdentity id = null, bool readOnly = false, string networkInterface = null)
        {
            _listener?.Stop();

            var config = new URLEndpointListenerConfiguration(OtherDb)
            {
                Port          = useDynamicPort ? (ushort)0 : tls ? WssPort : WsPort,
                DisableTLS    = !tls,
                Authenticator = auth,
                TlsIdentity   = id,
                ReadOnly      = readOnly
            };

            return(config);
        }
        public void TestReadOnlyListener()
        {
            using (var doc1 = new MutableDocument()) {
                Db.Save(doc1);
            }

            var config = new URLEndpointListenerConfiguration(OtherDb)
            {
                ReadOnly = true
            };

            Listen(config);
            RunReplication(_listener.LocalEndpoint(), ReplicatorType.PushAndPull,
                           false, null, null,
                           (int)CouchbaseLiteError.HTTPForbidden,
                           CouchbaseLiteErrorType.CouchbaseLite);

            _listener.Stop();
        }
        private URLEndpointListener CreateListener(bool tls = true, bool useDynamicPort = true, IListenerAuthenticator auth = null)
        {
            _listener?.Stop();

            var config = new URLEndpointListenerConfiguration(OtherDb);

            //In order to get the test to pass on Linux, Port needs to be 0.
            if (useDynamicPort)
            {
                config.Port = 0;
            }
            else
            {
                config.Port = tls ? WssPort : WsPort;
            }

            config.DisableTLS    = !tls;
            config.Authenticator = auth;

            return(Listen(config));
        }