Beispiel #1
0
        public void TestEmptyContentType()
        {
            var sg = new SyncGateway(GetReplicationProtocol(), GetReplicationServer());

            using (var remoteDb = sg.CreateDatabase("empty-content-type")) {
                var doc     = database.CreateDocument();
                var unsaved = doc.CreateRevision();

                var data = Enumerable.Repeat <byte>((byte)80, 2500);
                unsaved.SetAttachment("attach", "", data);
                unsaved.Save();
                database.GetDocumentCount().Should().Be(1, "because a document was added");

                var push = database.CreatePushReplication(remoteDb.RemoteUri);
                push.Start();
                var now = DateTime.UtcNow;
                while (push.CompletedChangesCount < 1)
                {
                    Sleep(500);
                    if (DateTime.UtcNow - now > TimeSpan.FromSeconds(10))
                    {
                        throw new TimeoutException("Test timed out");
                    }
                }
            }
        }
        public void TestExternalReplicationStart()
        {
            var sg  = new SyncGateway(GetReplicationProtocol(), GetReplicationServer());
            var tmp = EnsureEmptyDatabase("test_db");

            tmp.Close();

            SetupListener(false);
            CreateDocuments(database, 10);
            using (var remoteDb = sg.CreateDatabase("external_replication_test")) {
                var request = WebRequest.Create("http://localhost:" + _port + "/_replicate");
                request.ContentType = "application/json";
                request.Method      = "POST";
                var body  = String.Format("{{\"source\":\"{0}\",\"target\":\"{1}\"}}", database.Name, remoteDb.RemoteUri);
                var bytes = Encoding.UTF8.GetBytes(body);
                request.ContentLength = bytes.Length;
                request.GetRequestStream().Write(bytes, 0, bytes.Length);

                var response = (HttpWebResponse)request.GetResponse();
                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

                request             = WebRequest.Create("http://localhost:" + _port + "/_replicate");
                request.ContentType = "application/json";
                request.Method      = "POST";
                body  = String.Format("{{\"source\":\"{0}\",\"target\":\"test_db\",\"create_target\":true}}", remoteDb.RemoteUri);
                bytes = Encoding.UTF8.GetBytes(body);
                request.ContentLength = bytes.Length;
                request.GetRequestStream().Write(bytes, 0, bytes.Length);

                response = (HttpWebResponse)request.GetResponse();
                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

                var createdDb = manager.GetExistingDatabase("test_db");
                Assert.IsNotNull(createdDb);
                Assert.AreEqual(10, createdDb.GetDocumentCount());
            }
        }
Beispiel #3
0
 protected override void SetUp()
 {
     base.SetUp();
     _sg = new SyncGateway(GetReplicationProtocol(), GetReplicationServer());
 }
Beispiel #4
0
 protected override void SetUp()
 {
     base.SetUp();
     _sg = new SyncGateway(GetReplicationProtocol(), GetReplicationServer());
     Assert.DoesNotThrow(() => _ts = new TimeSeries(database, "tstest"), "Could not create ts");
 }
Beispiel #5
0
        public void TestFacebookAuth()
        {
            var sg = new SyncGateway("http", GetReplicationServer());

            using (var remoteDb = sg.CreateDatabase("facebook")) {
                remoteDb.DisableGuestAccess();
                var doneEvent = new ManualResetEvent(false);

                var accountStore = new ACAccountStore();
                var accountType  = accountStore.FindAccountType(ACAccountType.Facebook);

                var options = new AccountStoreOptions();
                options.FacebookAppId = FacebookAppId;
                options.SetPermissions(ACFacebookAudience.Friends, new [] { "email" });

                var       success = true;
                ACAccount account = null;
                accountStore.RequestAccess(accountType, options, (result, error) =>
                {
                    success = result;
                    if (success)
                    {
                        var accounts = accountStore.FindAccounts(accountType);
                        account      = accounts != null && accounts.Length > 0 ? accounts[0] : null;
                    }
                    else
                    {
                        Log.W(Tag, "Facebook Login needed. Go to Settings > Facebook and login.");
                        Log.E(Tag, "Facebook Request Access Error : " + error);
                    }
                    doneEvent.Set();
                });

                doneEvent.WaitOne(TimeSpan.FromSeconds(30));

                Assert.IsTrue(success);
                Assert.IsNotNull(account);

                var token = account.Credential.OAuthToken;
                Assert.IsNotNull(token);
                Assert.IsTrue(token.Length > 0);

                var url = remoteDb.RemoteUri;

                var cookieStore       = new CookieStore(manager.Directory);
                var httpClientFactory = new CouchbaseLiteHttpClientFactory(cookieStore);
                manager.DefaultHttpClientFactory = httpClientFactory;
                Replication replicator = database.CreatePushReplication(url);
                replicator.Authenticator = AuthenticatorFactory.CreateFacebookAuthenticator(token);

                Assert.IsNotNull(replicator);
                Assert.IsNotNull(replicator.Authenticator);
                Assert.IsTrue(replicator.Authenticator is TokenAuthenticator);

                CreateDocuments(database, 20);

                RunReplication(replicator);

                var urlStr = url.ToString();
                urlStr = urlStr.EndsWith("/") ? urlStr : urlStr + "/";
                //var cookies = httpClientFactory.GetCookieContainer().GetCookies(new Uri(urlStr));
                //Assert.IsTrue(cookies.Count == 1);
                //Assert.AreEqual("SyncGatewaySession", cookies[0].Name);
            }
        }