Exemple #1
0
        static void Main(string[] args)
        {
            // RedDot Login with (user/password)
            var authData = new PasswordAuthentication("user", "password");

            var login = new ServerLogin()
            {
                Address = new Uri("http://localhost/cms"), AuthData = authData
            };

            // Session is the entry point to interact with the RedDot server.
            // Creating the session object automatically creates a connection.
            // Dispose() closes the connection in a a clean way (this is done
            // automatically at the end of the using block).
            using (var session = SessionBuilder.CreateOrReplaceOldestSession(login))
            {
                // Select a project based on the name
                var project = session.ServerManager.Projects.GetByName("MyProjekt");

                // Find all pages based on the Content Class "MyContentClass"
                var pageSearch = project.Pages.CreateSearch();
                pageSearch.ContentClass = project.ContentClasses.GetByName("MyContentClass");

                var pages = pageSearch.Execute();

                // Attach suffix ".php" to all filenames of the pages found
                foreach (var curPage in pages)
                {
                    curPage.Filename = curPage.Filename + ".php";

                    // Commit changes to the server
                    curPage.Commit();
                }
            }
        }
Exemple #2
0
        public void TestPersist()
        {
            Session s1 = new SessionBuilder().StartDefault("S1").Build();
            Session s2 = new SessionBuilder().StartDefault("S2").Build();
            Session s3 = new SessionBuilder().StartDefault("S3").Build();

            var mockUnitOfWork = new Mock <IUnitOfWork>();
            var mockRepository = new Mock <ISessionRepository>();

            mockRepository.Setup(sm => sm.GetUnitOfWork()).Returns(mockUnitOfWork.Object);

            var manager = new SessionManager(mockRepository.Object);

            manager.AddSession(s1);
            manager.AddSession(s2);
            manager.AddSession(s3);
            manager.RemoveSession(s3);
            manager.CurrentSession = s1;

            manager.Persist();

            mockUnitOfWork.Verify(uow => uow.RegisterSavedOrUpdated(It.Is <Session>(o => o.Equals(s1))), Times.Once());
            mockUnitOfWork.Verify(uow => uow.RegisterSavedOrUpdated(It.Is <Session>(o => o.Equals(s2))), Times.Once());
            mockUnitOfWork.Verify(uow => uow.RegisterRemoved(It.Is <Session>(o => o.Equals(s3))), Times.Once());
            mockUnitOfWork.Verify(uow => uow.RegisterSavedOrUpdated(It.Is <CurrentSessionInfo>(o => o.CurrentSessionName.Equals(s1.Name))), Times.Once());
            mockUnitOfWork.Verify(uow => uow.Commit(), Times.Once());
        }
Exemple #3
0
        public void testSimultaneousKeyExchange()
        {
            SignalProtocolStore aliceStore          = new TestInMemorySignalProtocolStore();
            SessionBuilder      aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS);

            SignalProtocolStore bobStore          = new TestInMemorySignalProtocolStore();
            SessionBuilder      bobSessionBuilder = new SessionBuilder(bobStore, ALICE_ADDRESS);

            KeyExchangeMessage aliceKeyExchange = aliceSessionBuilder.process();
            KeyExchangeMessage bobKeyExchange   = bobSessionBuilder.process();

            Assert.IsNotNull(aliceKeyExchange);
            Assert.IsNotNull(bobKeyExchange);

            KeyExchangeMessage aliceResponse = aliceSessionBuilder.process(bobKeyExchange);
            KeyExchangeMessage bobResponse   = bobSessionBuilder.process(aliceKeyExchange);

            Assert.IsNotNull(aliceResponse);
            Assert.IsNotNull(bobResponse);

            KeyExchangeMessage aliceAck = aliceSessionBuilder.process(bobResponse);
            KeyExchangeMessage bobAck   = bobSessionBuilder.process(aliceResponse);

            Assert.IsNull(aliceAck);
            Assert.IsNull(bobAck);

            runInteraction(aliceStore, bobStore);
        }
        public void ReturnANullTopicIdIfNotSupplied()
        {
            var actualSession = new SessionBuilder()
                                .Build(Int32.MaxValue.GetRandom());

            Assert.False(actualSession.TopicId.HasValue);
        }
