Exemplo n.º 1
0
        public void RepositoryStart_DataProviderExtensions_OverrideDefault()
        {
            var dbProvider         = new InMemoryDataProvider();
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            // switch this ON here for testing purposes (to check that repo start does not override it)
            SnTrace.Custom.Enabled = true;

            // switch this ON here for testing purposes (to check that repo start does not override it)
            SnTrace.Custom.Enabled = true;

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseAccessTokenDataProviderExtension(new TestAccessTokenDataProvider()) // ACTION: set test provider
                              .UseSecurityDataProvider(securityDbProvider)
                              .UseSearchEngine(searchEngine)
                              .UseAccessProvider(accessProvider)
                              .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.AreEqual(typeof(TestAccessTokenDataProvider), DataStore.GetDataProviderExtension <IAccessTokenDataProviderExtension>().GetType());
            }
        }
Exemplo n.º 2
0
        public void RepositoryStart_NodeObservers_EnableMore()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .EnableNodeObservers(typeof(TestNodeObserver1), typeof(TestNodeObserver2))
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.AreEqual(2, Providers.Instance.NodeObservers.Length);
                Assert.IsTrue(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver1)));
                Assert.IsTrue(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver2)));
            }
        }
Exemplo n.º 3
0
        public void RepositoryStart_NodeObservers_DisableOne()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers(typeof(TestNodeObserver1))
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.IsFalse(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver1)));

                //TODO: currently this does not work, because observers are enabled/disabled globally.
                // Itt will, when we move to a per-thread environment in tests.
                //Assert.IsTrue(Providers.Instance.NodeObservers.Any(no => no.GetType() == typeof(TestNodeObserver2)));
            }
        }
Exemplo n.º 4
0
        public void RepositoryStart_NodeObservers_EnableOne()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .AddBlobProvider(new InMemoryBlobProvider())
                              .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                              .UseTestingDataProviderExtension(new InMemoryTestingDataProvider())
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .EnableNodeObservers(typeof(TestNodeObserver1))
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");


            using (Repository.Start(repoBuilder))
            {
                Assert.AreEqual(1, Providers.Instance.NodeObservers.Length);
                Assert.AreEqual(typeof(TestNodeObserver1), Providers.Instance.NodeObservers[0].GetType());
            }
        }
Exemplo n.º 5
0
        public void RepositoryStart_NodeObservers_DisableAll()
        {
            var dbProvider = new InMemoryDataProvider();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseSharedLockDataProviderExtension(new InMemorySharedLockDataProvider())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .UseAccessTokenDataProviderExtension(new InMemoryAccessTokenDataProvider())
                              .UseSearchEngine(new InMemorySearchEngine(GetInitialIndex()))
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseTestingDataProviderExtension(new InMemoryTestingDataProvider())
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.IsFalse(Providers.Instance.NodeObservers.Any());
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the security service to the collection.
        /// </summary>
        public static IServiceCollection AddSenseNetSecurity(this IServiceCollection services,
                                                             Action <SecurityConfiguration> configureSecurity = null,
                                                             Action <MessagingOptions> configureMessaging     = null)
        {
            // custom or default configuration
            if (configureSecurity != null)
            {
                services.Configure(configureSecurity);
            }
            else
            {
                services.Configure <SecurityConfiguration>(config => { });
            }

            if (configureMessaging != null)
            {
                services.Configure(configureMessaging);
            }
            else
            {
                services.Configure <MessagingOptions>(config => { });
            }

            services
            .AddInMemorySecurityDataProvider(DatabaseStorage.CreateEmpty())
            .AddSecurityMissingEntityHandler <MissingEntityHandler>()
            .AddDefaultSecurityMessageSenderManager()
            .AddDefaultSecurityMessageProvider();

            return(services);
        }
Exemplo n.º 7
0
        public void RepositoryStart_NamedProviders()
        {
            var dbProvider         = new InMemoryDataProvider();
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            // switch this ON here for testing purposes (to check that repo start does not override it)
            SnTrace.Custom.Enabled = true;

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .AddBlobProvider(new InMemoryBlobProvider())
                              .UseSecurityDataProvider(securityDbProvider)
                              .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                              .UseSearchEngine(searchEngine)
                              .UseAccessProvider(accessProvider)
                              .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.AreSame(dbProvider, Providers.Instance.DataStore.DataProvider);
                Assert.AreEqual(searchEngine, SearchManager.SearchEngine);
                Assert.AreEqual(accessProvider, AccessProvider.Current);
                Assert.AreEqual(emvrProvider, Providers.Instance.ElevatedModificationVisibilityRuleProvider);

                // Currently this does not work, because the property below re-creates the security
                // db provider from the prototype, so it cannot be ref equal with the original.
                // Assert.AreEqual(securityDbProvider, SecurityHandler.SecurityContext.DataProvider);
                Assert.AreEqual(securityDbProvider, Providers.Instance.SecurityDataProvider);

                // Check a few trace categories that were switched ON above.
                Assert.IsTrue(SnTrace.Custom.Enabled);
                Assert.IsTrue(SnTrace.Test.Enabled);
                Assert.IsTrue(SnTrace.Web.Enabled);
                Assert.IsTrue(SnTrace.System.Enabled);
                Assert.IsFalse(SnTrace.TaskManagement.Enabled);
                Assert.IsFalse(SnTrace.Workflow.Enabled);
            }
        }
Exemplo n.º 8
0
        public void RepositoryStart_AuditEventWriter_Database()
        {
            var originalWriter = SnLog.AuditEventWriter;
            var auditWriter    = new DatabaseAuditEventWriter();

            var dbProvider         = new InMemoryDataProvider();
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            try
            {
                // Clear the slot to ensure a real test.
                Providers.Instance.AuditEventWriter = null;

                var repoBuilder = new RepositoryBuilder()
                                  .UseAccessProvider(new DesktopAccessProvider())
                                  .UseDataProvider(dbProvider)
                                  .UseAuditEventWriter(auditWriter) // <-- The important line
                                  .UseInitialData(GetInitialData())
                                  .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider))
                                  .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                                  .AddBlobProvider(new InMemoryBlobProvider())
                                  .UseSecurityDataProvider(securityDbProvider)
                                  .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                                  .UseSearchEngine(searchEngine)
                                  .UseAccessProvider(accessProvider)
                                  .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                                  .StartIndexingEngine(false)
                                  .StartWorkflowEngine(false)
                                  .UseTraceCategories("Test", "Web", "System");

                using (Repository.Start(repoBuilder))
                {
                    Assert.AreSame(auditWriter, Providers.Instance.AuditEventWriter);
                    Assert.AreSame(auditWriter, SnLog.AuditEventWriter);
                }
            }
            finally
            {
                SnLog.AuditEventWriter = originalWriter;
            }
        }
Exemplo n.º 9
0
        public void RepositoryStart_NullPopulator()
        {
            var dbProvider2 = new InMemoryDataProvider();

            Providers.Instance.DataProvider = dbProvider2;
            var securityDbProvider = new MemoryDataProvider(DatabaseStorage.CreateEmpty());
            var searchEngine       = new InMemorySearchEngine(GetInitialIndex());
            var accessProvider     = new DesktopAccessProvider();
            var emvrProvider       = new ElevatedModificationVisibilityRule();

            var repoBuilder = new RepositoryBuilder()
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseDataProvider(dbProvider2)
                              .UseInitialData(GetInitialData())
                              .UseBlobMetaDataProvider(new InMemoryBlobStorageMetaDataProvider(dbProvider2))
                              .UseBlobProviderSelector(new InMemoryBlobProviderSelector())
                              .AddBlobProvider(new InMemoryBlobProvider())
                              .UseSecurityDataProvider(securityDbProvider)
                              .UseSecurityMessageProvider(new DefaultMessageProvider(new MessageSenderManager()))
                              .UseSearchEngine(searchEngine)
                              .UseAccessProvider(accessProvider)
                              .UseElevatedModificationVisibilityRuleProvider(emvrProvider)
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            var originalIsOuterSearchEngineEnabled = Indexing.IsOuterSearchEngineEnabled;

            Indexing.IsOuterSearchEngineEnabled = false;
            try
            {
                using (Repository.Start(repoBuilder))
                {
                    Assert.IsFalse(SearchManager.IsOuterEngineEnabled);
                    Assert.AreEqual(typeof(InternalSearchEngine), SearchManager.SearchEngine.GetType());
                    var populator = SearchManager.GetIndexPopulator();
                    Assert.AreEqual(typeof(NullPopulator), populator.GetType());
                }
            }
            finally
            {
                Indexing.IsOuterSearchEngineEnabled = originalIsOuterSearchEngineEnabled;
            }
        }
Exemplo n.º 10
0
        public void RepositoryStart_NodeObservers_DisableAll()
        {
            var repoBuilder = new RepositoryBuilder()
                              .UseDataProvider(new InMemoryDataProvider())
                              .UseSecurityDataProvider(new MemoryDataProvider(DatabaseStorage.CreateEmpty()))
                              .UseSearchEngine(new InMemorySearchEngine())
                              .UseAccessProvider(new DesktopAccessProvider())
                              .UseElevatedModificationVisibilityRuleProvider(new ElevatedModificationVisibilityRule())
                              .UseCacheProvider(new EmptyCache())
                              .DisableNodeObservers()
                              .StartIndexingEngine(false)
                              .StartWorkflowEngine(false)
                              .UseTraceCategories("Test", "Web", "System");

            using (Repository.Start(repoBuilder))
            {
                Assert.IsFalse(Providers.Instance.NodeObservers.Any());
            }
        }