Exemple #1
0
        public PackageStatistics FromCdnLogEntry(CdnLogEntry cdnLogEntry)
        {
            var packageDefinition = PackageDefinition.FromRequestUrl(cdnLogEntry.RequestUrl);

            if (packageDefinition == null)
            {
                return(null);
            }

            if (_packageTranslator != null)
            {
                packageDefinition = _packageTranslator.TranslatePackageDefinition(packageDefinition);
            }

            var statistic = new PackageStatistics();

            statistic.EdgeServerTimeDelivered = cdnLogEntry.EdgeServerTimeDelivered;
            statistic.PackageId      = packageDefinition.PackageId;
            statistic.PackageVersion = NormalizeSemanticVersion(packageDefinition.PackageVersion);

            var customFieldDictionary = CdnLogCustomFieldParser.Parse(cdnLogEntry.CustomField);

            statistic.Operation           = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetOperation);
            statistic.DependentPackage    = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetDependentPackage);
            statistic.ProjectGuids        = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetProjectGuids);
            statistic.UserAgent           = GetUserAgentValue(cdnLogEntry);
            statistic.EdgeServerIpAddress = cdnLogEntry.EdgeServerIpAddress;

            // ignore blacklisted user agents
            if (!IsBlackListed(statistic.UserAgent))
            {
                return(statistic);
            }
            return(null);
        }
Exemple #2
0
        public void FromCdnLogCustomFieldProperlyReturnsEmptyDictionaryForNullValue()
        {
            var customFields = CdnLogCustomFieldParser.Parse(null);

            Assert.NotNull(customFields);
            Assert.Equal(0, customFields.Count);
        }
Exemple #3
0
        public void FromCdnLogCustomFieldProperlyExtractsKeyValuePairs()
        {
            var customField  = "\"NuGet-Operation: - UA: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; AppInsights)\"";
            var customFields = CdnLogCustomFieldParser.Parse(customField);

            Assert.True(customFields.ContainsKey("NuGet-Operation"));
            Assert.Equal("-", customFields["NuGet-Operation"]);

            Assert.True(customFields.ContainsKey("UA"));
            Assert.Equal("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; AppInsights)", customFields["UA"]);
        }
        public PackageStatistics FromCdnLogEntry(CdnLogEntry cdnLogEntry)
        {
            var packageDefinitions = PackageDefinition.FromRequestUrl(cdnLogEntry.RequestUrl);

            if (packageDefinitions == null || !packageDefinitions.Any())
            {
                return(null);
            }

            if (packageDefinitions.Count > 1)
            {
                _logger.LogWarning(LogEvents.MultiplePackageIDVersionParseOptions,
                                   "Found multiple parse options for URL {RequestUrl}: {PackageDefinitions}",
                                   cdnLogEntry.RequestUrl,
                                   string.Join(", ", packageDefinitions));
            }

            var packageDefinition = packageDefinitions.First();

            if (_packageTranslator != null)
            {
                bool translateOccured = _packageTranslator.TryTranslatePackageDefinition(packageDefinition);

                if (translateOccured)
                {
                    _logger.LogInformation(LogEvents.TranslatedPackageIdVersion,
                                           "Translated package. Url: {RequestUrl}, New definition: {PackageDefinition}",
                                           cdnLogEntry.RequestUrl,
                                           packageDefinition);
                }
            }

            var statistic = new PackageStatistics();

            statistic.EdgeServerTimeDelivered = cdnLogEntry.EdgeServerTimeDelivered;
            statistic.PackageId      = packageDefinition.PackageId;
            statistic.PackageVersion = NormalizeSemanticVersion(packageDefinition.PackageVersion);

            var customFieldDictionary = CdnLogCustomFieldParser.Parse(cdnLogEntry.CustomField);

            statistic.Operation           = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetOperation);
            statistic.DependentPackage    = GetCustomFieldValue(customFieldDictionary, NuGetCustomHeaders.NuGetDependentPackage);
            statistic.UserAgent           = GetUserAgentValue(cdnLogEntry);
            statistic.EdgeServerIpAddress = cdnLogEntry.EdgeServerIpAddress;

            // Ignore blacklisted user agents
            if (!IsBlackListed(statistic.UserAgent))
            {
                return(statistic);
            }
            return(null);
        }
        public void FromCdnLogCustomFieldProperlyExtractsDependentPackage()
        {
            var customField  = "\"NuGet-Operation: Install-Dependency NuGet-DependentPackage: CefSharp.WinForms NuGet-ProjectGuids: {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\"";
            var customFields = CdnLogCustomFieldParser.Parse(customField);

            Assert.True(customFields.ContainsKey("NuGet-Operation"));
            Assert.Equal("Install-Dependency", customFields["NuGet-Operation"]);

            Assert.True(customFields.ContainsKey("NuGet-DependentPackage"));
            Assert.Equal("CefSharp.WinForms", customFields["NuGet-DependentPackage"]);

            Assert.True(customFields.ContainsKey("NuGet-ProjectGuids"));
            Assert.Equal("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", customFields["NuGet-ProjectGuids"]);
        }
        public void FromCdnLogCustomFieldProperlyExtractsEmptyProjectGuid()
        {
            var customField  = "\"NuGet-Operation: Install-Dependency NuGet-DependentPackage: - NuGet-ProjectGuids: -\"";
            var customFields = CdnLogCustomFieldParser.Parse(customField);

            Assert.True(customFields.ContainsKey("NuGet-Operation"));
            Assert.Equal("Install-Dependency", customFields["NuGet-Operation"]);

            Assert.True(customFields.ContainsKey("NuGet-DependentPackage"));
            Assert.Equal("-", customFields["NuGet-DependentPackage"]);

            Assert.True(customFields.ContainsKey("NuGet-ProjectGuids"));
            Assert.True(string.IsNullOrEmpty(customFields["NuGet-ProjectGuids"]));
        }
        public void FromCdnLogCustomFieldProperlyExtractsKeyValuePairsEvenIfUnordered()
        {
            var customField  = "\"NuGet-Operation: Install-Dependency NuGet-DependentPackage: - NuGet-ProjectGuids: {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\"";
            var customFields = CdnLogCustomFieldParser.Parse(customField);

            Assert.True(customFields.ContainsKey("NuGet-Operation"));
            Assert.Equal("Install-Dependency", customFields["NuGet-Operation"]);

            Assert.True(customFields.ContainsKey("NuGet-DependentPackage"));
            Assert.Equal("-", customFields["NuGet-DependentPackage"]);

            Assert.True(customFields.ContainsKey("NuGet-ProjectGuids"));
            Assert.Equal("{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", customFields["NuGet-ProjectGuids"]);
        }
        public void FromCdnLogCustomFieldProperlyExtractsKeyValuePairs()
        {
            var customField  = "\"NuGet-Operation: Install-Package NuGet-DependentPackage: - NuGet-ProjectGuids: {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - UA: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; AppInsights)\"";
            var customFields = CdnLogCustomFieldParser.Parse(customField);

            Assert.True(customFields.ContainsKey("NuGet-Operation"));
            Assert.Equal("Install-Package", customFields["NuGet-Operation"]);

            Assert.True(customFields.ContainsKey("NuGet-DependentPackage"));
            Assert.Equal("-", customFields["NuGet-DependentPackage"]);

            Assert.True(customFields.ContainsKey("NuGet-ProjectGuids"));
            Assert.Equal("{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}", customFields["NuGet-ProjectGuids"]);

            Assert.True(customFields.ContainsKey("UA"));
            Assert.Equal("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; AppInsights)", customFields["UA"]);
        }