Exemple #5
0
        private void handleMismatchedDevices(PushServiceSocket socket, SignalServiceAddress recipient, MismatchedDevices mismatchedDevices)
        {
            try
            {
                foreach (uint extraDeviceId in mismatchedDevices.getExtraDevices())
                {
                    store.DeleteSession(new SignalProtocolAddress(recipient.getNumber(), extraDeviceId));
                }

                foreach (uint missingDeviceId in mismatchedDevices.getMissingDevices())
                {
                    PreKeyBundle preKey = socket.getPreKey(recipient, missingDeviceId);

                    try
                    {
                        SessionBuilder sessionBuilder = new SessionBuilder(store, new SignalProtocolAddress(recipient.getNumber(), missingDeviceId));
                        sessionBuilder.process(preKey);
                    }
                    catch (libsignal.exceptions.UntrustedIdentityException e)
                    {
                        throw new UntrustedIdentityException("Untrusted identity key!", recipient.getNumber(), preKey.getIdentityKey());
                    }
                }
            }
            catch (InvalidKeyException e)
            {
                throw new Exception(e.Message);
            }
        }
        public void ReturnTheCorrectSessionIdIfTheNextIdIsSupplied()
        {
            var expected      = Int32.MaxValue.GetRandom();
            var actualSession = new SessionBuilder().Build(expected);

            Assert.Equal(expected, actualSession.Id);
        }
        public void ReturnASessionInstanceIfANextIdIsSupplied()
        {
            var actual = new SessionBuilder()
                         .Build(Int32.MaxValue.GetRandom());

            Assert.NotNull(actual);
        }
        public void ReturnAnEmptyPresenterCollectionIfNoneAreAdded()
        {
            var actualSession = new SessionBuilder()
                                .Build(Int32.MaxValue.GetRandom());

            Assert.False(actualSession.Presenters.Any());
        }
        public static SessionBuilder WithGHF(this SessionBuilder sessionBuilder)
        {
            var msp = new Mock <ILibMSPWrapper>();

            msp.Setup(m => m.GetEmptyFieldsObj()).Returns(new MspFieldsMock());
            return(sessionBuilder.WithGHF(msp));
        }
Exemple #10
0
        static void Main(string[] args)
        {
            var url      = args[0];
            var user     = args[1];
            var password = args[2];

            var authData = new PasswordAuthentication(user, password);
            var login    = new ServerLogin()
            {
                Address = new Uri(url), AuthData = authData
            };

            using (var session = SessionBuilder.CreateOrReplaceOldestSession(login))
            {
                var project = session.ServerManager.Projects["nav_demo"];
                var search  = project.Pages.CreateSearch();
                search.PageType = PageType.Unlinked;
                var unlinkedPages = search.Execute();

                IEnumerable <IPage> processedPages = new List <IPage>();

                while (unlinkedPages.Any())
                {
                    foreach (var curPage in unlinkedPages)
                    {
                        Console.WriteLine("Deleting " + curPage);
                        //curPage.Delete();
                    }
                    processedPages = processedPages.Union(unlinkedPages);
                    unlinkedPages  = search.Execute().Where(page => !processedPages.Contains(page));
                }

                Console.WriteLine("Done");
            }
        }
        public void ReturnTheCorrectDependencyChainIfNoDependenciesSpecified()
        {
            int primarySessionId   = Int32.MaxValue.GetRandom();
            int secondarySessionId = Int32.MaxValue.GetRandom();
            int tertiarySessionId  = Int32.MaxValue.GetRandom();

            var primarySessionBuilder = new SessionBuilder()
                                        .Id(primarySessionId);

            var secondarySessionBuilder = new SessionBuilder()
                                          .Id(secondarySessionId);

            var tertiarySessionBuilder = new SessionBuilder()
                                         .Id(tertiarySessionId);

            var actualSessions = new SessionCollectionBuilder()
                                 .AddSession(primarySessionBuilder)
                                 .AddSession(secondarySessionBuilder)
                                 .AddSession(tertiarySessionBuilder)
                                 .Build();

            var primarySession   = actualSessions.Single(s => s.Id == primarySessionId);
            var secondarySession = actualSessions.Single(s => s.Id == secondarySessionId);
            var tertiarySession  = actualSessions.Single(s => s.Id == tertiarySessionId);

            Assert.False(tertiarySession.IsDependentUpon(secondarySessionId));
            Assert.False(tertiarySession.IsDependentUpon(primarySessionId));

            Assert.False(secondarySession.IsDependentUpon(primarySessionId));
            Assert.False(secondarySession.IsDependentUpon(tertiarySessionId));

            Assert.False(primarySession.IsDependentUpon(secondarySessionId));
            Assert.False(primarySession.IsDependentUpon(tertiarySessionId));
        }
