public void IPAddressProcessorStorageDisabled()
        {
            var settings = new QueryLoggerSettings()
            {
                StoreClientIPAddress = false
            };

            var result = IPAddressProcessor.Process("40.77.167.0", settings);

            Assert.Equal("PRIVATE", result);
        }
        public void IPAddressProcessorIPUnknown()
        {
            var settings = new QueryLoggerSettings()
            {
                StoreClientIPAddress = true
            };

            var result = IPAddressProcessor.Process("", settings);

            Assert.Equal("UNKNOWN", result);
        }
        public void IPAddressProcessorPartialAnonymizationIPv6()
        {
            var settings = new QueryLoggerSettings()
            {
                StoreClientIPAddress = true,
                AnonymizeIPAddress   = IPAddressAnonymizationLevel.Partial
            };

            var result = IPAddressProcessor.Process("2001:0db8:85a3:0000:0000:8a2e:0370:7334", settings);

            Assert.Equal("2001:0db8:85a3:0000:0000:0000:0000:0000", result);
        }
        public void IPAddressProcessorPartialAnonymizationIPv4()
        {
            var settings = new QueryLoggerSettings()
            {
                StoreClientIPAddress = true,
                AnonymizeIPAddress   = IPAddressAnonymizationLevel.Partial
            };

            var result = IPAddressProcessor.Process("40.77.167.23", settings);

            Assert.Equal("40.77.167.0", result);
        }
Ejemplo n.º 5
0
        public async void LoggingEnabled()
        {
            var configuration   = TestHelper.GetQueryLoggerConfiguration("typicalsettings.json");
            var serviceProvider = GetServiceProvider(configuration);
            var store           = serviceProvider.GetService <ILogStore>();
            var queryLogger     = serviceProvider.GetService <IQueryLogger>();
            var settings        = serviceProvider.GetService <IOptionsMonitor <QueryLoggerSettings> >();

            var category = "TestCategory";

            var autoPopulatedQuery = new Query()
            {
                QueryTerms    = "test1",
                QueryCategory = category
            };

            var userSpecifiedQueryID = Guid.NewGuid();

            var userSpecifiedQuery = new Query()
            {
                QueryID         = userSpecifiedQueryID,
                ApplicationName = "MyTestApp",
                QueryTerms      = "test2",
                Host            = "www.example.com",
                IPAddress       = "987.65.43.0"
            };

            queryLogger.Log(autoPopulatedQuery, userSpecifiedQuery);
            store.LogQueue.Writer.Complete();

            var queue = new List <Query>();

            while (await store.LogQueue.Reader.WaitToReadAsync())
            {
                if (store.LogQueue.Reader.TryRead(out Query query))
                {
                    queue.Add(query);
                }
            }

            var queueCount = queue.Count;

            Assert.Equal(2, queueCount);

            var queuedAutoPopulatedQuery = queue[0];
            var processedContextIP       = IPAddressProcessor.Process(_context.IPAddress, settings.CurrentValue);

            Assert.NotNull(queuedAutoPopulatedQuery.QueryID);
            Assert.Equal("RecordsApp", queuedAutoPopulatedQuery.ApplicationName);
            Assert.Equal(category, queuedAutoPopulatedQuery.QueryCategory);
            Assert.Equal(_context.Host, queuedAutoPopulatedQuery.Host);
            Assert.Equal(processedContextIP, queuedAutoPopulatedQuery.IPAddress);

            var queuedUserSpecifiedQuery = queue[1];

            Assert.Equal(userSpecifiedQueryID, queuedUserSpecifiedQuery.QueryID);
            Assert.Equal("MyTestApp", queuedUserSpecifiedQuery.ApplicationName);
            Assert.Null(queuedUserSpecifiedQuery.QueryCategory);
            Assert.NotEqual(_context.Host, queuedUserSpecifiedQuery.Host);
            Assert.NotEqual(processedContextIP, queuedUserSpecifiedQuery.IPAddress);
        }