Esempio n. 1
0
        public void InitializeSetsLocationIpToUserHostAddressIfHeadersIsEmpty()
        {
            var module    = new TestableClientIpHeaderTelemetryInitializer(new Dictionary <string, string>());
            var telemetry = new PageViewTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
        public void InitializeSetsLocationIpOfRequestToUserHostAddressIfNoHeadersInRequest()
        {
            var module = new TestableClientIpHeaderTelemetryInitializer();
            var requestTelemetry = module.PlatformContext.CreateRequestTelemetryPrivate();
            
            module.Initialize(new EventTelemetry());

            Assert.AreEqual("127.0.0.1", requestTelemetry.Context.Location.Ip);
        }
Esempio n. 3
0
        public void InitializeSetsLocationIpToUserHostAddressIfNoHeadersInRequest()
        {
            var module    = new TestableClientIpHeaderTelemetryInitializer();
            var telemetry = new EventTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
Esempio n. 4
0
        public void InitializeSetsLocationIpOfRequestToUserHostAddressIfNoHeadersInRequest()
        {
            var module           = new TestableClientIpHeaderTelemetryInitializer();
            var requestTelemetry = module.PlatformContext.CreateRequestTelemetryPrivate();

            module.Initialize(new EventTelemetry());

            Assert.AreEqual("127.0.0.1", requestTelemetry.Context.Location.Ip);
        }
        public void InitializeSetsLocationIpToUserHostAddressIfNoHeadersInRequest()
        {
            var module = new TestableClientIpHeaderTelemetryInitializer();
            var telemetry = new EventTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
        public void InitializeDoesNotSetLocationIpIfProvidedInline()
        {
            var module = new TestableClientIpHeaderTelemetryInitializer();
            var telemetry = new ExceptionTelemetry();
            telemetry.Context.Location.Ip = "10.10.10.10";

            module.Initialize(telemetry);

            Assert.AreEqual("10.10.10.10", telemetry.Context.Location.Ip);
        }
        public void InitializeSetsLocationIpToUserHostAddressFromXForwarderHeader()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "1.2.3.4" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new TraceTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
        public void InitializeGetsFirstIpIfHeaderHasSeveralIps()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "1.2.3.4, 2.3.4.5,3.4.5.6" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new EventTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
        public void InitializeCutsPortFromIp()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "1.2.3.4:54321" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new PageViewTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
Esempio n. 10
0
        public void InitializeDoesNotSetLocationIpIfProvidedInline()
        {
            var module    = new TestableClientIpHeaderTelemetryInitializer();
            var telemetry = new ExceptionTelemetry();

            telemetry.Context.Location.Ip = "10.10.10.10";

            module.Initialize(telemetry);

            Assert.AreEqual("10.10.10.10", telemetry.Context.Location.Ip);
        }
Esempio n. 11
0
        public void InitializeSetsLocationIpOfRequestToUserHostAddressFromXForwarderHeader()
        {
            var dictionary = new Dictionary <string, string> {
                { "X-Forwarded-For", "1.2.3.4" }
            };
            var module           = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var requestTelemetry = module.PlatformContext.CreateRequestTelemetryPrivate();

            module.Initialize(new SessionStateTelemetry());

            Assert.AreEqual("1.2.3.4", requestTelemetry.Context.Location.Ip);
        }
Esempio n. 12
0
        public void InitializeSetsLocationIpToUserHostAddressIfHeadersHasMalformedIp()
        {
            var dictionary = new Dictionary <string, string> {
                { "X-Forwarded-For", "bad" }
            };
            var module    = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new RequestTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
Esempio n. 13
0
        public void InitializeGetsFirstIpIfHeaderHasSeveralIps()
        {
            var dictionary = new Dictionary <string, string> {
                { "X-Forwarded-For", "1.2.3.4, 2.3.4.5,3.4.5.6" }
            };
            var module    = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new EventTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
Esempio n. 14
0
        public void InitializeSetsLocationIpToUserHostAddressFromXForwarderHeader()
        {
            var dictionary = new Dictionary <string, string> {
                { "X-Forwarded-For", "1.2.3.4" }
            };
            var module    = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new TraceTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
Esempio n. 15
0
        public void InitializeCutsPortFromIp()
        {
            var dictionary = new Dictionary <string, string> {
                { "X-Forwarded-For", "1.2.3.4:54321" }
            };
            var module    = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new PageViewTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
Esempio n. 16
0
        public void InitializeGetsLastIpIfHeaderHasSeveralIpsAndUseFirstIpFalse()
        {
            var dictionary = new Dictionary <string, string> {
                { "X-Forwarded-For", "1.2.3.4, 2.3.4.5" }
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary)
            {
                UseFirstIp = false
            };
            var telemetry = new ExceptionTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("2.3.4.5", telemetry.Context.Location.Ip);
        }
Esempio n. 17
0
        public void InitializeUsesCustomHeaderValueSeparatorIfProvidedInline()
        {
            var dictionary = new Dictionary <string, string>
            {
                { "X-Forwarded-For", "1.2.3.4;2.3.4.5,3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary)
            {
                HeaderValueSeparators = ",;"
            };
            var telemetry = new RequestTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
        public void InitializeGetsIpFromFirstAvailableHeader()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "CustomHeader1", "1.2.3.4, 2.3.4.5" },
                { "CustomHeader2", "3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            module.HeaderNames.Add("CustomHeader1");
            module.HeaderNames.Add("CustomHeader2");
            var telemetry = new PageViewTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
Esempio n. 19
0
        public void InitializeGetsIpFromHeaderProvidedInline()
        {
            var dictionary = new Dictionary <string, string>
            {
                { "X-Forwarded-For", "1.2.3.4, 2.3.4.5" },
                { "CustomHeader", "3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);

            module.HeaderNames.Clear();
            module.HeaderNames.Add("CustomHeader");
            var telemetry = new MetricTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("3.4.5.6", telemetry.Context.Location.Ip);
        }
Esempio n. 20
0
        public void InitializeSkipsHeadersThatHasIncorrectIps()
        {
            var dictionary = new Dictionary <string, string>
            {
                { "CustomHeader1", "BAD" },
                { "CustomHeader2", "3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);

            module.HeaderNames.Add("CustomHeader1");
            module.HeaderNames.Add("CustomHeader2");
            var telemetry = new SessionStateTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("3.4.5.6", telemetry.Context.Location.Ip);
        }
Esempio n. 21
0
        public void InitializeGetsIpFromFirstAvailableHeader()
        {
            var dictionary = new Dictionary <string, string>
            {
                { "CustomHeader1", "1.2.3.4, 2.3.4.5" },
                { "CustomHeader2", "3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);

            module.HeaderNames.Add("CustomHeader1");
            module.HeaderNames.Add("CustomHeader2");
            var telemetry = new PageViewTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }
        public void InitializeSkipsHeadersThatHasIncorrectIps()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "CustomHeader1", "BAD" },
                { "CustomHeader2", "3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            module.HeaderNames.Add("CustomHeader1");
            module.HeaderNames.Add("CustomHeader2");
            var telemetry = new SessionStateTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("3.4.5.6", telemetry.Context.Location.Ip);
        }
        public void InitializeSetsLocationIpOfRequestToUserHostAddressFromXForwarderHeader()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "1.2.3.4" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var requestTelemetry = module.PlatformContext.CreateRequestTelemetryPrivate();
            
            module.Initialize(new SessionStateTelemetry());

            Assert.AreEqual("1.2.3.4", requestTelemetry.Context.Location.Ip);
        }
        public void InitializeGetsIpFromHeaderProvidedInline()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "X-Forwarded-For", "1.2.3.4, 2.3.4.5" },
                { "CustomHeader", "3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            module.HeaderNames.Clear();
            module.HeaderNames.Add("CustomHeader");
            var telemetry = new MetricTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("3.4.5.6", telemetry.Context.Location.Ip);
        }
        public void InitializeSetsLocationIpToUserHostAddressIfHeadersIsEmpty()
        {
            var module = new TestableClientIpHeaderTelemetryInitializer(new Dictionary<string, string>());
            var telemetry = new PageViewTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
        public void InitializeSetsLocationIpToUserHostAddressIfHeadersHasMalformedIp()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "bad" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary);
            var telemetry = new RequestTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("127.0.0.1", telemetry.Context.Location.Ip);
        }
        public void InitializeGetsLastIpIfHeaderHasSeveralIpsAndUseFirstIpFalse()
        {
            var dictionary = new Dictionary<string, string> { { "X-Forwarded-For", "1.2.3.4, 2.3.4.5" } };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary) { UseFirstIp = false };
            var telemetry = new ExceptionTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("2.3.4.5", telemetry.Context.Location.Ip);
        }
        public void InitializeUsesCustomHeaderValueSeparatorIfProvidedInline()
        {
            var dictionary = new Dictionary<string, string>
            {
                { "X-Forwarded-For", "1.2.3.4;2.3.4.5,3.4.5.6" },
            };
            var module = new TestableClientIpHeaderTelemetryInitializer(dictionary) { HeaderValueSeparators = ",;" };
            var telemetry = new RequestTelemetry();

            module.Initialize(telemetry);

            Assert.AreEqual("1.2.3.4", telemetry.Context.Location.Ip);
        }