Exemple #12
0
        private async Task HandleMismatchedDevices(CancellationToken token, PushServiceSocket socket, SignalServiceAddress recipient, MismatchedDevices mismatchedDevices)
        {
            try
            {
                foreach (uint extraDeviceId in mismatchedDevices.ExtraDevices)
                {
                    store.DeleteSession(new SignalProtocolAddress(recipient.E164number, extraDeviceId));
                }

                foreach (uint missingDeviceId in mismatchedDevices.MissingDevices)
                {
                    PreKeyBundle preKey = await socket.GetPreKey(token, recipient, missingDeviceId);

                    try
                    {
                        SessionBuilder sessionBuilder = new SessionBuilder(store, new SignalProtocolAddress(recipient.E164number, missingDeviceId));
                        sessionBuilder.process(preKey);
                    }
                    catch (libsignal.exceptions.UntrustedIdentityException)
                    {
                        throw new UntrustedIdentityException("Untrusted identity key!", recipient.E164number, preKey.getIdentityKey());
                    }
                }
            }
            catch (InvalidKeyException e)
            {
                throw new Exception(e.Message);
            }
        }
Exemple #13
0
        public void TestSaveDocuments()
        {
            var repo     = new XmlSessionRepository();
            var uow      = repo.GetUnitOfWork();
            var session1 = new SessionBuilder().StartDefault("session1").Build();
            var doc1     = new SessionDocumentBuilder().StartDefault("doc1").Build();

            session1.AddDocument(doc1);
            var doc2 = new SessionDocumentBuilder().StartDefault("doc2").Build();

            session1.AddDocument(doc2);
            uow.RegisterSavedOrUpdated(session1);
            uow.Commit();

            repo = new XmlSessionRepository();
            var sessionsInRepo = repo.GetAllSessions();

            Assert.AreEqual(1, sessionsInRepo.Count());
            Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1)));
            Assert.AreEqual(2, sessionsInRepo.First().GetDocuments().Count());

            repo = new XmlSessionRepository();
            uow  = repo.GetUnitOfWork();
            session1.RemoveDocument(doc1);
            uow.RegisterSavedOrUpdated(session1);
            uow.Commit();

            repo           = new XmlSessionRepository();
            sessionsInRepo = repo.GetAllSessions();
            Assert.AreEqual(1, sessionsInRepo.Count());
            Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1)));
            Assert.AreEqual(1, sessionsInRepo.First().GetDocuments().Count());
        }
