-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.IO; | ||
using System.IO.Abstractions; | ||
using System.IO.Abstractions.TestingHelpers; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CycloneDX.Models; | ||
using Xunit; | ||
|
||
namespace CycloneDX.Tests.FunctionalTests | ||
{ | ||
public class MetaData | ||
{ | ||
private MockFileSystem getMockFS() | ||
{ | ||
return new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ MockUnixSupport.Path("c:/ProjectPath/obj/project.assets.json"), | ||
new MockFileData( | ||
File.ReadAllText(Path.Combine("FunctionalTests", "TestcaseFiles", "SimpleNET6.0Library.json"))) }, | ||
{ MockUnixSupport.Path("c:/ProjectPath/Project.csproj"), new MockFileData(FunctionalTestHelper.CsprojContents) }, | ||
{ MockUnixSupport.Path("c:/ProjectPath/metadata.xml"), | ||
new MockFileData( | ||
File.ReadAllText(Path.Combine("FunctionalTests", "TestcaseFiles", "metadata.xml"))) } | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task ImportedMetaDataAreInBomOutput() | ||
{ | ||
var options = new RunOptions | ||
{ | ||
importMetadataPath = MockUnixSupport.Path("c:/ProjectPath/metadata.xml") | ||
}; | ||
|
||
var bom = await FunctionalTestHelper.Test(options, getMockFS()); | ||
|
||
Assert.Equal("CycloneDX", bom.Metadata.Component.Name); | ||
Assert.Equal("1.3.0", bom.Metadata.Component.Version); | ||
Assert.Equal(Component.Classification.Application, bom.Metadata.Component.Type); | ||
Assert.False(string.IsNullOrEmpty(bom.Metadata.Component.Description)); | ||
Assert.Equal("Apache License 2.0", bom.Metadata.Component.Licenses.First().License.Name); | ||
Assert.Equal("Apache-2.0", bom.Metadata.Component.Licenses.First().License.Id); | ||
Assert.Equal("pkg:nuget/[email protected]", bom.Metadata.Component.Purl); | ||
} | ||
|
||
[Fact] | ||
public async Task IfNoMetadataIsImportedTimestampIsSetAutomatically() | ||
{ | ||
var options = new RunOptions | ||
{ | ||
}; | ||
|
||
var bom = await FunctionalTestHelper.Test(options, getMockFS()); | ||
Assert.True(bom.Metadata.Timestamp.Value > DateTime.UtcNow.AddMinutes(-10)); | ||
} | ||
|
||
[Fact] | ||
public async Task IfMetadataWithoutTimestampIsImportedTimestampStillGetsSet() | ||
{ | ||
var options = new RunOptions | ||
{ | ||
importMetadataPath = MockUnixSupport.Path("c:/ProjectPath/metadata.xml") | ||
}; | ||
|
||
var bom = await FunctionalTestHelper.Test(options, getMockFS()); | ||
Assert.True(bom.Metadata.Timestamp.Value > DateTime.UtcNow.AddMinutes(-10)); | ||
} | ||
|
||
[Fact(Skip ="Test schlägt fehl #821")] | ||
public async Task SetVersionOverwritesVersionWhenMetadataAreProvided() | ||
{ | ||
var options = new RunOptions | ||
{ | ||
importMetadataPath = MockUnixSupport.Path("c:/ProjectPath/metadata.xml"), | ||
setVersion = "3.0.4" | ||
|
||
}; | ||
|
||
var bom = await FunctionalTestHelper.Test(options, getMockFS()); | ||
|
||
Assert.Equal("CycloneDX", bom.Metadata.Component.Name); | ||
Assert.Equal("3.0.4", bom.Metadata.Component.Version); | ||
Assert.Equal(Component.Classification.Application, bom.Metadata.Component.Type); | ||
Assert.False(string.IsNullOrEmpty(bom.Metadata.Component.Description)); | ||
Assert.Equal("Apache License 2.0", bom.Metadata.Component.Licenses.First().License.Name); | ||
Assert.Equal("Apache-2.0", bom.Metadata.Component.Licenses.First().License.Id); | ||
Assert.Equal("pkg:nuget/[email protected]", bom.Metadata.Component.Purl); | ||
} | ||
|
||
[Fact(Skip = "Test schlägt fehl #821")] | ||
public async Task SetNameOverwritesNameWhenMetadataAreProvided() | ||
{ | ||
var options = new RunOptions | ||
{ | ||
importMetadataPath = MockUnixSupport.Path("c:/ProjectPath/metadata.xml"), | ||
setName = "Foo" | ||
|
||
}; | ||
|
||
var bom = await FunctionalTestHelper.Test(options, getMockFS()); | ||
|
||
Assert.Equal("Foo", bom.Metadata.Component.Name); | ||
Assert.Equal("1.3.0", bom.Metadata.Component.Version); | ||
Assert.Equal(Component.Classification.Application, bom.Metadata.Component.Type); | ||
Assert.False(string.IsNullOrEmpty(bom.Metadata.Component.Description)); | ||
Assert.Equal("Apache License 2.0", bom.Metadata.Component.Licenses.First().License.Name); | ||
Assert.Equal("Apache-2.0", bom.Metadata.Component.Licenses.First().License.Id); | ||
Assert.Equal("pkg:nuget/[email protected]", bom.Metadata.Component.Purl); | ||
} | ||
|
||
[Fact(Skip = "Test schlägt fehl #821")] | ||
public async Task SetTypeOverwritesTypeWhenMetadataAreProvided() | ||
{ | ||
var options = new RunOptions | ||
{ | ||
importMetadataPath = MockUnixSupport.Path("c:/ProjectPath/metadata.xml"), | ||
setType = Component.Classification.Container | ||
|
||
}; | ||
|
||
var bom = await FunctionalTestHelper.Test(options, getMockFS()); | ||
|
||
Assert.Equal("CycloneDX", bom.Metadata.Component.Name); | ||
Assert.Equal("1.3.0", bom.Metadata.Component.Version); | ||
Assert.Equal(Component.Classification.Container, bom.Metadata.Component.Type); | ||
Assert.False(string.IsNullOrEmpty(bom.Metadata.Component.Description)); | ||
Assert.Equal("Apache License 2.0", bom.Metadata.Component.Licenses.First().License.Name); | ||
Assert.Equal("Apache-2.0", bom.Metadata.Component.Licenses.First().License.Id); | ||
Assert.Equal("pkg:nuget/[email protected]", bom.Metadata.Component.Purl); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
CycloneDX.Tests/FunctionalTests/TestcaseFiles/metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<bom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serialNumber="urn:uuid:087d0712-f591-4995-ba76-03f1c5c48884" version="1" xmlns="http://cyclonedx.org/schema/bom/1.5"> | ||
<metadata> | ||
<component type="application" bom-ref="pkg:nuget/[email protected]"> | ||
<name>CycloneDX</name> | ||
<version>1.3.0</version> | ||
<description> | ||
<![CDATA[The [CycloneDX module](https://github.com/CycloneDX/cyclonedx-dotnet) for .NET creates a valid CycloneDX bill-of-material document containing an aggregate of all project dependencies. CycloneDX is a lightweight BOM specification that is easily created, human readable, and simple to parse.]]> | ||
</description> | ||
<licenses> | ||
<license> | ||
<name>Apache License 2.0</name> | ||
<id>Apache-2.0</id> | ||
</license> | ||
</licenses> | ||
<purl>pkg:nuget/[email protected]</purl> | ||
</component> | ||
</metadata> | ||
</bom> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters