Пример #1
0
        public CertificateResolverFacts()
        {
            m_resolver = CreateResolver(true, 60, false); // enable caching, ttl=60secs, disable negative caching 

            m_cache = m_resolver.Cache;

            ClearCache();            
        }
Пример #2
0
        public void TestDomain()
        {
            DummyX509Index index = new DummyX509Index();
            CertificateResolver resolver = new CertificateResolver(index, null);

            resolver.GetCertificatesForDomain("redmond.hsgincubator.com");
            Assert.True(index.Log.Count == 1);
            Assert.True(index.Log[0] == "redmond.hsgincubator.com");
        }
Пример #3
0
        public void TestOrgOnly()
        {
            DummyX509Index index = new DummyX509Index();
            CertificateResolver resolver = new CertificateResolver(index, null);
            resolver.OrgCertificatesOnly = true;

            resolver.GetCertificates(new MailAddress("*****@*****.**"));
            Assert.True(index.Log.Count == 1);
            Assert.True(index.Log[0] == "redmond.hsgincubator.com");
        }
Пример #4
0
        /// <summary>
        /// Create a resolver that resolvers anchors from the middle tier
        /// </summary>
        /// <param name="clientSettings">Settings to set up WCF connections to the middle tier</param>
        /// <param name="cacheSettings">Optional: if caching is enabled. Else null</param>
        public ConfigAnchorResolver(ClientSettings clientSettings, CacheSettings cacheSettings)
        {
            if (clientSettings == null)
            {
                throw new ArgumentNullException("clientSettings");
            }

            CacheSettings incomingCacheSettings = new CacheSettings(cacheSettings) { Name = "AnchorCache.incoming" };
            CacheSettings outgoingCacheSettings = new CacheSettings(cacheSettings) { Name = "AnchorCache.outgoing" };

            m_incomingResolver = new CertificateResolver(new AnchorIndex(clientSettings, true), incomingCacheSettings);
            m_outgoingResolver = new CertificateResolver(new AnchorIndex(clientSettings, false), outgoingCacheSettings);
        }
Пример #5
0
        /// <summary>
        /// Tuck away settings and create resolvers. 
        /// </summary>
        /// <param name="settings"></param>
        public void Initialize(BundleResolverSettings settings)
        {
            m_settings = settings;

            CacheSettings incomingCacheSettings =
                new CacheSettings(m_settings.CacheSettings) { Name = "BundleCache.incoming" };

            CacheSettings outgoingCacheSettings =
                new CacheSettings(m_settings.CacheSettings) { Name = "BundleCache.outgoing" };

            m_incomingResolver =
                new CertificateResolver(new BundleAnchorIndex(m_settings, true), incomingCacheSettings);

            m_outgoingResolver =
                new CertificateResolver(new BundleAnchorIndex(m_settings, false), outgoingCacheSettings);
        }
Пример #6
0
 public void TestErrorEventHandler()
 {
     ThrowingX509Index throwingIndex = new ThrowingX509Index();
     CacheSettings cacheSettings = new CacheSettings();
     cacheSettings.Cache = false;
     
     List<Exception> notifiedErrors = new List<Exception>();
     List<Exception> thrownErrors = new List<Exception>();
     //
     // Test Notifications are fired
     //
     CertificateResolver resolver = new CertificateResolver(throwingIndex, cacheSettings);
     resolver.Error += (r, e) => notifiedErrors.Add(e);
     MailAddress address = new MailAddress("toby@toby");
     this.TryResolveCerts(resolver, address, thrownErrors);
     
     Assert.True(notifiedErrors.Count == thrownErrors.Count);
     //
     // Test they are NOT fired
     //
     int countThrownFiredBefore = thrownErrors.Count;
     resolver = new CertificateResolver(throwingIndex, cacheSettings);
     notifiedErrors.Clear();
     thrownErrors.Clear();
     this.TryResolveCerts(resolver, address, thrownErrors);
     
     Assert.True(notifiedErrors.Count == 0);
     Assert.True(thrownErrors.Count == countThrownFiredBefore);
 }
Пример #7
0
 public void CachingCertNotFoundNegativeCache()
 {
     m_resolver = CreateResolver(true, 60, true);
     CachingCertNotFound();
 }
Пример #8
0
 public void CachingVerifyFallbackAddressesNegativeCache()
 {   
     m_resolver = CreateResolver(true, 60, true);
     CachingVerifyFallbackAddresses();
 }
Пример #9
0
        public void CachingVerifyDisabledNullCacheSettings()
        {
            using (SystemX509Store store = SystemX509Store.OpenExternal())
            {
                m_resolver = new CertificateResolver(store, null);                
                m_cache = m_resolver.Cache;
                string domain = DomainIncubator;
                X509Certificate2Collection source = m_resolver.GetCertificatesForDomain(domain);

                Assert.Null(m_resolver.Cache);
                Assert.True(source.Count > 0);
            }
        }
Пример #10
0
        public void CachingVerifyDisabled()
        {
            m_resolver = CreateResolver(
                false,  /* caching disabled */
                0,      /* TTL */
                false); /* negative caching */

            string domain = DomainIncubator;
            X509Certificate2Collection source = m_resolver.GetCertificatesForDomain(domain);
            X509Certificate2Collection cached = m_cache.Get(domain);

            Assert.Null(cached);
            Assert.True(source.Count > 0); 
        }
Пример #11
0
        public void CachingVerifyTTL()
        {
            m_resolver = CreateResolver(
                true,   /* caching enabled */
                3,      /* TTL */
                false); /* negative cache */
                
            string domain = DomainIncubator;
            X509Certificate2Collection source = m_resolver.GetCertificatesForDomain(domain);
            X509Certificate2Collection cached = m_cache.Get(domain);

            VerifyValidCert(source, cached);

            Thread.Sleep(4000);

            // verify its evicted from cache.
            cached = m_cache.Get(domain);
            Assert.Null(cached);

            // now get it served from the cache. 
            source = m_resolver.GetCertificatesForDomain(domain);
            cached = m_cache.Get(domain);

            VerifyValidCert(source, cached);
        }