Exemple #14
0
        public void TestCrud()
        {
            var repo     = new XmlSessionRepository();
            var uow      = repo.GetUnitOfWork();
            var session1 = new SessionBuilder().StartDefault("session1").Build();

            uow.RegisterSavedOrUpdated(session1);
            uow.Commit();

            repo = new XmlSessionRepository();
            var sessionsInRepo = repo.GetAllSessions();

            Assert.AreEqual(1, sessionsInRepo.Count());
            Assert.IsNotNull(sessionsInRepo.FirstOrDefault(s => s.Equals(session1)));

            repo = new XmlSessionRepository();
            uow  = repo.GetUnitOfWork();
            session1.AddDocument(new SessionDocumentBuilder().StartDefault("doc1").Build()); // <-- adding one document to modify something in the session
            uow.RegisterSavedOrUpdated(session1);
            uow.Commit();

            repo           = new XmlSessionRepository();
            sessionsInRepo = repo.GetAllSessions();
            Assert.AreEqual(1, sessionsInRepo.Count());
            Assert.AreEqual(1, sessionsInRepo.First().GetDocuments().Count());

            repo = new XmlSessionRepository();
            uow  = repo.GetUnitOfWork();
            uow.RegisterRemoved(session1);
            uow.Commit();

            repo           = new XmlSessionRepository();
            sessionsInRepo = repo.GetAllSessions();
            Assert.AreEqual(0, sessionsInRepo.Count());
        }
        public ActionResult StopSession(SessionModel model)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            model = new SessionBuilder().GetById(model.Id);
            SessionStopModelApiPost sessionModel = new SessionStopModelApiPost();

            if (model.Id != Guid.Empty && model.Id != null)
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://////////api/Session");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                sessionModel = new SessionBuilder().MakeSessionStopModelReadyForJsonConversion(model);

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string jsonReturnValue = serializer.Serialize(sessionModel);
                    streamWriter.Write(jsonReturnValue);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
            }
            return(RedirectToAction("Menu", "Dashboard"));
        }
        public void TestReloadSession()
        {
            var sessionToReload = new SessionBuilder().StartDefault().Build();

            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(sm => sm.CurrentSession).Returns(sessionToReload);

            var dsmSettings         = new DsmSettingsBuilder().StartDefault().Build();
            var settingsManagerMock = new Mock <IDsmSettingsManager>();

            settingsManagerMock.Setup(st => st.DsmSettings).Returns(dsmSettings);

            var dteAdapterMock = new Mock <IDteAdapter>();

            dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List <IDteWindowAdapter>());

            var controller = new AddinController(sessionManagerMock.Object, settingsManagerMock.Object, null,
                                                 dteAdapterMock.Object, null);

            controller.ReloadSession();

            sessionManagerMock.Verify(sm => sm.CurrentSession);
            settingsManagerMock.Verify(st => st.DsmSettings);
        }
        public void TestLoadDocumentsFromSession_NonExistentDocument()
        {
            const string NON_EXISTENT_DOCUMENT = "NON_EXISTENT_DOCUMENT";

            var sessionWithDocumentsToLoad = new SessionBuilder().StartDefault().Build();

            var nonExistentDocument = new SessionDocumentBuilder().StartDefault(NON_EXISTENT_DOCUMENT).Build();

            sessionWithDocumentsToLoad.AddDocument(nonExistentDocument);

            var dteAdapterMock = new Mock <IDteAdapter>();

            dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(new List <IDteWindowAdapter>());

            dteAdapterMock.Setup(da => da.FileExists(It.IsAny <string>())).Returns(false);

            var viewAdapterMock = new Mock <IViewAdapter>();

            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(sm => sm.CurrentSession).Returns((Session)null);

            var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object,
                                                 dteAdapterMock.Object, null);

            controller.LoadDocumentsFromSession(sessionWithDocumentsToLoad);

            dteAdapterMock.Verify(da => da.OpenFile(It.IsAny <string>(), It.IsAny <DocumentType>()), Times.Never());
            dteAdapterMock.Verify(da => da.FileExists(It.IsAny <string>()), Times.Once());
            viewAdapterMock.Verify(va => va.ShowLongMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once());
        }
        public void NewUser()
        {
            var session = new SessionBuilder()
                          .WithAddOn(new GHAddOn())
                          .WithAddOn(new GHCAddOn())
                          .WithXmlFile(@"GHCTests\Integration\ActionButtonTemplate.xml")
                          .WithXmlFile(@"GHCTests\Integration\Cooldown.xml")
                          .WithIgnoredXmlTemplate("NumberFontNormalSmallGray")
                          .WithIgnoredXmlTemplate("NumberFontNormal")
                          .WithIgnoredXmlTemplate("GameFontHighlightSmallOutline")
                          .Build();

            var optionsContainer = session.FrameProvider.CreateFrame(BlizzardApi.WidgetEnums.FrameType.Frame, "InterfaceOptionsFramePanelContainer") as IFrame;

            optionsContainer.SetWidth(400);
            optionsContainer.SetHeight(500);


            session.RunStartup();

            var ghTestable = new GHAddOnTestable(session);

            ghTestable.MouseOverMainButton();
            ghTestable.ClickSubButton("Interface/ICONS/Ability_Stealth");

            session.Actor.VerifyVisible("Interface/ICONS/INV_Misc_Bag_11", true);
        }
