コード例 #1
0
        public bool Remove(string uriPrefix)
        {
            Debug.Assert(!String.IsNullOrEmpty(uriPrefix));

            string newServiceName = BuildSimpleServiceName(uriPrefix);

            newServiceName = ServiceNameCollection.NormalizeServiceName(newServiceName);
            bool needToRemove = Contains(newServiceName);

            if (needToRemove)
            {
                serviceNames.Remove(newServiceName);
                serviceNameCollection = null; //invalidate (readonly) ServiceNameCollection
            }

            if (Logging.On)
            {
                if (needToRemove)
                {
                    Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" +
                                      ValidationHelper.HashString(this) + "::Remove() "
                                      + SR.GetString(SR.net_log_listener_spn_remove, newServiceName, uriPrefix));
                }
                else
                {
                    Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" +
                                      ValidationHelper.HashString(this) + "::Remove() "
                                      + SR.GetString(SR.net_log_listener_spn_not_remove, uriPrefix));
                }
            }

            return(needToRemove);
        }
コード例 #2
0
        public void Constructor_ServiceNameCollection_ZeroElementsParam()
        {
            var paramValue = new ServiceNameCollection(new List <string>());
            var ex         = Assert.Throws <ArgumentException>("customServiceNames", () => new ExtendedProtectionPolicy(PolicyEnforcement.Always, ProtectionScenario.TransportSelected, paramValue));

            Assert.Equal(typeof(ArgumentException), ex.GetType());
        }
コード例 #3
0
        public bool Remove(string uriPrefix)
        {
            Debug.Assert(!string.IsNullOrEmpty(uriPrefix));

            string newServiceName = BuildSimpleServiceName(uriPrefix);

            newServiceName = NormalizeServiceName(newServiceName);
            bool needToRemove = Contains(newServiceName);

            if (needToRemove)
            {
                _serviceNames.Remove(newServiceName);
                _serviceNameCollection = null; //invalidate (readonly) ServiceNameCollection
            }

            if (NetEventSource.IsEnabled)
            {
                if (needToRemove)
                {
                    NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_remove, newServiceName, uriPrefix));
                }
                else
                {
                    NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_not_remove, uriPrefix));
                }
            }

            return(needToRemove);
        }
コード例 #4
0
        public void CopyTo_DestinationTooSmall_Throws()
        {
            ICollection collection = new ServiceNameCollection(new[] { "first", "second" });

            int[] destination = new int[collection.Count - 1];
            Assert.Throws <ArgumentException>(() => collection.CopyTo(destination, 0));
        }
コード例 #5
0
        public void Merge_EnumerableContainingNullOrEmpty_Throws(string item)
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            Assert.Throws <ArgumentException>(() => collection.Merge(new[] { item }));
            Assert.Throws <ArgumentException>(() => collection.Merge(new[] { "third", item }));
        }
コード例 #6
0
        public bool Add(string uriPrefix)
        {
            string[] strArray = this.BuildServiceNames(uriPrefix);
            bool     flag     = false;

            foreach (string str in strArray)
            {
                if (this.AddSingleServiceName(str))
                {
                    flag = true;
                    if (Logging.On)
                    {
                        Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Add() adding default SPNs '" + str + "' from prefix '" + uriPrefix + "'");
                    }
                }
            }
            if (flag)
            {
                this.serviceNameCollection = null;
                return(flag);
            }
            if (Logging.On)
            {
                Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Add() no default SPN added for prefix '" + uriPrefix + "'");
            }
            return(flag);
        }
コード例 #7
0
        public void Merge_NonStringEnumerable_Throws()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            Assert.Throws <ArgumentException>(() => collection.Merge(new[] { 3 }));
            Assert.Throws <ArgumentException>(() => collection.Merge(new[] { new object() }));
        }
コード例 #8
0
        public void SyncRoot_NonNullSameObject()
        {
            ICollection collection = new ServiceNameCollection(new[] { "first", "second" });

            Assert.NotNull(collection.SyncRoot);
            Assert.Same(collection.SyncRoot, collection.SyncRoot);
        }
