66 lines
2.4 KiB
C#
66 lines
2.4 KiB
C#
using System.Collections.Immutable;
|
||
using MongoDB.Bson;
|
||
using StellaOps.Feedser.Source.Common;
|
||
using StellaOps.Feedser.Models;
|
||
using StellaOps.Feedser.Source.Ru.Bdu.Internal;
|
||
using StellaOps.Feedser.Storage.Mongo.Documents;
|
||
using Xunit;
|
||
|
||
namespace StellaOps.Feedser.Source.Ru.Bdu.Tests;
|
||
|
||
public sealed class RuBduMapperTests
|
||
{
|
||
[Fact]
|
||
public void Map_ConstructsCanonicalAdvisory()
|
||
{
|
||
var dto = new RuBduVulnerabilityDto(
|
||
Identifier: "BDU:2025-12345",
|
||
Name: "Уязвимость тестового продукта",
|
||
Description: "Описание",
|
||
Solution: "Обновить",
|
||
IdentifyDate: new DateTimeOffset(2025, 10, 10, 0, 0, 0, TimeSpan.Zero),
|
||
SeverityText: "Высокий",
|
||
CvssVector: "AV:N/AC:L/Au:N/C:P/I:P/A:P",
|
||
CvssScore: 7.5,
|
||
Cvss3Vector: null,
|
||
Cvss3Score: null,
|
||
ExploitStatus: "Существует",
|
||
IncidentCount: 1,
|
||
FixStatus: "Устранена",
|
||
VulStatus: "Подтверждена",
|
||
VulClass: null,
|
||
VulState: null,
|
||
Other: null,
|
||
Software: new[]
|
||
{
|
||
new RuBduSoftwareDto("ООО Вендор", "Продукт", "1.2.3", "Windows", ImmutableArray<string>.Empty)
|
||
}.ToImmutableArray(),
|
||
Environment: ImmutableArray<RuBduEnvironmentDto>.Empty,
|
||
Cwes: new[] { new RuBduCweDto("CWE-79", "XSS") }.ToImmutableArray());
|
||
|
||
var document = new DocumentRecord(
|
||
Guid.NewGuid(),
|
||
RuBduConnectorPlugin.SourceName,
|
||
"https://bdu.fstec.ru/vul/2025-12345",
|
||
DateTimeOffset.UtcNow,
|
||
"abc",
|
||
DocumentStatuses.PendingMap,
|
||
"application/json",
|
||
null,
|
||
null,
|
||
null,
|
||
dto.IdentifyDate,
|
||
ObjectId.GenerateNewId());
|
||
|
||
var advisory = RuBduMapper.Map(dto, document, dto.IdentifyDate!.Value);
|
||
|
||
Assert.Equal("BDU:2025-12345", advisory.AdvisoryKey);
|
||
Assert.Contains("BDU:2025-12345", advisory.Aliases);
|
||
Assert.Equal("high", advisory.Severity);
|
||
Assert.True(advisory.ExploitKnown);
|
||
Assert.Single(advisory.AffectedPackages);
|
||
Assert.Single(advisory.CvssMetrics);
|
||
Assert.Contains(advisory.References, reference => reference.Url.Contains("bdu.fstec.ru", StringComparison.OrdinalIgnoreCase));
|
||
}
|
||
}
|