Exemple #19
0
        public void TestLoad()
        {
            Session s1 = new SessionBuilder().StartDefault("S1").Build();
            Session s2 = new SessionBuilder().StartDefault("S2").Build();
            Session s3 = new SessionBuilder().StartDefault("S3").Build();

            var mock = new Mock <ISessionRepository>();

            mock.Setup(repo => repo.GetAllSessions()).Returns(new List <Session>()
            {
                s1, s2, s3
            });
            mock.Setup(repo => repo.GetCurrentSessionName()).Returns("S2");

            var manager = new SessionManager(mock.Object);

            manager.Load();

            var sessions = manager.GetSessions();

            Assert.AreEqual(3, sessions.Count());

            Assert.AreEqual(1, sessions.Where(s => s.Equals(s1)).Count());
            Assert.AreEqual(1, sessions.Where(s => s.Equals(s2)).Count());
            Assert.AreEqual(1, sessions.Where(s => s.Equals(s3)).Count());

            Assert.AreSame(s2, manager.CurrentSession);
        }
Exemple #20
0
        public void TestGetSessionNames()
        {
            var mock    = new Mock <ISessionRepository>();
            var manager = new SessionManager(mock.Object);

            Session newSession = new SessionBuilder().StartDefault("S1").Build();

            manager.AddSession(newSession);

            newSession = new SessionBuilder().StartDefault("S2").Build();
            manager.AddSession(newSession);

            newSession = new SessionBuilder().StartDefault("S3").Build();
            manager.AddSession(newSession);

            var names = manager.GetSessionNames();

            const int QTY_SESSIONS_ADDED = 3;

            Assert.AreEqual(QTY_SESSIONS_ADDED, names.Count());

            Assert.AreEqual(1, names.Where(n => n.Equals("S1")).Count());
            Assert.AreEqual(1, names.Where(n => n.Equals("S2")).Count());
            Assert.AreEqual(1, names.Where(n => n.Equals("S3")).Count());
        }
        public ActionResult StartSession(SessionModel model)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("http:////////////api/Session");

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";
            SessionStartModelApiPost sessionModel = new SessionStartModelApiPost();
            JavaScriptSerializer     serializer   = new JavaScriptSerializer();

            //checking if the sessionmodel is not null.
            if (model != null)
            {
                //getting the current logged in teacher.
                model.TeacherEmail = HttpContext.User.Identity.Name;
                //returning a SessionStartModelApiPost model.
                sessionModel = new SessionBuilder().MakeSessionStartModelReadyForJsonConversion(model);
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    //serializing the sessionModel object to a JSON-object.
                    string jsonReturnValue = serializer.Serialize(sessionModel);
                    streamWriter.Write(jsonReturnValue);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
            }
            SessionModel returnSession = new SessionBuilder().GetById(sessionModel.Id);

            return(View("StopSession", returnSession));
        }
 public void Should_create_a_new_session()
 {
     var builder = new SessionBuilder();
     var session = builder.GetSession();
     session.ShouldNotBeNull();
     session.IsOpen.ShouldBeTrue();
 }
        public void TestDeleteSessions()
        {
            var sessionToDelete = new SessionBuilder().StartDefault().Build();

            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(sm => sm.GetSessions()).Returns(new List <Session>());
            sessionManagerMock.Setup(sm => sm.GetSession(It.IsAny <string>())).Returns(sessionToDelete);
            sessionManagerMock.Setup(sm => sm.CurrentSession).Returns(sessionToDelete);

            var viewAdapterMock = new Mock <IViewAdapter>();

            viewAdapterMock.Setup(va => va.GetSessionsForDelete(It.IsAny <IList <SessionDto> >()))
            .Returns(new List <SessionDto>()
            {
                new SessionDto()
            });

            var controller = new AddinController(sessionManagerMock.Object, null, viewAdapterMock.Object,
                                                 null, null);

            controller.DeleteSessions();

            sessionManagerMock.Verify(sm => sm.RemoveSession(sessionToDelete), Times.Once());
            sessionManagerMock.Verify(sm => sm.Persist(), Times.Once());
        }
        public void TestFillDocumentsInSession()
        {
            const string DOCUMENT_TO_ADD1    = "documentToAdd1";
            const string DOCUMENT_TO_ADD2    = "documentToAdd2";
            const string DOCUMENT_TO_ADD3    = "documentToAdd3";
            const string DOCUMENT_DUPLICATED = "documentDuplicated";

            var session = new SessionBuilder().StartDefault().Build();

            session.AddDocument(new SessionDocumentBuilder().StartDefault("documentToRemove").Build());
            session.AddDocument(new SessionDocumentBuilder().StartDefault(DOCUMENT_DUPLICATED).Build());

            var dteWindowAdapterMock1 = new Mock <IDteWindowAdapter>();

            dteWindowAdapterMock1.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_TO_ADD1);
            dteWindowAdapterMock1.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text);

            var dteWindowAdapterMock2 = new Mock <IDteWindowAdapter>();

            dteWindowAdapterMock2.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_TO_ADD2);
            dteWindowAdapterMock2.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text);

            var dteWindowAdapterMock3 = new Mock <IDteWindowAdapter>();

            dteWindowAdapterMock3.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_TO_ADD3);
            dteWindowAdapterMock3.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text);

            var dteWindowAdapterMock4 = new Mock <IDteWindowAdapter>();

            dteWindowAdapterMock4.Setup(dwa => dwa.FullPath).Returns(DOCUMENT_DUPLICATED);
            dteWindowAdapterMock4.Setup(dwa => dwa.DocumentType).Returns(DocumentType.Text);

            var dteAdapterMock = new Mock <IDteAdapter>();

            dteAdapterMock.Setup(da => da.GetWindowsForValidDocuments()).Returns(
                new List <IDteWindowAdapter>()
            {
                dteWindowAdapterMock1.Object,
                dteWindowAdapterMock2.Object,
                dteWindowAdapterMock3.Object,
                dteWindowAdapterMock4.Object
            });

            var sessionManagerMock = new Mock <ISessionManager>();

            sessionManagerMock.Setup(sm => sm.CurrentSession).Returns((Session)null);

            var controller = new AddinController(sessionManagerMock.Object, null, null, dteAdapterMock.Object, null);

            controller.FillDocumentsInSession(session);

            IEnumerable <SessionDocument> documentsInSession = session.GetDocuments();

            Assert.AreEqual(4, documentsInSession.Count());
            Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_TO_ADD1)).Count());
            Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_TO_ADD2)).Count());
            Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_TO_ADD3)).Count());
            Assert.AreEqual(1, documentsInSession.Where(d => d.Path.Equals(DOCUMENT_DUPLICATED)).Count());
        }