コード例 #9
0
        public void Constructor_VariousCollections_Success(string[] expected, ICollection items)
        {
            var collection = new ServiceNameCollection(items);

            Assert.Equal(expected, collection.Cast <string>());
            Assert.Equal(expected.Length, collection.Count);
        }
コード例 #10
0
        public bool Add(string uriPrefix)
        {
            Debug.Assert(!string.IsNullOrEmpty(uriPrefix));

            string[] newServiceNames = BuildServiceNames(uriPrefix);

            bool addedAny = false;

            foreach (string spn in newServiceNames)
            {
                if (AddSingleServiceName(spn))
                {
                    addedAny = true;

                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_add, spn, uriPrefix));
                    }
                }
            }

            if (addedAny)
            {
                _serviceNameCollection = null;
            }
            else if (NetEventSource.IsEnabled)
            {
                NetEventSource.Info(this, SR.Format(SR.net_log_listener_spn_not_add, uriPrefix));
            }

            return(addedAny);
        }
コード例 #11
0
        public void Merge_NullOrEmptyString_Throws()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            Assert.Throws <ArgumentException>(() => collection.Merge((string)null));
            Assert.Throws <ArgumentException>(() => collection.Merge(string.Empty));
        }
コード例 #12
0
        public void Contains_Found()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            Assert.True(collection.Contains("first"));
            Assert.True(collection.Contains("second"));
        }
コード例 #13
0
        public void SyncRemote(ServiceNameDiscoveryService.ServiceNameDiscoveryServiceClient serviceClient)
        {
            if (_unRegisterOpNames.Count > 0)
            {
                var serviceNameCollection = new ServiceNameCollection();
                foreach (var opName in _unRegisterOpNames)
                {
                    var serviceName = new ServiceNameElement();
                    serviceName.ApplicationId = opName.Key.ApplicationId;
                    serviceName.ServiceName   = opName.Key.OperationName;
                    serviceName.SrcSpanType   = opName.Key.SpanType;
                    serviceNameCollection.Elements.Add(serviceName);
                }

                var mapping = serviceClient.discovery(serviceNameCollection);

                foreach (var item in mapping.Elements)
                {
                    var element = item.Element;
                    var key     = new OperationNameKey(element.ApplicationId, element.ServiceName,
                                                       SpanType.Entry == element.SrcSpanType, SpanType.Exit == element.SrcSpanType);
                    _unRegisterOpNames.TryRemove(key, out _);
                    _operationNameDic.TryAdd(key, item.ServiceId);
                }
            }
        }
コード例 #14
0
 public ServiceBindingNameTraceRecord(string serviceBindingNameSentByClient, string defaultServiceBindingNameOfServer, ServiceNameCollection serviceNameCollectionConfiguredOnServer)
     : base("ServiceBindingCheckAfterSpNego")
 {
     this.serviceBindingNameSentByClient          = serviceBindingNameSentByClient;
     this.defaultServiceBindingNameOfServer       = defaultServiceBindingNameOfServer;
     this.serviceNameCollectionConfiguredOnServer = serviceNameCollectionConfiguredOnServer;
 }
コード例 #15
0
        public void Enumerator_BehavesAsExpected()
        {
            string item1 = "first";
            string item2 = "second";
            string item3 = "third";

            var collection = new ServiceNameCollection(new[] { item1, item2, item3 });

            IEnumerator e = collection.GetEnumerator();

            for (int i = 0; i < 2; i++)
            {
                // Not started
                Assert.Throws <InvalidOperationException>(() => e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(item1, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(item2, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(item3, e.Current);

                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());

                // Ended
                Assert.Throws <InvalidOperationException>(() => e.Current);

                e.Reset();
            }
        }
コード例 #16
0
        public void CopyTo_InvalidDestinationType_Throws()
        {
            ICollection collection = new ServiceNameCollection(new[] { "first", "second" });

            int[] destination = new int[collection.Count];

            Assert.Throws <InvalidCastException>(() => collection.CopyTo(destination, 0));
        }
コード例 #17
0
        public void Contains_NotFound()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            Assert.False(collection.Contains(null));
            Assert.False(collection.Contains(string.Empty));
            Assert.False(collection.Contains("third"));
        }
コード例 #18
0
        public void Merge_NullEnumerable_Throws()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            // This really should be ArgumentNullException, but the full framework does not
            // guard against null, so NullReferenceException ends up being thrown instead.
            Assert.Throws <NullReferenceException>(() => collection.Merge((IEnumerable)null));
        }
