Skip to content

Commit 904e244

Browse files
Updated IT test cases
1 parent 8f8dbf5 commit 904e244

File tree

4 files changed

+341
-1
lines changed

4 files changed

+341
-1
lines changed

src/LCT.SW360PackageCreator/URLHelper.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ public static string GetSourceUrlForAlpine(string pkgFilePath,string sourceData)
166166
Match url = Regex.Match(sourceData, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=$]*)?");
167167
string finalUrl = url.ToString();
168168
sourceUrl = finalUrl.Replace("$pkgver", pkgVersion).Replace("$_commit", _commitValue).Replace("$_tzcodever", _tzcodever);
169-
169+
if (pkgVersion == null && _commitValue == null && _tzcodever == null)
170+
{
171+
sourceUrl = string.Empty;
172+
}
173+
170174
}
171175
}
172176
catch (IOException ex)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// SPDX-FileCopyrightText: 2023 Siemens AG
3+
//
4+
// SPDX-License-Identifier: MIT
5+
6+
// --------------------------------------------------------------------------------------------------------------------
7+
8+
using System.Collections.Generic;
9+
using TestUtilities;
10+
using LCT.Common.Model;
11+
using System.IO;
12+
using NUnit.Framework;
13+
using CycloneDX.Models;
14+
15+
namespace SW360IntegrationTest.Alpine
16+
{
17+
[TestFixture, Order(27)]
18+
public class PackageIdentifierInitialAlpine
19+
{
20+
private string CCTLocalBomTestFile { get; set; }
21+
private string OutFolder { get; set; }
22+
TestParamAlpine testParameters;
23+
24+
[SetUp]
25+
public void Setup()
26+
{
27+
OutFolder = TestHelper.OutFolder;
28+
29+
CCTLocalBomTestFile = OutFolder + @"..\..\..\src\SW360IntegrationTest\PackageIdentifierTestFiles\Alpine\CCTLocalBOMAlpineInitial.json";
30+
31+
if (!Directory.Exists(OutFolder + @"\..\BOMs"))
32+
{
33+
Directory.CreateDirectory(OutFolder + @"\..\BOMs");
34+
}
35+
testParameters = new TestParamAlpine();
36+
}
37+
38+
[Test, Order(1)]
39+
public void RunBOMCreatorexe_ProvidedPackageJsonFilePath_ReturnsSuccess()
40+
{
41+
string packagejsonPath = OutFolder + @"\..\..\TestFiles\IntegrationTestFiles\SystemTest1stIterationData\Alpine";
42+
string bomPath = OutFolder + @"\..\BOMs";
43+
44+
// Test BOM Creator ran with exit code 0
45+
Assert.AreEqual(0, TestHelper.RunBOMCreatorExe(new string[]{
46+
TestConstant.PackageFilePath, packagejsonPath,
47+
TestConstant.BomFolderPath, bomPath,
48+
TestConstant.Sw360Token, testParameters.SW360AuthTokenValue,
49+
TestConstant.SW360AuthTokenType, testParameters.SW360AuthTokenType,
50+
TestConstant.SW360URL, testParameters.SW360URL,
51+
TestConstant.SW360ProjectID, testParameters.SW360ProjectID,
52+
TestConstant.SW360ProjectName, testParameters.SW360ProjectName,
53+
TestConstant.JFrogApiURL, testParameters.JfrogApi,
54+
TestConstant.ArtifactoryKey, testParameters.ArtifactoryUploadApiKey,
55+
TestConstant.ProjectType,"ALPINE",
56+
TestConstant.Mode,""}),
57+
"Test to run Package Identifier EXE execution");
58+
}
59+
60+
61+
62+
[Test, Order(2)]
63+
public void LocalBOMCreation_AfterSuccessfulExeRun_ReturnsSuccess()
64+
{
65+
bool fileExist = false;
66+
67+
// Expected
68+
ComponentJsonParsor expected = new ComponentJsonParsor();
69+
expected.Read(CCTLocalBomTestFile);
70+
71+
// Actual
72+
string generatedBOM = OutFolder + $"\\..\\BOMs\\{testParameters.SW360ProjectName}_Bom.cdx.json";
73+
if (File.Exists(generatedBOM))
74+
{
75+
fileExist = true;
76+
77+
ComponentJsonParsor actual = new ComponentJsonParsor();
78+
actual.Read(generatedBOM);
79+
80+
foreach (var item in expected.Components)
81+
{
82+
83+
foreach (var i in actual.Components)
84+
{
85+
if ((i.Name == item.Name) && (i.Version == item.Version))
86+
{
87+
Component component = i;
88+
Assert.AreEqual(item.Name, component.Name);
89+
Assert.AreEqual(item.Version, component.Version);
90+
Assert.AreEqual(item.Purl, component.Purl);
91+
Assert.AreEqual(item.BomRef, component.BomRef);
92+
}
93+
}
94+
95+
}
96+
}
97+
98+
Assert.IsTrue(fileExist, "Test to BOM file present");
99+
}
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
{
2+
"BomFormat": "CycloneDX",
3+
"SpecVersion": 4,
4+
"SpecVersionString": "1.4",
5+
"SerialNumber": "urn:uuid:80ef8e07-0343-46e3-898e-1eb298abd180",
6+
"Version": 1,
7+
"NonNullableVersion": 1,
8+
"Metadata": {
9+
"Timestamp": "2023-09-27T09:39:34Z",
10+
"Tools": [
11+
{
12+
"Vendor": "anchore",
13+
"Name": "syft",
14+
"Version": "0.89.0",
15+
"Hashes": null
16+
},
17+
{
18+
"Vendor": "Siemens AG",
19+
"Name": "Clearing Automation Tool",
20+
"Version": "3.1.2",
21+
"Hashes": null
22+
}
23+
],
24+
"Authors": null,
25+
"Component": {
26+
"Type": 7,
27+
"MimeType": null,
28+
"BomRef": "1d098408640ab242",
29+
"Supplier": null,
30+
"Author": null,
31+
"Publisher": null,
32+
"Group": null,
33+
"Name": "alpine",
34+
"Version": "sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33",
35+
"Description": null,
36+
"Scope": null,
37+
"Hashes": null,
38+
"Licenses": null,
39+
"Copyright": null,
40+
"Cpe": null,
41+
"Purl": null,
42+
"Swid": null,
43+
"Modified": null,
44+
"Pedigree": null,
45+
"Components": null,
46+
"Evidence": null
47+
},
48+
"Manufacture": null,
49+
"Supplier": null
50+
},
51+
"Components": [
52+
{
53+
"Type": 0,
54+
"MimeType": null,
55+
"BomRef": "pkg:apk/alpine/[email protected]?arch=source",
56+
"Supplier": null,
57+
"Author": null,
58+
"Publisher": null,
59+
"Group": null,
60+
"Name": "apk-tools",
61+
"Version": "2.12.9-r3",
62+
"Description": "",
63+
"Scope": null,
64+
"Hashes": null,
65+
"Licenses": null,
66+
"Copyright": null,
67+
"Cpe": null,
68+
"Purl": "pkg:apk/alpine/[email protected]?arch=source",
69+
"Swid": null,
70+
"Modified": null,
71+
"Pedigree": null,
72+
"Components": null,
73+
"Properties": [
74+
{
75+
"Name": "internal:siemens:clearing:identifier-type",
76+
"Value": "Discovered"
77+
},
78+
{
79+
"Name": "internal:siemens:clearing:is-internal",
80+
"Value": "false"
81+
},
82+
{
83+
"Name": "internal:siemens:clearing:repo-url",
84+
"Value": "Not Found in JFrogRepo"
85+
},
86+
{
87+
"Name": "internal:siemens:clearing:project-type",
88+
"Value": "Alpine"
89+
},
90+
{
91+
"Name": "internal:siemens:clearing:development",
92+
"Value": "false"
93+
}
94+
],
95+
"Evidence": null
96+
},
97+
{
98+
"Type": 0,
99+
"MimeType": null,
100+
"BomRef": "pkg:apk/alpine/[email protected]?arch=source",
101+
"Supplier": null,
102+
"Author": null,
103+
"Publisher": null,
104+
"Group": null,
105+
"Name": "busybox",
106+
"Version": "1.35.0-r17",
107+
"Description": "",
108+
"Scope": null,
109+
"Hashes": null,
110+
"Licenses": null,
111+
"Copyright": null,
112+
"Cpe": null,
113+
"Purl": "pkg:apk/alpine/[email protected]?arch=source",
114+
"Swid": null,
115+
"Modified": null,
116+
"Pedigree": null,
117+
"Components": null,
118+
"Properties": [
119+
{
120+
"Name": "internal:siemens:clearing:identifier-type",
121+
"Value": "Discovered"
122+
},
123+
{
124+
"Name": "internal:siemens:clearing:is-internal",
125+
"Value": "false"
126+
},
127+
{
128+
"Name": "internal:siemens:clearing:repo-url",
129+
"Value": "Not Found in JFrogRepo"
130+
},
131+
{
132+
"Name": "internal:siemens:clearing:project-type",
133+
"Value": "Alpine"
134+
},
135+
{
136+
"Name": "internal:siemens:clearing:development",
137+
"Value": "false"
138+
}
139+
],
140+
"Evidence": null
141+
},
142+
{
143+
"Type": 0,
144+
"MimeType": null,
145+
"BomRef": "pkg:apk/alpine/[email protected]?arch=source",
146+
"Supplier": null,
147+
"Author": null,
148+
"Publisher": null,
149+
"Group": null,
150+
"Name": "musl",
151+
"Version": "1.2.3-r0",
152+
"Description": "",
153+
"Scope": null,
154+
"Hashes": null,
155+
"Licenses": null,
156+
"Copyright": null,
157+
"Cpe": null,
158+
"Purl": "pkg:apk/alpine/[email protected]?arch=source",
159+
"Swid": null,
160+
"Modified": null,
161+
"Pedigree": null,
162+
"Components": null,
163+
"Properties": [
164+
{
165+
"Name": "internal:siemens:clearing:identifier-type",
166+
"Value": "Discovered"
167+
},
168+
{
169+
"Name": "internal:siemens:clearing:is-internal",
170+
"Value": "false"
171+
},
172+
{
173+
"Name": "internal:siemens:clearing:repo-url",
174+
"Value": "Not Found in JFrogRepo"
175+
},
176+
{
177+
"Name": "internal:siemens:clearing:project-type",
178+
"Value": "Alpine"
179+
},
180+
{
181+
"Name": "internal:siemens:clearing:development",
182+
"Value": "false"
183+
}
184+
],
185+
"Evidence": null
186+
},
187+
{
188+
"Type": 0,
189+
"MimeType": null,
190+
"BomRef": "pkg:apk/alpine/[email protected]?arch=source",
191+
"Supplier": null,
192+
"Author": null,
193+
"Publisher": null,
194+
"Group": null,
195+
"Name": "zlib",
196+
"Version": "1.2.12-r3",
197+
"Description": "",
198+
"Scope": null,
199+
"Hashes": null,
200+
"Licenses": null,
201+
"Copyright": null,
202+
"Cpe": null,
203+
"Purl": "pkg:apk/alpine/[email protected]?arch=source",
204+
"Swid": null,
205+
"Modified": null,
206+
"Pedigree": null,
207+
"Components": null,
208+
"Properties": [
209+
{
210+
"Name": "internal:siemens:clearing:identifier-type",
211+
"Value": "Discovered"
212+
},
213+
{
214+
"Name": "internal:siemens:clearing:is-internal",
215+
"Value": "false"
216+
},
217+
{
218+
"Name": "internal:siemens:clearing:repo-url",
219+
"Value": "Not Found in JFrogRepo"
220+
},
221+
{
222+
"Name": "internal:siemens:clearing:project-type",
223+
"Value": "Alpine"
224+
},
225+
{
226+
"Name": "internal:siemens:clearing:development",
227+
"Value": "false"
228+
}
229+
],
230+
"Evidence": null
231+
}
232+
],
233+
"Compositions": null
234+
}

src/SW360IntegrationTest/SW360IntegrationTest.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383
<ItemGroup>
8484
<Folder Include="Maven\" />
85+
<Folder Include="PackageIdentifierTestFiles\Alpine\" />
8586
</ItemGroup>
8687

8788
</Project>

0 commit comments

Comments
 (0)