Exemple #25
0
        public BtrieveRuntime_Tests()
        {
            _modulePath = GetModulePath();

            _serviceResolver = new ServiceResolver(SessionBuilder.ForTest($"MBBSExeRuntime_{RANDOM.Next()}"));

            Directory.CreateDirectory(_modulePath);
        }
Exemple #26
0
        public SignalProtocolAddress newSession(string chatJid, uint recipientDeviceId, PreKeyBundle recipientPreKey)
        {
            SignalProtocolAddress address = new SignalProtocolAddress(chatJid, recipientDeviceId);
            SessionBuilder        builder = new SessionBuilder(SESSION_STORE, PRE_KEY_STORE, SIGNED_PRE_KEY_STORE, IDENTITY_STORE, address);

            builder.process(recipientPreKey);
            return(address);
        }
Exemple #27
0
        public MBBSEmuIntegrationTestBase()
        {
            _serviceResolver = new ServiceResolver(SessionBuilder.ForTest($"MBBSDb_{RANDOM.Next()}"));

            _serviceResolver.GetService <IAccountRepository>().Reset("sysop");
            _serviceResolver.GetService <IAccountKeyRepository>().Reset();
            Directory.CreateDirectory(_modulePath);
        }
        public void Should_create_a_new_session()
        {
            var builder = new SessionBuilder();
            var session = builder.GetSession();

            session.ShouldNotBeNull();
            session.IsOpen.ShouldBeTrue();
        }
        public SignalProtocolAddress newSession(string chatJid, uint recipientDeviceId, PreKeyBundle recipientPreKey)
        {
            SignalProtocolAddress address = new SignalProtocolAddress(chatJid, recipientDeviceId);
            SessionBuilder        builder = new SessionBuilder(OMEMO_STORE, address);

            builder.process(recipientPreKey);
            return(address);
        }
Exemple #30
0
        public void testBadMessageBundle()
        {
            SignalProtocolStore aliceStore          = new TestInMemorySignalProtocolStore();
            SessionBuilder      aliceSessionBuilder = new SessionBuilder(aliceStore, BOB_ADDRESS);

            SignalProtocolStore bobStore = new TestInMemorySignalProtocolStore();

            ECKeyPair bobPreKeyPair       = Curve.generateKeyPair();
            ECKeyPair bobSignedPreKeyPair = Curve.generateKeyPair();

            byte[] bobSignedPreKeySignature = Curve.calculateSignature(bobStore.GetIdentityKeyPair().getPrivateKey(),
                                                                       bobSignedPreKeyPair.getPublicKey().serialize());

            PreKeyBundle bobPreKey = new PreKeyBundle(bobStore.GetLocalRegistrationId(), 1,
                                                      31337, bobPreKeyPair.getPublicKey(),
                                                      22, bobSignedPreKeyPair.getPublicKey(), bobSignedPreKeySignature,
                                                      bobStore.GetIdentityKeyPair().getPublicKey());

            bobStore.StorePreKey(31337, new PreKeyRecord(bobPreKey.getPreKeyId(), bobPreKeyPair));
            bobStore.StoreSignedPreKey(22, new SignedPreKeyRecord(22, DateUtil.currentTimeMillis(), bobSignedPreKeyPair, bobSignedPreKeySignature));

            aliceSessionBuilder.process(bobPreKey);

            String            originalMessage    = "L'homme est condamné à être libre";
            SessionCipher     aliceSessionCipher = new SessionCipher(aliceStore, BOB_ADDRESS);
            CiphertextMessage outgoingMessageOne = aliceSessionCipher.encrypt(Encoding.UTF8.GetBytes(originalMessage));

            Assert.AreEqual(CiphertextMessage.PREKEY_TYPE, outgoingMessageOne.getType());

            byte[] goodMessage = outgoingMessageOne.serialize();
            byte[] badMessage  = new byte[goodMessage.Length];
            Array.Copy(goodMessage, 0, badMessage, 0, badMessage.Length);

            badMessage[badMessage.Length - 10] ^= 0x01;

            PreKeySignalMessage incomingMessage  = new PreKeySignalMessage(badMessage);
            SessionCipher       bobSessionCipher = new SessionCipher(bobStore, ALICE_ADDRESS);

            byte[] plaintext = new byte[0];

            try
            {
                plaintext = bobSessionCipher.decrypt(incomingMessage);
                throw new Exception("Decrypt should have failed!");
            }
            catch (InvalidMessageException)
            {
                // good.
            }

            Assert.IsTrue(bobStore.ContainsPreKey(31337));

            plaintext = bobSessionCipher.decrypt(new PreKeySignalMessage(goodMessage));

            Assert.AreEqual(originalMessage, Encoding.UTF8.GetString(plaintext));
            Assert.IsFalse(bobStore.ContainsPreKey(31337));
        }
Exemple #31
0
        public IEnumerable <ISession> GetSessions()
        {
            var sessions = _sessionManager.SearchAllEntities();

            return(SessionBuilder.NewSessionBuilder()
                   .SetAlarmClock(_alarmClock)
                   .SetConnectionString(_connectionString)
                   .BuildAll(sessions));
        }
        public void Should_build_a_new_session_when_session_is_disposed()
        {
            var builder = new SessionBuilder();
            var session = builder.GetSession();
            session.Dispose();

            var session2 = builder.GetSession();
            session2.IsOpen.ShouldBeTrue();
        }
        public void Should_return_the_same_instance_second_time()
        {
            var builder = new SessionBuilder();
            var session = builder.GetSession();
            session.ShouldNotBeNull();

            var session2 = builder.GetSession();
            ReferenceEquals(session, session2).ShouldBeTrue();
        }
        public void Database_connection_should_work()
        {
            ISession session = new SessionBuilder().GetSession();
            if (session.Transaction.IsActive)
                session.Transaction.Rollback();

            IDbConnection connection = session.Connection;
            IDbCommand command = connection.CreateCommand();
            command.CommandText = "select 1+1 from Users";
            command.ExecuteNonQuery();
        }