コード例 #19
0
        public void CopyTo_InvalidIndex_Throws()
        {
            ICollection collection = new ServiceNameCollection(new[] { "first", "second" });

            int[] destination = new int[collection.Count];
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.CopyTo(destination, -1));
            Assert.Throws <ArgumentException>(() => collection.CopyTo(destination, destination.Length));
        }
コード例 #20
0
        public void Merge_VariousEnumerables_Success(string[] expected, IEnumerable serviceNames)
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });
            ServiceNameCollection merged = collection.Merge(serviceNames);

            Assert.Equal(expected, merged.Cast <string>());
            Assert.Equal(expected.Length, merged.Count);
        }
コード例 #21
0
        public void Merge_NonDuplicateString_Succeeds()
        {
            string[] expected   = new[] { "first", "second", "third" };
            var      collection = new ServiceNameCollection(new[] { "first", "second" });

            ServiceNameCollection merged = collection.Merge("third");

            Assert.Equal(expected, merged.Cast <string>());
        }
コード例 #22
0
        public void Contains_Found()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second", "localhost:3000/test", "www.test.com" });

            Assert.True(collection.Contains("first"));
            Assert.True(collection.Contains("second"));
            Assert.True(collection.Contains("localhost:3000/test"));
            Assert.True(collection.Contains("www.test.com"));
        }
コード例 #23
0
        public void Merge_DuplicateString_DuplicateFiltered(string duplicate)
        {
            string[] expected   = new[] { "first", "second" };
            var      collection = new ServiceNameCollection(new[] { "first", "second" });

            ServiceNameCollection merged = collection.Merge(duplicate);

            Assert.Equal(expected, merged.Cast <string>());
        }
コード例 #24
0
        public void Merge_EnumerableContainingNullOrEmpty_Throws()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            AssertExtensions.Throws <ArgumentNullException>("serviceName", () => collection.Merge(new[] { (string)null }));
            AssertExtensions.Throws <ArgumentNullException>("serviceName", () => collection.Merge(new[] { "third", null }));
            AssertExtensions.Throws <ArgumentException>("serviceName", () => collection.Merge(new[] { "" }));
            AssertExtensions.Throws <ArgumentException>("serviceName", () => collection.Merge(new[] { "third", "" }));
        }
コード例 #25
0
        // Assumes already normalized
        private bool Contains(string newServiceName)
        {
            if (newServiceName == null)
            {
                return(false);
            }

            return(ServiceNameCollection.Contains(newServiceName, serviceNames));
        }
コード例 #26
0
        public void Constructor_CollectionParam()
        {
            var paramValue = new List <string> {
                "Test1", "Test2"
            };
            var expectedServiceNameCollection = new ServiceNameCollection(paramValue);
            var extendedProtectionPolicy      = new ExtendedProtectionPolicy(PolicyEnforcement.Always, ProtectionScenario.TransportSelected, paramValue);

            Assert.Equal(2, extendedProtectionPolicy.CustomServiceNames.Count);
            Assert.Equal(expectedServiceNameCollection, extendedProtectionPolicy.CustomServiceNames);
        }
コード例 #27
0
        public void CopyTo_ValidDestination_Success()
        {
            string[]    expected   = new[] { "first", "second" };
            ICollection collection = new ServiceNameCollection(expected);

            string[] destination = new string[collection.Count];

            collection.CopyTo(destination, 0);

            Assert.Equal(expected, destination);
        }
コード例 #28
0
 public static bool IsSubset(ServiceNameCollection primaryList, ServiceNameCollection subset)
 {
     if ((subset == null) || (subset.Count == 0))
     {
         return(true);
     }
     if ((primaryList == null) || (primaryList.Count < subset.Count))
     {
         return(false);
     }
     return(primaryList.Merge(subset).Count == primaryList.Count);
 }
コード例 #29
0
 private bool AddSingleServiceName(string spn)
 {
     spn = ServiceNameCollection.NormalizeServiceName(spn);
     if (Contains(spn))
     {
         return(false);
     }
     else
     {
         serviceNames.Add(spn);
         return(true);
     }
 }
コード例 #30
0
        public void ExtendedProtectionPolicy_ToString()
        {
            string serviceName1 = "Test1";
            string serviceName2 = "Test2";
            var    serviceNameCollectionParam = new ServiceNameCollection(new List <string> {
                serviceName1, serviceName2
            });
            var    extendedProtectionPolicy = new ExtendedProtectionPolicy(PolicyEnforcement.Always, ProtectionScenario.TransportSelected, serviceNameCollectionParam);
            string expectedResult           = $"ProtectionScenario={ProtectionScenario.TransportSelected}; PolicyEnforcement={PolicyEnforcement.Always}; CustomChannelBinding=<null>; ServiceNames={serviceName1}, {serviceName2}";

            string result = extendedProtectionPolicy.ToString();

            Assert.Equal(expectedResult, result);
        }
コード例 #31
0
        public ExtendedProtectionPolicy BuildPolicy()
        {
            if (PolicyEnforcement == PolicyEnforcement.Never)
            {
                return new ExtendedProtectionPolicy(PolicyEnforcement.Never);
            }

            ServiceNameCollection spns = null;

            ServiceNameElementCollection spnCollection = CustomServiceNames;
            if (spnCollection != null && spnCollection.Count > 0)
            {
                List<string> spnList = new List<string>(spnCollection.Count);
                foreach (ServiceNameElement element in spnCollection)
                {
                    spnList.Add(element.Name);
                }
                spns = new ServiceNameCollection(spnList);
            }

            return new ExtendedProtectionPolicy(PolicyEnforcement, ProtectionScenario, spns);
        }
コード例 #32
0
 public void CopyTo_NullDestination_Throws()
 {
     ICollection collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 0));
 }
コード例 #33
0
 public void CopyTo_DestinationTooSmall_Throws()
 {
     ICollection collection = new ServiceNameCollection(new[] { "first", "second" });
     int[] destination = new int[collection.Count - 1];
     Assert.Throws<ArgumentException>(() => collection.CopyTo(destination, 0));
 }
コード例 #34
0
 public void CopyTo_InvalidIndex_Throws()
 {
     ICollection collection = new ServiceNameCollection(new[] { "first", "second" });
     int[] destination = new int[collection.Count];
     Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(destination, -1));
     Assert.Throws<ArgumentException>(() => collection.CopyTo(destination, destination.Length));
 }
コード例 #35
0
        public void CopyTo_InvalidDestinationType_Throws()
        {
            ICollection collection = new ServiceNameCollection(new[] { "first", "second" });
            int[] destination = new int[collection.Count];

            Assert.Throws<InvalidCastException>(() => collection.CopyTo(destination, 0));
        }
コード例 #36
0
 public void SyncRoot_NonNullSameObject()
 {
     ICollection collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.NotNull(collection.SyncRoot);
     Assert.Same(collection.SyncRoot, collection.SyncRoot);
 }
コード例 #37
0
        public void Merge_DuplicateString_DuplicateFiltered(string duplicate)
        {
            string[] expected = new[] { "first", "second" };
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            ServiceNameCollection merged = collection.Merge(duplicate);
            Assert.Equal(expected, merged.Cast<string>());
        }
コード例 #38
0
        public void Merge_NullEnumerable_Throws()
        {
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            // This really should be ArgumentNullException, but the full framework does not
            // guard against null, so NullReferenceException ends up being thrown instead.
            Assert.Throws<NullReferenceException>(() => collection.Merge((IEnumerable)null));
        }
コード例 #39
0
 public void Merge_EnumerableContainingNullOrEmpty_Throws(string item)
 {
     var collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.Throws<ArgumentException>(() => collection.Merge(new[] { item }));
     Assert.Throws<ArgumentException>(() => collection.Merge(new[] { "third", item }));
 }
コード例 #40
0
 public void Merge_VariousEnumerables_Success(string[] expected, IEnumerable serviceNames)
 {
     var collection = new ServiceNameCollection(new[] { "first", "second" });
     ServiceNameCollection merged = collection.Merge(serviceNames);
     Assert.Equal(expected, merged.Cast<string>());
     Assert.Equal(expected.Length, merged.Count);
 }
コード例 #41
0
 public void Constructor_VariousCollections_Success(string[] expected, ICollection items)
 {
     var collection = new ServiceNameCollection(items);
     Assert.Equal(expected, collection.Cast<string>());
     Assert.Equal(expected.Length, collection.Count);
 }
コード例 #42
0
 public void Contains_NotFound()
 {
     var collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.False(collection.Contains(null));
     Assert.False(collection.Contains(string.Empty));
     Assert.False(collection.Contains("third"));
 }
コード例 #43
0
 public void Contains_Found()
 {
     var collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.True(collection.Contains("first"));
     Assert.True(collection.Contains("second"));
 }
コード例 #44
0
        public void CopyTo_ValidDestination_Success()
        {
            string[] expected = new[] { "first", "second" };
            ICollection collection = new ServiceNameCollection(expected);
            string[] destination = new string[collection.Count];

            collection.CopyTo(destination, 0);

            Assert.Equal(expected, destination);
        }
コード例 #45
0
 public ExtendedProtectionPolicy(PolicyEnforcement policyEnforcement, ProtectionScenario protectionScenario, ServiceNameCollection customServiceNames);
コード例 #46
0
        public void Merge_NonDuplicateString_Succeeds()
        {
            string[] expected = new[] { "first", "second", "third" };
            var collection = new ServiceNameCollection(new[] { "first", "second" });

            ServiceNameCollection merged = collection.Merge("third");
            Assert.Equal(expected, merged.Cast<string>());
        }
コード例 #47
0
 public void Merge_NullOrEmptyString_Throws()
 {
     var collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.Throws<ArgumentException>(() => collection.Merge((string)null));
     Assert.Throws<ArgumentException>(() => collection.Merge(string.Empty));
 }
コード例 #48
0
        public void Enumerator_BehavesAsExpected()
        {
            string item1 = "first";
            string item2 = "second";
            string item3 = "third";

            var collection = new ServiceNameCollection(new[] { item1, item2, item3 });

            IEnumerator e = collection.GetEnumerator();

            for (int i = 0; i < 2; i++)
            {
                // Not started
                Assert.Throws<InvalidOperationException>(() => e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(item1, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(item2, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(item3, e.Current);

                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());

                // Ended
                Assert.Throws<InvalidOperationException>(() => e.Current);

                e.Reset();
            }
        }
コード例 #49
0
 public void Merge_NonStringEnumerable_Throws()
 {
     var collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.Throws<ArgumentException>(() => collection.Merge(new[] { 3 }));
     Assert.Throws<ArgumentException>(() => collection.Merge(new[] { new object() }));
 }
コード例 #50
0
 public void IsSynchronized_ReturnsFalse()
 {
     ICollection collection = new ServiceNameCollection(new[] { "first", "second" });
     Assert.False(collection.IsSynchronized);
 }