blob: cc8805f927a0cbe9129e99e1fbb55b1a830baa04 [file] [log] [blame]
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +000018 "bytes"
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +000019 "encoding/json"
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +000020 "fmt"
21 "os"
22 "reflect"
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +000023 "strings"
24 "testing"
25 "time"
26
27 "android/soong/tools/compliance"
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +000028 "github.com/spdx/tools-golang/builder/builder2v2"
29 "github.com/spdx/tools-golang/spdx/common"
30 spdx "github.com/spdx/tools-golang/spdx/v2_2"
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +000031)
32
33func TestMain(m *testing.M) {
34 // Change into the parent directory before running the tests
35 // so they can find the testdata directory.
36 if err := os.Chdir(".."); err != nil {
37 fmt.Printf("failed to change to testdata directory: %s\n", err)
38 os.Exit(1)
39 }
40 os.Exit(m.Run())
41}
42
43func Test(t *testing.T) {
44 tests := []struct {
45 condition string
46 name string
47 outDir string
48 roots []string
49 stripPrefix string
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +000050 expectedOut *spdx.Document
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +000051 expectedDeps []string
52 }{
53 {
54 condition: "firstparty",
55 name: "apex",
56 roots: []string{"highest.apex.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +000057 expectedOut: &spdx.Document{
58 SPDXIdentifier: "DOCUMENT",
59 CreationInfo: getCreationInfo(t),
60 Packages: []*spdx.Package{
61 {
62 PackageName: "testdata-firstparty-highest.apex.meta_lic",
63 PackageVersion: "NOASSERTION",
64 PackageDownloadLocation: "NOASSERTION",
65 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-highest.apex.meta_lic"),
66 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
67 },
68 {
69 PackageName: "testdata-firstparty-bin-bin1.meta_lic",
70 PackageVersion: "NOASSERTION",
71 PackageDownloadLocation: "NOASSERTION",
72 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-bin-bin1.meta_lic"),
73 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
74 },
75 {
76 PackageName: "testdata-firstparty-bin-bin2.meta_lic",
77 PackageVersion: "NOASSERTION",
78 PackageDownloadLocation: "NOASSERTION",
79 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-bin-bin2.meta_lic"),
80 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
81 },
82 {
83 PackageName: "testdata-firstparty-lib-liba.so.meta_lic",
84 PackageVersion: "NOASSERTION",
85 PackageDownloadLocation: "NOASSERTION",
86 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-liba.so.meta_lic"),
87 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
88 },
89 {
90 PackageName: "testdata-firstparty-lib-libb.so.meta_lic",
91 PackageVersion: "NOASSERTION",
92 PackageDownloadLocation: "NOASSERTION",
93 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libb.so.meta_lic"),
94 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
95 },
96 {
97 PackageName: "testdata-firstparty-lib-libc.a.meta_lic",
98 PackageVersion: "NOASSERTION",
99 PackageDownloadLocation: "NOASSERTION",
100 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libc.a.meta_lic"),
101 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
102 },
103 {
104 PackageName: "testdata-firstparty-lib-libd.so.meta_lic",
105 PackageVersion: "NOASSERTION",
106 PackageDownloadLocation: "NOASSERTION",
107 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libd.so.meta_lic"),
108 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
109 },
110 },
111 Relationships: []*spdx.Relationship{
112 {
113 RefA: common.MakeDocElementID("", "DOCUMENT"),
114 RefB: common.MakeDocElementID("", "testdata-firstparty-highest.apex.meta_lic"),
115 Relationship: "DESCRIBES",
116 },
117 {
118 RefA: common.MakeDocElementID("", "testdata-firstparty-highest.apex.meta_lic"),
119 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
120 Relationship: "CONTAINS",
121 },
122 {
123 RefA: common.MakeDocElementID("", "testdata-firstparty-highest.apex.meta_lic"),
124 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin2.meta_lic"),
125 Relationship: "CONTAINS",
126 },
127 {
128 RefA: common.MakeDocElementID("", "testdata-firstparty-highest.apex.meta_lic"),
129 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-liba.so.meta_lic"),
130 Relationship: "CONTAINS",
131 },
132 {
133 RefA: common.MakeDocElementID("", "testdata-firstparty-highest.apex.meta_lic"),
134 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-libb.so.meta_lic"),
135 Relationship: "CONTAINS",
136 },
137 {
138 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
139 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-liba.so.meta_lic"),
140 Relationship: "CONTAINS",
141 },
142 {
143 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
144 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-libc.a.meta_lic"),
145 Relationship: "CONTAINS",
146 },
147 {
148 RefA: common.MakeDocElementID("", "testdata-firstparty-lib-libb.so.meta_lic"),
149 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin2.meta_lic"),
150 Relationship: "RUNTIME_DEPENDENCY_OF",
151 },
152 {
153 RefA: common.MakeDocElementID("", "testdata-firstparty-lib-libd.so.meta_lic"),
154 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin2.meta_lic"),
155 Relationship: "RUNTIME_DEPENDENCY_OF",
156 },
157 },
158 OtherLicenses: []*spdx.OtherLicense{
159 {
160 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
161 ExtractedText: "&&&First Party License&&&\n",
162 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
163 },
164 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000165 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000166 expectedDeps: []string{
167 "testdata/firstparty/FIRST_PARTY_LICENSE",
168 "testdata/firstparty/bin/bin1.meta_lic",
169 "testdata/firstparty/bin/bin2.meta_lic",
170 "testdata/firstparty/highest.apex.meta_lic",
171 "testdata/firstparty/lib/liba.so.meta_lic",
172 "testdata/firstparty/lib/libb.so.meta_lic",
173 "testdata/firstparty/lib/libc.a.meta_lic",
174 "testdata/firstparty/lib/libd.so.meta_lic",
175 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000176 },
177 {
178 condition: "firstparty",
179 name: "application",
180 roots: []string{"application.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000181 expectedOut: &spdx.Document{
182 SPDXIdentifier: "DOCUMENT",
183 CreationInfo: getCreationInfo(t),
184 Packages: []*spdx.Package{
185 {
186 PackageName: "testdata-firstparty-application.meta_lic",
187 PackageVersion: "NOASSERTION",
188 PackageDownloadLocation: "NOASSERTION",
189 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-application.meta_lic"),
190 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
191 },
192 {
193 PackageName: "testdata-firstparty-bin-bin3.meta_lic",
194 PackageVersion: "NOASSERTION",
195 PackageDownloadLocation: "NOASSERTION",
196 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-bin-bin3.meta_lic"),
197 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
198 },
199 {
200 PackageName: "testdata-firstparty-lib-liba.so.meta_lic",
201 PackageVersion: "NOASSERTION",
202 PackageDownloadLocation: "NOASSERTION",
203 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-liba.so.meta_lic"),
204 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
205 },
206 {
207 PackageName: "testdata-firstparty-lib-libb.so.meta_lic",
208 PackageVersion: "NOASSERTION",
209 PackageDownloadLocation: "NOASSERTION",
210 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libb.so.meta_lic"),
211 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
212 },
213 },
214 Relationships: []*spdx.Relationship{
215 {
216 RefA: common.MakeDocElementID("", "DOCUMENT"),
217 RefB: common.MakeDocElementID("", "testdata-firstparty-application.meta_lic"),
218 Relationship: "DESCRIBES",
219 },
220 {
221 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin3.meta_lic"),
222 RefB: common.MakeDocElementID("", "testdata-firstparty-application.meta_lic"),
223 Relationship: "BUILD_TOOL_OF",
224 },
225 {
226 RefA: common.MakeDocElementID("", "testdata-firstparty-application.meta_lic"),
227 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-liba.so.meta_lic"),
228 Relationship: "CONTAINS",
229 },
230 {
231 RefA: common.MakeDocElementID("", "testdata-firstparty-lib-libb.so.meta_lic"),
232 RefB: common.MakeDocElementID("", "testdata-firstparty-application.meta_lic"),
233 Relationship: "RUNTIME_DEPENDENCY_OF",
234 },
235 },
236 OtherLicenses: []*spdx.OtherLicense{
237 {
238 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
239 ExtractedText: "&&&First Party License&&&\n",
240 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
241 },
242 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000243 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000244 expectedDeps: []string{
245 "testdata/firstparty/FIRST_PARTY_LICENSE",
246 "testdata/firstparty/application.meta_lic",
247 "testdata/firstparty/bin/bin3.meta_lic",
248 "testdata/firstparty/lib/liba.so.meta_lic",
249 "testdata/firstparty/lib/libb.so.meta_lic",
250 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000251 },
252 {
253 condition: "firstparty",
254 name: "container",
255 roots: []string{"container.zip.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000256 expectedOut: &spdx.Document{
257 SPDXIdentifier: "DOCUMENT",
258 CreationInfo: getCreationInfo(t),
259 Packages: []*spdx.Package{
260 {
261 PackageName: "testdata-firstparty-container.zip.meta_lic",
262 PackageVersion: "NOASSERTION",
263 PackageDownloadLocation: "NOASSERTION",
264 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-container.zip.meta_lic"),
265 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
266 },
267 {
268 PackageName: "testdata-firstparty-bin-bin1.meta_lic",
269 PackageVersion: "NOASSERTION",
270 PackageDownloadLocation: "NOASSERTION",
271 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-bin-bin1.meta_lic"),
272 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
273 },
274 {
275 PackageName: "testdata-firstparty-bin-bin2.meta_lic",
276 PackageVersion: "NOASSERTION",
277 PackageDownloadLocation: "NOASSERTION",
278 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-bin-bin2.meta_lic"),
279 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
280 },
281 {
282 PackageName: "testdata-firstparty-lib-liba.so.meta_lic",
283 PackageVersion: "NOASSERTION",
284 PackageDownloadLocation: "NOASSERTION",
285 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-liba.so.meta_lic"),
286 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
287 },
288 {
289 PackageName: "testdata-firstparty-lib-libb.so.meta_lic",
290 PackageVersion: "NOASSERTION",
291 PackageDownloadLocation: "NOASSERTION",
292 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libb.so.meta_lic"),
293 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
294 },
295 {
296 PackageName: "testdata-firstparty-lib-libc.a.meta_lic",
297 PackageVersion: "NOASSERTION",
298 PackageDownloadLocation: "NOASSERTION",
299 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libc.a.meta_lic"),
300 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
301 },
302 {
303 PackageName: "testdata-firstparty-lib-libd.so.meta_lic",
304 PackageVersion: "NOASSERTION",
305 PackageDownloadLocation: "NOASSERTION",
306 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libd.so.meta_lic"),
307 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
308 },
309 },
310 Relationships: []*spdx.Relationship{
311 {
312 RefA: common.MakeDocElementID("", "DOCUMENT"),
313 RefB: common.MakeDocElementID("", "testdata-firstparty-container.zip.meta_lic"),
314 Relationship: "DESCRIBES",
315 },
316 {
317 RefA: common.MakeDocElementID("", "testdata-firstparty-container.zip.meta_lic"),
318 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
319 Relationship: "CONTAINS",
320 },
321 {
322 RefA: common.MakeDocElementID("", "testdata-firstparty-container.zip.meta_lic"),
323 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin2.meta_lic"),
324 Relationship: "CONTAINS",
325 },
326 {
327 RefA: common.MakeDocElementID("", "testdata-firstparty-container.zip.meta_lic"),
328 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-liba.so.meta_lic"),
329 Relationship: "CONTAINS",
330 },
331 {
332 RefA: common.MakeDocElementID("", "testdata-firstparty-container.zip.meta_lic"),
333 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-libb.so.meta_lic"),
334 Relationship: "CONTAINS",
335 },
336 {
337 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
338 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-liba.so.meta_lic"),
339 Relationship: "CONTAINS",
340 },
341 {
342 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
343 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-libc.a.meta_lic"),
344 Relationship: "CONTAINS",
345 },
346 {
347 RefA: common.MakeDocElementID("", "testdata-firstparty-lib-libb.so.meta_lic"),
348 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin2.meta_lic"),
349 Relationship: "RUNTIME_DEPENDENCY_OF",
350 },
351 {
352 RefA: common.MakeDocElementID("", "testdata-firstparty-lib-libd.so.meta_lic"),
353 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin2.meta_lic"),
354 Relationship: "RUNTIME_DEPENDENCY_OF",
355 },
356 },
357 OtherLicenses: []*spdx.OtherLicense{
358 {
359 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
360 ExtractedText: "&&&First Party License&&&\n",
361 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
362 },
363 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000364 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000365 expectedDeps: []string{
366 "testdata/firstparty/FIRST_PARTY_LICENSE",
367 "testdata/firstparty/bin/bin1.meta_lic",
368 "testdata/firstparty/bin/bin2.meta_lic",
369 "testdata/firstparty/container.zip.meta_lic",
370 "testdata/firstparty/lib/liba.so.meta_lic",
371 "testdata/firstparty/lib/libb.so.meta_lic",
372 "testdata/firstparty/lib/libc.a.meta_lic",
373 "testdata/firstparty/lib/libd.so.meta_lic",
374 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000375 },
376 {
377 condition: "firstparty",
378 name: "binary",
379 roots: []string{"bin/bin1.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000380 expectedOut: &spdx.Document{
381 SPDXIdentifier: "DOCUMENT",
382 CreationInfo: getCreationInfo(t),
383 Packages: []*spdx.Package{
384 {
385 PackageName: "testdata-firstparty-bin-bin1.meta_lic",
386 PackageVersion: "NOASSERTION",
387 PackageDownloadLocation: "NOASSERTION",
388 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-bin-bin1.meta_lic"),
389 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
390 },
391 {
392 PackageName: "testdata-firstparty-lib-liba.so.meta_lic",
393 PackageVersion: "NOASSERTION",
394 PackageDownloadLocation: "NOASSERTION",
395 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-liba.so.meta_lic"),
396 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
397 },
398 {
399 PackageName: "testdata-firstparty-lib-libc.a.meta_lic",
400 PackageVersion: "NOASSERTION",
401 PackageDownloadLocation: "NOASSERTION",
402 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libc.a.meta_lic"),
403 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
404 },
405 },
406 Relationships: []*spdx.Relationship{
407 {
408 RefA: common.MakeDocElementID("", "DOCUMENT"),
409 RefB: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
410 Relationship: "DESCRIBES",
411 },
412 {
413 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
414 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-liba.so.meta_lic"),
415 Relationship: "CONTAINS",
416 },
417 {
418 RefA: common.MakeDocElementID("", "testdata-firstparty-bin-bin1.meta_lic"),
419 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-libc.a.meta_lic"),
420 Relationship: "CONTAINS",
421 },
422 },
423 OtherLicenses: []*spdx.OtherLicense{
424 {
425 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
426 ExtractedText: "&&&First Party License&&&\n",
427 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
428 },
429 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000430 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000431 expectedDeps: []string{
432 "testdata/firstparty/FIRST_PARTY_LICENSE",
433 "testdata/firstparty/bin/bin1.meta_lic",
434 "testdata/firstparty/lib/liba.so.meta_lic",
435 "testdata/firstparty/lib/libc.a.meta_lic",
436 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000437 },
438 {
439 condition: "firstparty",
440 name: "library",
441 roots: []string{"lib/libd.so.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000442 expectedOut: &spdx.Document{
443 SPDXIdentifier: "DOCUMENT",
444 CreationInfo: getCreationInfo(t),
445 Packages: []*spdx.Package{
446 {
447 PackageName: "testdata-firstparty-lib-libd.so.meta_lic",
448 PackageVersion: "NOASSERTION",
449 PackageDownloadLocation: "NOASSERTION",
450 PackageSPDXIdentifier: common.ElementID("testdata-firstparty-lib-libd.so.meta_lic"),
451 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
452 },
453 },
454 Relationships: []*spdx.Relationship{
455 {
456 RefA: common.MakeDocElementID("", "DOCUMENT"),
457 RefB: common.MakeDocElementID("", "testdata-firstparty-lib-libd.so.meta_lic"),
458 Relationship: "DESCRIBES",
459 },
460 },
461 OtherLicenses: []*spdx.OtherLicense{
462 {
463 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
464 ExtractedText: "&&&First Party License&&&\n",
465 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
466 },
467 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000468 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000469 expectedDeps: []string{
470 "testdata/firstparty/FIRST_PARTY_LICENSE",
471 "testdata/firstparty/lib/libd.so.meta_lic",
472 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000473 },
474 {
475 condition: "notice",
476 name: "apex",
477 roots: []string{"highest.apex.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000478 expectedOut: &spdx.Document{
479 SPDXIdentifier: "DOCUMENT",
480 CreationInfo: getCreationInfo(t),
481 Packages: []*spdx.Package{
482 {
483 PackageName: "testdata-notice-highest.apex.meta_lic",
484 PackageVersion: "NOASSERTION",
485 PackageDownloadLocation: "NOASSERTION",
486 PackageSPDXIdentifier: common.ElementID("testdata-notice-highest.apex.meta_lic"),
487 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
488 },
489 {
490 PackageName: "testdata-notice-bin-bin1.meta_lic",
491 PackageVersion: "NOASSERTION",
492 PackageDownloadLocation: "NOASSERTION",
493 PackageSPDXIdentifier: common.ElementID("testdata-notice-bin-bin1.meta_lic"),
494 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
495 },
496 {
497 PackageName: "testdata-notice-bin-bin2.meta_lic",
498 PackageVersion: "NOASSERTION",
499 PackageDownloadLocation: "NOASSERTION",
500 PackageSPDXIdentifier: common.ElementID("testdata-notice-bin-bin2.meta_lic"),
501 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
502 },
503 {
504 PackageName: "testdata-notice-lib-liba.so.meta_lic",
505 PackageVersion: "NOASSERTION",
506 PackageDownloadLocation: "NOASSERTION",
507 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-liba.so.meta_lic"),
508 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
509 },
510 {
511 PackageName: "testdata-notice-lib-libb.so.meta_lic",
512 PackageVersion: "NOASSERTION",
513 PackageDownloadLocation: "NOASSERTION",
514 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libb.so.meta_lic"),
515 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
516 },
517 {
518 PackageName: "testdata-notice-lib-libc.a.meta_lic",
519 PackageVersion: "NOASSERTION",
520 PackageDownloadLocation: "NOASSERTION",
521 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libc.a.meta_lic"),
522 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
523 },
524 {
525 PackageName: "testdata-notice-lib-libd.so.meta_lic",
526 PackageVersion: "NOASSERTION",
527 PackageDownloadLocation: "NOASSERTION",
528 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libd.so.meta_lic"),
529 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
530 },
531 },
532 Relationships: []*spdx.Relationship{
533 {
534 RefA: common.MakeDocElementID("", "DOCUMENT"),
535 RefB: common.MakeDocElementID("", "testdata-notice-highest.apex.meta_lic"),
536 Relationship: "DESCRIBES",
537 },
538 {
539 RefA: common.MakeDocElementID("", "testdata-notice-highest.apex.meta_lic"),
540 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
541 Relationship: "CONTAINS",
542 },
543 {
544 RefA: common.MakeDocElementID("", "testdata-notice-highest.apex.meta_lic"),
545 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin2.meta_lic"),
546 Relationship: "CONTAINS",
547 },
548 {
549 RefA: common.MakeDocElementID("", "testdata-notice-highest.apex.meta_lic"),
550 RefB: common.MakeDocElementID("", "testdata-notice-lib-liba.so.meta_lic"),
551 Relationship: "CONTAINS",
552 },
553 {
554 RefA: common.MakeDocElementID("", "testdata-notice-highest.apex.meta_lic"),
555 RefB: common.MakeDocElementID("", "testdata-notice-lib-libb.so.meta_lic"),
556 Relationship: "CONTAINS",
557 },
558 {
559 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
560 RefB: common.MakeDocElementID("", "testdata-notice-lib-liba.so.meta_lic"),
561 Relationship: "CONTAINS",
562 },
563 {
564 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
565 RefB: common.MakeDocElementID("", "testdata-notice-lib-libc.a.meta_lic"),
566 Relationship: "CONTAINS",
567 },
568 {
569 RefA: common.MakeDocElementID("", "testdata-notice-lib-libb.so.meta_lic"),
570 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin2.meta_lic"),
571 Relationship: "RUNTIME_DEPENDENCY_OF",
572 },
573 {
574 RefA: common.MakeDocElementID("", "testdata-notice-lib-libd.so.meta_lic"),
575 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin2.meta_lic"),
576 Relationship: "RUNTIME_DEPENDENCY_OF",
577 },
578 },
579 OtherLicenses: []*spdx.OtherLicense{
580 {
581 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
582 ExtractedText: "&&&First Party License&&&\n",
583 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
584 },
585 {
586 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
587 ExtractedText: "%%%Notice License%%%\n",
588 LicenseName: "testdata-notice-NOTICE_LICENSE",
589 },
590 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000591 },
592 expectedDeps: []string{
593 "testdata/firstparty/FIRST_PARTY_LICENSE",
594 "testdata/notice/NOTICE_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000595 "testdata/notice/bin/bin1.meta_lic",
596 "testdata/notice/bin/bin2.meta_lic",
597 "testdata/notice/highest.apex.meta_lic",
598 "testdata/notice/lib/liba.so.meta_lic",
599 "testdata/notice/lib/libb.so.meta_lic",
600 "testdata/notice/lib/libc.a.meta_lic",
601 "testdata/notice/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000602 },
603 },
604 {
605 condition: "notice",
606 name: "container",
607 roots: []string{"container.zip.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000608 expectedOut: &spdx.Document{
609 SPDXIdentifier: "DOCUMENT",
610 CreationInfo: getCreationInfo(t),
611 Packages: []*spdx.Package{
612 {
613 PackageName: "testdata-notice-container.zip.meta_lic",
614 PackageVersion: "NOASSERTION",
615 PackageDownloadLocation: "NOASSERTION",
616 PackageSPDXIdentifier: common.ElementID("testdata-notice-container.zip.meta_lic"),
617 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
618 },
619 {
620 PackageName: "testdata-notice-bin-bin1.meta_lic",
621 PackageVersion: "NOASSERTION",
622 PackageDownloadLocation: "NOASSERTION",
623 PackageSPDXIdentifier: common.ElementID("testdata-notice-bin-bin1.meta_lic"),
624 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
625 },
626 {
627 PackageName: "testdata-notice-bin-bin2.meta_lic",
628 PackageVersion: "NOASSERTION",
629 PackageDownloadLocation: "NOASSERTION",
630 PackageSPDXIdentifier: common.ElementID("testdata-notice-bin-bin2.meta_lic"),
631 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
632 },
633 {
634 PackageName: "testdata-notice-lib-liba.so.meta_lic",
635 PackageVersion: "NOASSERTION",
636 PackageDownloadLocation: "NOASSERTION",
637 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-liba.so.meta_lic"),
638 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
639 },
640 {
641 PackageName: "testdata-notice-lib-libb.so.meta_lic",
642 PackageVersion: "NOASSERTION",
643 PackageDownloadLocation: "NOASSERTION",
644 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libb.so.meta_lic"),
645 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
646 },
647 {
648 PackageName: "testdata-notice-lib-libc.a.meta_lic",
649 PackageVersion: "NOASSERTION",
650 PackageDownloadLocation: "NOASSERTION",
651 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libc.a.meta_lic"),
652 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
653 },
654 {
655 PackageName: "testdata-notice-lib-libd.so.meta_lic",
656 PackageVersion: "NOASSERTION",
657 PackageDownloadLocation: "NOASSERTION",
658 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libd.so.meta_lic"),
659 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
660 },
661 },
662 Relationships: []*spdx.Relationship{
663 {
664 RefA: common.MakeDocElementID("", "DOCUMENT"),
665 RefB: common.MakeDocElementID("", "testdata-notice-container.zip.meta_lic"),
666 Relationship: "DESCRIBES",
667 },
668 {
669 RefA: common.MakeDocElementID("", "testdata-notice-container.zip.meta_lic"),
670 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
671 Relationship: "CONTAINS",
672 },
673 {
674 RefA: common.MakeDocElementID("", "testdata-notice-container.zip.meta_lic"),
675 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin2.meta_lic"),
676 Relationship: "CONTAINS",
677 },
678 {
679 RefA: common.MakeDocElementID("", "testdata-notice-container.zip.meta_lic"),
680 RefB: common.MakeDocElementID("", "testdata-notice-lib-liba.so.meta_lic"),
681 Relationship: "CONTAINS",
682 },
683 {
684 RefA: common.MakeDocElementID("", "testdata-notice-container.zip.meta_lic"),
685 RefB: common.MakeDocElementID("", "testdata-notice-lib-libb.so.meta_lic"),
686 Relationship: "CONTAINS",
687 },
688 {
689 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
690 RefB: common.MakeDocElementID("", "testdata-notice-lib-liba.so.meta_lic"),
691 Relationship: "CONTAINS",
692 },
693 {
694 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
695 RefB: common.MakeDocElementID("", "testdata-notice-lib-libc.a.meta_lic"),
696 Relationship: "CONTAINS",
697 },
698 {
699 RefA: common.MakeDocElementID("", "testdata-notice-lib-libb.so.meta_lic"),
700 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin2.meta_lic"),
701 Relationship: "RUNTIME_DEPENDENCY_OF",
702 },
703 {
704 RefA: common.MakeDocElementID("", "testdata-notice-lib-libd.so.meta_lic"),
705 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin2.meta_lic"),
706 Relationship: "RUNTIME_DEPENDENCY_OF",
707 },
708 },
709 OtherLicenses: []*spdx.OtherLicense{
710 {
711 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
712 ExtractedText: "&&&First Party License&&&\n",
713 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
714 },
715 {
716 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
717 ExtractedText: "%%%Notice License%%%\n",
718 LicenseName: "testdata-notice-NOTICE_LICENSE",
719 },
720 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000721 },
722 expectedDeps: []string{
723 "testdata/firstparty/FIRST_PARTY_LICENSE",
724 "testdata/notice/NOTICE_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000725 "testdata/notice/bin/bin1.meta_lic",
726 "testdata/notice/bin/bin2.meta_lic",
727 "testdata/notice/container.zip.meta_lic",
728 "testdata/notice/lib/liba.so.meta_lic",
729 "testdata/notice/lib/libb.so.meta_lic",
730 "testdata/notice/lib/libc.a.meta_lic",
731 "testdata/notice/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000732 },
733 },
734 {
735 condition: "notice",
736 name: "application",
737 roots: []string{"application.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000738 expectedOut: &spdx.Document{
739 SPDXIdentifier: "DOCUMENT",
740 CreationInfo: getCreationInfo(t),
741 Packages: []*spdx.Package{
742 {
743 PackageName: "testdata-notice-application.meta_lic",
744 PackageVersion: "NOASSERTION",
745 PackageDownloadLocation: "NOASSERTION",
746 PackageSPDXIdentifier: common.ElementID("testdata-notice-application.meta_lic"),
747 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
748 },
749 {
750 PackageName: "testdata-notice-bin-bin3.meta_lic",
751 PackageVersion: "NOASSERTION",
752 PackageDownloadLocation: "NOASSERTION",
753 PackageSPDXIdentifier: common.ElementID("testdata-notice-bin-bin3.meta_lic"),
754 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
755 },
756 {
757 PackageName: "testdata-notice-lib-liba.so.meta_lic",
758 PackageVersion: "NOASSERTION",
759 PackageDownloadLocation: "NOASSERTION",
760 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-liba.so.meta_lic"),
761 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
762 },
763 {
764 PackageName: "testdata-notice-lib-libb.so.meta_lic",
765 PackageVersion: "NOASSERTION",
766 PackageDownloadLocation: "NOASSERTION",
767 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libb.so.meta_lic"),
768 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
769 },
770 },
771 Relationships: []*spdx.Relationship{
772 {
773 RefA: common.MakeDocElementID("", "DOCUMENT"),
774 RefB: common.MakeDocElementID("", "testdata-notice-application.meta_lic"),
775 Relationship: "DESCRIBES",
776 },
777 {
778 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin3.meta_lic"),
779 RefB: common.MakeDocElementID("", "testdata-notice-application.meta_lic"),
780 Relationship: "BUILD_TOOL_OF",
781 },
782 {
783 RefA: common.MakeDocElementID("", "testdata-notice-application.meta_lic"),
784 RefB: common.MakeDocElementID("", "testdata-notice-lib-liba.so.meta_lic"),
785 Relationship: "CONTAINS",
786 },
787 {
788 RefA: common.MakeDocElementID("", "testdata-notice-lib-libb.so.meta_lic"),
789 RefB: common.MakeDocElementID("", "testdata-notice-application.meta_lic"),
790 Relationship: "RUNTIME_DEPENDENCY_OF",
791 },
792 },
793 OtherLicenses: []*spdx.OtherLicense{
794 {
795 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
796 ExtractedText: "&&&First Party License&&&\n",
797 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
798 },
799 {
800 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
801 ExtractedText: "%%%Notice License%%%\n",
802 LicenseName: "testdata-notice-NOTICE_LICENSE",
803 },
804 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000805 },
806 expectedDeps: []string{
807 "testdata/firstparty/FIRST_PARTY_LICENSE",
808 "testdata/notice/NOTICE_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000809 "testdata/notice/application.meta_lic",
810 "testdata/notice/bin/bin3.meta_lic",
811 "testdata/notice/lib/liba.so.meta_lic",
812 "testdata/notice/lib/libb.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000813 },
814 },
815 {
816 condition: "notice",
817 name: "binary",
818 roots: []string{"bin/bin1.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000819 expectedOut: &spdx.Document{
820 SPDXIdentifier: "DOCUMENT",
821 CreationInfo: getCreationInfo(t),
822 Packages: []*spdx.Package{
823 {
824 PackageName: "testdata-notice-bin-bin1.meta_lic",
825 PackageVersion: "NOASSERTION",
826 PackageDownloadLocation: "NOASSERTION",
827 PackageSPDXIdentifier: common.ElementID("testdata-notice-bin-bin1.meta_lic"),
828 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
829 },
830 {
831 PackageName: "testdata-notice-lib-liba.so.meta_lic",
832 PackageVersion: "NOASSERTION",
833 PackageDownloadLocation: "NOASSERTION",
834 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-liba.so.meta_lic"),
835 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
836 },
837 {
838 PackageName: "testdata-notice-lib-libc.a.meta_lic",
839 PackageVersion: "NOASSERTION",
840 PackageDownloadLocation: "NOASSERTION",
841 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libc.a.meta_lic"),
842 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
843 },
844 },
845 Relationships: []*spdx.Relationship{
846 {
847 RefA: common.MakeDocElementID("", "DOCUMENT"),
848 RefB: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
849 Relationship: "DESCRIBES",
850 },
851 {
852 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
853 RefB: common.MakeDocElementID("", "testdata-notice-lib-liba.so.meta_lic"),
854 Relationship: "CONTAINS",
855 },
856 {
857 RefA: common.MakeDocElementID("", "testdata-notice-bin-bin1.meta_lic"),
858 RefB: common.MakeDocElementID("", "testdata-notice-lib-libc.a.meta_lic"),
859 Relationship: "CONTAINS",
860 },
861 },
862 OtherLicenses: []*spdx.OtherLicense{
863 {
864 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
865 ExtractedText: "&&&First Party License&&&\n",
866 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
867 },
868 {
869 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
870 ExtractedText: "%%%Notice License%%%\n",
871 LicenseName: "testdata-notice-NOTICE_LICENSE",
872 },
873 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000874 },
875 expectedDeps: []string{
876 "testdata/firstparty/FIRST_PARTY_LICENSE",
877 "testdata/notice/NOTICE_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000878 "testdata/notice/bin/bin1.meta_lic",
879 "testdata/notice/lib/liba.so.meta_lic",
880 "testdata/notice/lib/libc.a.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000881 },
882 },
883 {
884 condition: "notice",
885 name: "library",
886 roots: []string{"lib/libd.so.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000887 expectedOut: &spdx.Document{
888 SPDXIdentifier: "DOCUMENT",
889 CreationInfo: getCreationInfo(t),
890 Packages: []*spdx.Package{
891 {
892 PackageName: "testdata-notice-lib-libd.so.meta_lic",
893 PackageVersion: "NOASSERTION",
894 PackageDownloadLocation: "NOASSERTION",
895 PackageSPDXIdentifier: common.ElementID("testdata-notice-lib-libd.so.meta_lic"),
896 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
897 },
898 },
899 Relationships: []*spdx.Relationship{
900 {
901 RefA: common.MakeDocElementID("", "DOCUMENT"),
902 RefB: common.MakeDocElementID("", "testdata-notice-lib-libd.so.meta_lic"),
903 Relationship: "DESCRIBES",
904 },
905 },
906 OtherLicenses: []*spdx.OtherLicense{
907 {
908 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
909 ExtractedText: "%%%Notice License%%%\n",
910 LicenseName: "testdata-notice-NOTICE_LICENSE",
911 },
912 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000913 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +0000914 expectedDeps: []string{
915 "testdata/notice/NOTICE_LICENSE",
916 "testdata/notice/lib/libd.so.meta_lic",
917 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +0000918 },
919 {
920 condition: "reciprocal",
921 name: "apex",
922 roots: []string{"highest.apex.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +0000923 expectedOut: &spdx.Document{
924 SPDXIdentifier: "DOCUMENT",
925 CreationInfo: getCreationInfo(t),
926 Packages: []*spdx.Package{
927 {
928 PackageName: "testdata-reciprocal-highest.apex.meta_lic",
929 PackageVersion: "NOASSERTION",
930 PackageDownloadLocation: "NOASSERTION",
931 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-highest.apex.meta_lic"),
932 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
933 },
934 {
935 PackageName: "testdata-reciprocal-bin-bin1.meta_lic",
936 PackageVersion: "NOASSERTION",
937 PackageDownloadLocation: "NOASSERTION",
938 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-bin-bin1.meta_lic"),
939 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
940 },
941 {
942 PackageName: "testdata-reciprocal-bin-bin2.meta_lic",
943 PackageVersion: "NOASSERTION",
944 PackageDownloadLocation: "NOASSERTION",
945 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-bin-bin2.meta_lic"),
946 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
947 },
948 {
949 PackageName: "testdata-reciprocal-lib-liba.so.meta_lic",
950 PackageVersion: "NOASSERTION",
951 PackageDownloadLocation: "NOASSERTION",
952 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-liba.so.meta_lic"),
953 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
954 },
955 {
956 PackageName: "testdata-reciprocal-lib-libb.so.meta_lic",
957 PackageVersion: "NOASSERTION",
958 PackageDownloadLocation: "NOASSERTION",
959 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-libb.so.meta_lic"),
960 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
961 },
962 {
963 PackageName: "testdata-reciprocal-lib-libc.a.meta_lic",
964 PackageVersion: "NOASSERTION",
965 PackageDownloadLocation: "NOASSERTION",
966 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-libc.a.meta_lic"),
967 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
968 },
969 {
970 PackageName: "testdata-reciprocal-lib-libd.so.meta_lic",
971 PackageVersion: "NOASSERTION",
972 PackageDownloadLocation: "NOASSERTION",
973 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-libd.so.meta_lic"),
974 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
975 },
976 },
977 Relationships: []*spdx.Relationship{
978 {
979 RefA: common.MakeDocElementID("", "DOCUMENT"),
980 RefB: common.MakeDocElementID("", "testdata-reciprocal-highest.apex.meta_lic"),
981 Relationship: "DESCRIBES",
982 },
983 {
984 RefA: common.MakeDocElementID("", "testdata-reciprocal-highest.apex.meta_lic"),
985 RefB: common.MakeDocElementID("", "testdata-reciprocal-bin-bin1.meta_lic"),
986 Relationship: "CONTAINS",
987 },
988 {
989 RefA: common.MakeDocElementID("", "testdata-reciprocal-highest.apex.meta_lic"),
990 RefB: common.MakeDocElementID("", "testdata-reciprocal-bin-bin2.meta_lic"),
991 Relationship: "CONTAINS",
992 },
993 {
994 RefA: common.MakeDocElementID("", "testdata-reciprocal-highest.apex.meta_lic"),
995 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-liba.so.meta_lic"),
996 Relationship: "CONTAINS",
997 },
998 {
999 RefA: common.MakeDocElementID("", "testdata-reciprocal-highest.apex.meta_lic"),
1000 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-libb.so.meta_lic"),
1001 Relationship: "CONTAINS",
1002 },
1003 {
1004 RefA: common.MakeDocElementID("", "testdata-reciprocal-bin-bin1.meta_lic"),
1005 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-liba.so.meta_lic"),
1006 Relationship: "CONTAINS",
1007 },
1008 {
1009 RefA: common.MakeDocElementID("", "testdata-reciprocal-bin-bin1.meta_lic"),
1010 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-libc.a.meta_lic"),
1011 Relationship: "CONTAINS",
1012 },
1013 {
1014 RefA: common.MakeDocElementID("", "testdata-reciprocal-lib-libb.so.meta_lic"),
1015 RefB: common.MakeDocElementID("", "testdata-reciprocal-bin-bin2.meta_lic"),
1016 Relationship: "RUNTIME_DEPENDENCY_OF",
1017 },
1018 {
1019 RefA: common.MakeDocElementID("", "testdata-reciprocal-lib-libd.so.meta_lic"),
1020 RefB: common.MakeDocElementID("", "testdata-reciprocal-bin-bin2.meta_lic"),
1021 Relationship: "RUNTIME_DEPENDENCY_OF",
1022 },
1023 },
1024 OtherLicenses: []*spdx.OtherLicense{
1025 {
1026 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1027 ExtractedText: "&&&First Party License&&&\n",
1028 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1029 },
1030 {
1031 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1032 ExtractedText: "%%%Notice License%%%\n",
1033 LicenseName: "testdata-notice-NOTICE_LICENSE",
1034 },
1035 {
1036 LicenseIdentifier: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1037 ExtractedText: "$$$Reciprocal License$$$\n",
1038 LicenseName: "testdata-reciprocal-RECIPROCAL_LICENSE",
1039 },
1040 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001041 },
1042 expectedDeps: []string{
1043 "testdata/firstparty/FIRST_PARTY_LICENSE",
1044 "testdata/notice/NOTICE_LICENSE",
1045 "testdata/reciprocal/RECIPROCAL_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001046 "testdata/reciprocal/bin/bin1.meta_lic",
1047 "testdata/reciprocal/bin/bin2.meta_lic",
1048 "testdata/reciprocal/highest.apex.meta_lic",
1049 "testdata/reciprocal/lib/liba.so.meta_lic",
1050 "testdata/reciprocal/lib/libb.so.meta_lic",
1051 "testdata/reciprocal/lib/libc.a.meta_lic",
1052 "testdata/reciprocal/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001053 },
1054 },
1055 {
1056 condition: "reciprocal",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001057 name: "application",
1058 roots: []string{"application.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001059 expectedOut: &spdx.Document{
1060 SPDXIdentifier: "DOCUMENT",
1061 CreationInfo: getCreationInfo(t),
1062 Packages: []*spdx.Package{
1063 {
1064 PackageName: "testdata-reciprocal-application.meta_lic",
1065 PackageVersion: "NOASSERTION",
1066 PackageDownloadLocation: "NOASSERTION",
1067 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-application.meta_lic"),
1068 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1069 },
1070 {
1071 PackageName: "testdata-reciprocal-bin-bin3.meta_lic",
1072 PackageVersion: "NOASSERTION",
1073 PackageDownloadLocation: "NOASSERTION",
1074 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-bin-bin3.meta_lic"),
1075 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1076 },
1077 {
1078 PackageName: "testdata-reciprocal-lib-liba.so.meta_lic",
1079 PackageVersion: "NOASSERTION",
1080 PackageDownloadLocation: "NOASSERTION",
1081 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-liba.so.meta_lic"),
1082 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1083 },
1084 {
1085 PackageName: "testdata-reciprocal-lib-libb.so.meta_lic",
1086 PackageVersion: "NOASSERTION",
1087 PackageDownloadLocation: "NOASSERTION",
1088 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-libb.so.meta_lic"),
1089 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1090 },
1091 },
1092 Relationships: []*spdx.Relationship{
1093 {
1094 RefA: common.MakeDocElementID("", "DOCUMENT"),
1095 RefB: common.MakeDocElementID("", "testdata-reciprocal-application.meta_lic"),
1096 Relationship: "DESCRIBES",
1097 },
1098 {
1099 RefA: common.MakeDocElementID("", "testdata-reciprocal-bin-bin3.meta_lic"),
1100 RefB: common.MakeDocElementID("", "testdata-reciprocal-application.meta_lic"),
1101 Relationship: "BUILD_TOOL_OF",
1102 },
1103 {
1104 RefA: common.MakeDocElementID("", "testdata-reciprocal-application.meta_lic"),
1105 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-liba.so.meta_lic"),
1106 Relationship: "CONTAINS",
1107 },
1108 {
1109 RefA: common.MakeDocElementID("", "testdata-reciprocal-lib-libb.so.meta_lic"),
1110 RefB: common.MakeDocElementID("", "testdata-reciprocal-application.meta_lic"),
1111 Relationship: "RUNTIME_DEPENDENCY_OF",
1112 },
1113 },
1114 OtherLicenses: []*spdx.OtherLicense{
1115 {
1116 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1117 ExtractedText: "&&&First Party License&&&\n",
1118 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1119 },
1120 {
1121 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1122 ExtractedText: "%%%Notice License%%%\n",
1123 LicenseName: "testdata-notice-NOTICE_LICENSE",
1124 },
1125 {
1126 LicenseIdentifier: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1127 ExtractedText: "$$$Reciprocal License$$$\n",
1128 LicenseName: "testdata-reciprocal-RECIPROCAL_LICENSE",
1129 },
1130 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001131 },
1132 expectedDeps: []string{
1133 "testdata/firstparty/FIRST_PARTY_LICENSE",
1134 "testdata/notice/NOTICE_LICENSE",
1135 "testdata/reciprocal/RECIPROCAL_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001136 "testdata/reciprocal/application.meta_lic",
1137 "testdata/reciprocal/bin/bin3.meta_lic",
1138 "testdata/reciprocal/lib/liba.so.meta_lic",
1139 "testdata/reciprocal/lib/libb.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001140 },
1141 },
1142 {
1143 condition: "reciprocal",
1144 name: "binary",
1145 roots: []string{"bin/bin1.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001146 expectedOut: &spdx.Document{
1147 SPDXIdentifier: "DOCUMENT",
1148 CreationInfo: getCreationInfo(t),
1149 Packages: []*spdx.Package{
1150 {
1151 PackageName: "testdata-reciprocal-bin-bin1.meta_lic",
1152 PackageVersion: "NOASSERTION",
1153 PackageDownloadLocation: "NOASSERTION",
1154 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-bin-bin1.meta_lic"),
1155 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1156 },
1157 {
1158 PackageName: "testdata-reciprocal-lib-liba.so.meta_lic",
1159 PackageVersion: "NOASSERTION",
1160 PackageDownloadLocation: "NOASSERTION",
1161 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-liba.so.meta_lic"),
1162 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1163 },
1164 {
1165 PackageName: "testdata-reciprocal-lib-libc.a.meta_lic",
1166 PackageVersion: "NOASSERTION",
1167 PackageDownloadLocation: "NOASSERTION",
1168 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-libc.a.meta_lic"),
1169 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1170 },
1171 },
1172 Relationships: []*spdx.Relationship{
1173 {
1174 RefA: common.MakeDocElementID("", "DOCUMENT"),
1175 RefB: common.MakeDocElementID("", "testdata-reciprocal-bin-bin1.meta_lic"),
1176 Relationship: "DESCRIBES",
1177 },
1178 {
1179 RefA: common.MakeDocElementID("", "testdata-reciprocal-bin-bin1.meta_lic"),
1180 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-liba.so.meta_lic"),
1181 Relationship: "CONTAINS",
1182 },
1183 {
1184 RefA: common.MakeDocElementID("", "testdata-reciprocal-bin-bin1.meta_lic"),
1185 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-libc.a.meta_lic"),
1186 Relationship: "CONTAINS",
1187 },
1188 },
1189 OtherLicenses: []*spdx.OtherLicense{
1190 {
1191 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1192 ExtractedText: "&&&First Party License&&&\n",
1193 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1194 },
1195 {
1196 LicenseIdentifier: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1197 ExtractedText: "$$$Reciprocal License$$$\n",
1198 LicenseName: "testdata-reciprocal-RECIPROCAL_LICENSE",
1199 },
1200 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001201 },
1202 expectedDeps: []string{
1203 "testdata/firstparty/FIRST_PARTY_LICENSE",
1204 "testdata/reciprocal/RECIPROCAL_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001205 "testdata/reciprocal/bin/bin1.meta_lic",
1206 "testdata/reciprocal/lib/liba.so.meta_lic",
1207 "testdata/reciprocal/lib/libc.a.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001208 },
1209 },
1210 {
1211 condition: "reciprocal",
1212 name: "library",
1213 roots: []string{"lib/libd.so.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001214 expectedOut: &spdx.Document{
1215 SPDXIdentifier: "DOCUMENT",
1216 CreationInfo: getCreationInfo(t),
1217 Packages: []*spdx.Package{
1218 {
1219 PackageName: "testdata-reciprocal-lib-libd.so.meta_lic",
1220 PackageVersion: "NOASSERTION",
1221 PackageDownloadLocation: "NOASSERTION",
1222 PackageSPDXIdentifier: common.ElementID("testdata-reciprocal-lib-libd.so.meta_lic"),
1223 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1224 },
1225 },
1226 Relationships: []*spdx.Relationship{
1227 {
1228 RefA: common.MakeDocElementID("", "DOCUMENT"),
1229 RefB: common.MakeDocElementID("", "testdata-reciprocal-lib-libd.so.meta_lic"),
1230 Relationship: "DESCRIBES",
1231 },
1232 },
1233 OtherLicenses: []*spdx.OtherLicense{
1234 {
1235 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1236 ExtractedText: "%%%Notice License%%%\n",
1237 LicenseName: "testdata-notice-NOTICE_LICENSE",
1238 },
1239 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001240 },
1241 expectedDeps: []string{
1242 "testdata/notice/NOTICE_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001243 "testdata/reciprocal/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001244 },
1245 },
1246 {
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001247 condition: "restricted",
1248 name: "apex",
1249 roots: []string{"highest.apex.meta_lic"},
1250 expectedOut: &spdx.Document{
1251 SPDXIdentifier: "DOCUMENT",
1252 CreationInfo: getCreationInfo(t),
1253 Packages: []*spdx.Package{
1254 {
1255 PackageName: "testdata-restricted-highest.apex.meta_lic",
1256 PackageVersion: "NOASSERTION",
1257 PackageDownloadLocation: "NOASSERTION",
1258 PackageSPDXIdentifier: common.ElementID("testdata-restricted-highest.apex.meta_lic"),
1259 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1260 },
1261 {
1262 PackageName: "testdata-restricted-bin-bin1.meta_lic",
1263 PackageVersion: "NOASSERTION",
1264 PackageDownloadLocation: "NOASSERTION",
1265 PackageSPDXIdentifier: common.ElementID("testdata-restricted-bin-bin1.meta_lic"),
1266 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1267 },
1268 {
1269 PackageName: "testdata-restricted-bin-bin2.meta_lic",
1270 PackageVersion: "NOASSERTION",
1271 PackageDownloadLocation: "NOASSERTION",
1272 PackageSPDXIdentifier: common.ElementID("testdata-restricted-bin-bin2.meta_lic"),
1273 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1274 },
1275 {
1276 PackageName: "testdata-restricted-lib-liba.so.meta_lic",
1277 PackageVersion: "NOASSERTION",
1278 PackageDownloadLocation: "NOASSERTION",
1279 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-liba.so.meta_lic"),
1280 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1281 },
1282 {
1283 PackageName: "testdata-restricted-lib-libb.so.meta_lic",
1284 PackageVersion: "NOASSERTION",
1285 PackageDownloadLocation: "NOASSERTION",
1286 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libb.so.meta_lic"),
1287 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1288 },
1289 {
1290 PackageName: "testdata-restricted-lib-libc.a.meta_lic",
1291 PackageVersion: "NOASSERTION",
1292 PackageDownloadLocation: "NOASSERTION",
1293 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libc.a.meta_lic"),
1294 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1295 },
1296 {
1297 PackageName: "testdata-restricted-lib-libd.so.meta_lic",
1298 PackageVersion: "NOASSERTION",
1299 PackageDownloadLocation: "NOASSERTION",
1300 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libd.so.meta_lic"),
1301 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1302 },
1303 },
1304 Relationships: []*spdx.Relationship{
1305 {
1306 RefA: common.MakeDocElementID("", "DOCUMENT"),
1307 RefB: common.MakeDocElementID("", "testdata-restricted-highest.apex.meta_lic"),
1308 Relationship: "DESCRIBES",
1309 },
1310 {
1311 RefA: common.MakeDocElementID("", "testdata-restricted-highest.apex.meta_lic"),
1312 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1313 Relationship: "CONTAINS",
1314 },
1315 {
1316 RefA: common.MakeDocElementID("", "testdata-restricted-highest.apex.meta_lic"),
1317 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin2.meta_lic"),
1318 Relationship: "CONTAINS",
1319 },
1320 {
1321 RefA: common.MakeDocElementID("", "testdata-restricted-highest.apex.meta_lic"),
1322 RefB: common.MakeDocElementID("", "testdata-restricted-lib-liba.so.meta_lic"),
1323 Relationship: "CONTAINS",
1324 },
1325 {
1326 RefA: common.MakeDocElementID("", "testdata-restricted-highest.apex.meta_lic"),
1327 RefB: common.MakeDocElementID("", "testdata-restricted-lib-libb.so.meta_lic"),
1328 Relationship: "CONTAINS",
1329 },
1330 {
1331 RefA: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1332 RefB: common.MakeDocElementID("", "testdata-restricted-lib-liba.so.meta_lic"),
1333 Relationship: "CONTAINS",
1334 },
1335 {
1336 RefA: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1337 RefB: common.MakeDocElementID("", "testdata-restricted-lib-libc.a.meta_lic"),
1338 Relationship: "CONTAINS",
1339 },
1340 {
1341 RefA: common.MakeDocElementID("", "testdata-restricted-lib-libb.so.meta_lic"),
1342 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin2.meta_lic"),
1343 Relationship: "RUNTIME_DEPENDENCY_OF",
1344 },
1345 {
1346 RefA: common.MakeDocElementID("", "testdata-restricted-lib-libd.so.meta_lic"),
1347 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin2.meta_lic"),
1348 Relationship: "RUNTIME_DEPENDENCY_OF",
1349 },
1350 },
1351 OtherLicenses: []*spdx.OtherLicense{
1352 {
1353 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1354 ExtractedText: "&&&First Party License&&&\n",
1355 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1356 },
1357 {
1358 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1359 ExtractedText: "%%%Notice License%%%\n",
1360 LicenseName: "testdata-notice-NOTICE_LICENSE",
1361 },
1362 {
1363 LicenseIdentifier: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1364 ExtractedText: "$$$Reciprocal License$$$\n",
1365 LicenseName: "testdata-reciprocal-RECIPROCAL_LICENSE",
1366 },
1367 {
1368 LicenseIdentifier: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1369 ExtractedText: "###Restricted License###\n",
1370 LicenseName: "testdata-restricted-RESTRICTED_LICENSE",
1371 },
1372 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001373 },
1374 expectedDeps: []string{
1375 "testdata/firstparty/FIRST_PARTY_LICENSE",
1376 "testdata/notice/NOTICE_LICENSE",
1377 "testdata/reciprocal/RECIPROCAL_LICENSE",
1378 "testdata/restricted/RESTRICTED_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001379 "testdata/restricted/bin/bin1.meta_lic",
1380 "testdata/restricted/bin/bin2.meta_lic",
1381 "testdata/restricted/highest.apex.meta_lic",
1382 "testdata/restricted/lib/liba.so.meta_lic",
1383 "testdata/restricted/lib/libb.so.meta_lic",
1384 "testdata/restricted/lib/libc.a.meta_lic",
1385 "testdata/restricted/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001386 },
1387 },
1388 {
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001389 condition: "restricted",
1390 name: "container",
1391 roots: []string{"container.zip.meta_lic"},
1392 expectedOut: &spdx.Document{
1393 SPDXIdentifier: "DOCUMENT",
1394 CreationInfo: getCreationInfo(t),
1395 Packages: []*spdx.Package{
1396 {
1397 PackageName: "testdata-restricted-container.zip.meta_lic",
1398 PackageVersion: "NOASSERTION",
1399 PackageDownloadLocation: "NOASSERTION",
1400 PackageSPDXIdentifier: common.ElementID("testdata-restricted-container.zip.meta_lic"),
1401 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1402 },
1403 {
1404 PackageName: "testdata-restricted-bin-bin1.meta_lic",
1405 PackageVersion: "NOASSERTION",
1406 PackageDownloadLocation: "NOASSERTION",
1407 PackageSPDXIdentifier: common.ElementID("testdata-restricted-bin-bin1.meta_lic"),
1408 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1409 },
1410 {
1411 PackageName: "testdata-restricted-bin-bin2.meta_lic",
1412 PackageVersion: "NOASSERTION",
1413 PackageDownloadLocation: "NOASSERTION",
1414 PackageSPDXIdentifier: common.ElementID("testdata-restricted-bin-bin2.meta_lic"),
1415 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1416 },
1417 {
1418 PackageName: "testdata-restricted-lib-liba.so.meta_lic",
1419 PackageVersion: "NOASSERTION",
1420 PackageDownloadLocation: "NOASSERTION",
1421 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-liba.so.meta_lic"),
1422 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1423 },
1424 {
1425 PackageName: "testdata-restricted-lib-libb.so.meta_lic",
1426 PackageVersion: "NOASSERTION",
1427 PackageDownloadLocation: "NOASSERTION",
1428 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libb.so.meta_lic"),
1429 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1430 },
1431 {
1432 PackageName: "testdata-restricted-lib-libc.a.meta_lic",
1433 PackageVersion: "NOASSERTION",
1434 PackageDownloadLocation: "NOASSERTION",
1435 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libc.a.meta_lic"),
1436 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1437 },
1438 {
1439 PackageName: "testdata-restricted-lib-libd.so.meta_lic",
1440 PackageVersion: "NOASSERTION",
1441 PackageDownloadLocation: "NOASSERTION",
1442 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libd.so.meta_lic"),
1443 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1444 },
1445 },
1446 Relationships: []*spdx.Relationship{
1447 {
1448 RefA: common.MakeDocElementID("", "DOCUMENT"),
1449 RefB: common.MakeDocElementID("", "testdata-restricted-container.zip.meta_lic"),
1450 Relationship: "DESCRIBES",
1451 },
1452 {
1453 RefA: common.MakeDocElementID("", "testdata-restricted-container.zip.meta_lic"),
1454 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1455 Relationship: "CONTAINS",
1456 },
1457 {
1458 RefA: common.MakeDocElementID("", "testdata-restricted-container.zip.meta_lic"),
1459 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin2.meta_lic"),
1460 Relationship: "CONTAINS",
1461 },
1462 {
1463 RefA: common.MakeDocElementID("", "testdata-restricted-container.zip.meta_lic"),
1464 RefB: common.MakeDocElementID("", "testdata-restricted-lib-liba.so.meta_lic"),
1465 Relationship: "CONTAINS",
1466 },
1467 {
1468 RefA: common.MakeDocElementID("", "testdata-restricted-container.zip.meta_lic"),
1469 RefB: common.MakeDocElementID("", "testdata-restricted-lib-libb.so.meta_lic"),
1470 Relationship: "CONTAINS",
1471 },
1472 {
1473 RefA: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1474 RefB: common.MakeDocElementID("", "testdata-restricted-lib-liba.so.meta_lic"),
1475 Relationship: "CONTAINS",
1476 },
1477 {
1478 RefA: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1479 RefB: common.MakeDocElementID("", "testdata-restricted-lib-libc.a.meta_lic"),
1480 Relationship: "CONTAINS",
1481 },
1482 {
1483 RefA: common.MakeDocElementID("", "testdata-restricted-lib-libb.so.meta_lic"),
1484 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin2.meta_lic"),
1485 Relationship: "RUNTIME_DEPENDENCY_OF",
1486 },
1487 {
1488 RefA: common.MakeDocElementID("", "testdata-restricted-lib-libd.so.meta_lic"),
1489 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin2.meta_lic"),
1490 Relationship: "RUNTIME_DEPENDENCY_OF",
1491 },
1492 },
1493 OtherLicenses: []*spdx.OtherLicense{
1494 {
1495 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1496 ExtractedText: "&&&First Party License&&&\n",
1497 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1498 },
1499 {
1500 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1501 ExtractedText: "%%%Notice License%%%\n",
1502 LicenseName: "testdata-notice-NOTICE_LICENSE",
1503 },
1504 {
1505 LicenseIdentifier: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1506 ExtractedText: "$$$Reciprocal License$$$\n",
1507 LicenseName: "testdata-reciprocal-RECIPROCAL_LICENSE",
1508 },
1509 {
1510 LicenseIdentifier: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1511 ExtractedText: "###Restricted License###\n",
1512 LicenseName: "testdata-restricted-RESTRICTED_LICENSE",
1513 },
1514 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001515 },
1516 expectedDeps: []string{
1517 "testdata/firstparty/FIRST_PARTY_LICENSE",
1518 "testdata/notice/NOTICE_LICENSE",
1519 "testdata/reciprocal/RECIPROCAL_LICENSE",
1520 "testdata/restricted/RESTRICTED_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001521 "testdata/restricted/bin/bin1.meta_lic",
1522 "testdata/restricted/bin/bin2.meta_lic",
1523 "testdata/restricted/container.zip.meta_lic",
1524 "testdata/restricted/lib/liba.so.meta_lic",
1525 "testdata/restricted/lib/libb.so.meta_lic",
1526 "testdata/restricted/lib/libc.a.meta_lic",
1527 "testdata/restricted/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001528 },
1529 },
1530 {
1531 condition: "restricted",
1532 name: "binary",
1533 roots: []string{"bin/bin1.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001534 expectedOut: &spdx.Document{
1535 SPDXIdentifier: "DOCUMENT",
1536 CreationInfo: getCreationInfo(t),
1537 Packages: []*spdx.Package{
1538 {
1539 PackageName: "testdata-restricted-bin-bin1.meta_lic",
1540 PackageVersion: "NOASSERTION",
1541 PackageDownloadLocation: "NOASSERTION",
1542 PackageSPDXIdentifier: common.ElementID("testdata-restricted-bin-bin1.meta_lic"),
1543 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1544 },
1545 {
1546 PackageName: "testdata-restricted-lib-liba.so.meta_lic",
1547 PackageVersion: "NOASSERTION",
1548 PackageDownloadLocation: "NOASSERTION",
1549 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-liba.so.meta_lic"),
1550 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1551 },
1552 {
1553 PackageName: "testdata-restricted-lib-libc.a.meta_lic",
1554 PackageVersion: "NOASSERTION",
1555 PackageDownloadLocation: "NOASSERTION",
1556 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libc.a.meta_lic"),
1557 PackageLicenseConcluded: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1558 },
1559 },
1560 Relationships: []*spdx.Relationship{
1561 {
1562 RefA: common.MakeDocElementID("", "DOCUMENT"),
1563 RefB: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1564 Relationship: "DESCRIBES",
1565 },
1566 {
1567 RefA: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1568 RefB: common.MakeDocElementID("", "testdata-restricted-lib-liba.so.meta_lic"),
1569 Relationship: "CONTAINS",
1570 },
1571 {
1572 RefA: common.MakeDocElementID("", "testdata-restricted-bin-bin1.meta_lic"),
1573 RefB: common.MakeDocElementID("", "testdata-restricted-lib-libc.a.meta_lic"),
1574 Relationship: "CONTAINS",
1575 },
1576 },
1577 OtherLicenses: []*spdx.OtherLicense{
1578 {
1579 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1580 ExtractedText: "&&&First Party License&&&\n",
1581 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1582 },
1583 {
1584 LicenseIdentifier: "LicenseRef-testdata-reciprocal-RECIPROCAL_LICENSE",
1585 ExtractedText: "$$$Reciprocal License$$$\n",
1586 LicenseName: "testdata-reciprocal-RECIPROCAL_LICENSE",
1587 },
1588 {
1589 LicenseIdentifier: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1590 ExtractedText: "###Restricted License###\n",
1591 LicenseName: "testdata-restricted-RESTRICTED_LICENSE",
1592 },
1593 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001594 },
1595 expectedDeps: []string{
1596 "testdata/firstparty/FIRST_PARTY_LICENSE",
1597 "testdata/reciprocal/RECIPROCAL_LICENSE",
1598 "testdata/restricted/RESTRICTED_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001599 "testdata/restricted/bin/bin1.meta_lic",
1600 "testdata/restricted/lib/liba.so.meta_lic",
1601 "testdata/restricted/lib/libc.a.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001602 },
1603 },
1604 {
1605 condition: "restricted",
1606 name: "library",
1607 roots: []string{"lib/libd.so.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001608 expectedOut: &spdx.Document{
1609 SPDXIdentifier: "DOCUMENT",
1610 CreationInfo: getCreationInfo(t),
1611 Packages: []*spdx.Package{
1612 {
1613 PackageName: "testdata-restricted-lib-libd.so.meta_lic",
1614 PackageVersion: "NOASSERTION",
1615 PackageDownloadLocation: "NOASSERTION",
1616 PackageSPDXIdentifier: common.ElementID("testdata-restricted-lib-libd.so.meta_lic"),
1617 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1618 },
1619 },
1620 Relationships: []*spdx.Relationship{
1621 {
1622 RefA: common.MakeDocElementID("", "DOCUMENT"),
1623 RefB: common.MakeDocElementID("", "testdata-restricted-lib-libd.so.meta_lic"),
1624 Relationship: "DESCRIBES",
1625 },
1626 },
1627 OtherLicenses: []*spdx.OtherLicense{
1628 {
1629 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1630 ExtractedText: "%%%Notice License%%%\n",
1631 LicenseName: "testdata-notice-NOTICE_LICENSE",
1632 },
1633 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001634 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001635 expectedDeps: []string{
1636 "testdata/notice/NOTICE_LICENSE",
1637 "testdata/restricted/lib/libd.so.meta_lic",
1638 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001639 },
1640 {
1641 condition: "proprietary",
1642 name: "apex",
1643 roots: []string{"highest.apex.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001644 expectedOut: &spdx.Document{
1645 SPDXIdentifier: "DOCUMENT",
1646 CreationInfo: getCreationInfo(t),
1647 Packages: []*spdx.Package{
1648 {
1649 PackageName: "testdata-proprietary-highest.apex.meta_lic",
1650 PackageVersion: "NOASSERTION",
1651 PackageDownloadLocation: "NOASSERTION",
1652 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-highest.apex.meta_lic"),
1653 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1654 },
1655 {
1656 PackageName: "testdata-proprietary-bin-bin1.meta_lic",
1657 PackageVersion: "NOASSERTION",
1658 PackageDownloadLocation: "NOASSERTION",
1659 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-bin-bin1.meta_lic"),
1660 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1661 },
1662 {
1663 PackageName: "testdata-proprietary-bin-bin2.meta_lic",
1664 PackageVersion: "NOASSERTION",
1665 PackageDownloadLocation: "NOASSERTION",
1666 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-bin-bin2.meta_lic"),
1667 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1668 },
1669 {
1670 PackageName: "testdata-proprietary-lib-liba.so.meta_lic",
1671 PackageVersion: "NOASSERTION",
1672 PackageDownloadLocation: "NOASSERTION",
1673 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-liba.so.meta_lic"),
1674 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1675 },
1676 {
1677 PackageName: "testdata-proprietary-lib-libb.so.meta_lic",
1678 PackageVersion: "NOASSERTION",
1679 PackageDownloadLocation: "NOASSERTION",
1680 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libb.so.meta_lic"),
1681 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1682 },
1683 {
1684 PackageName: "testdata-proprietary-lib-libc.a.meta_lic",
1685 PackageVersion: "NOASSERTION",
1686 PackageDownloadLocation: "NOASSERTION",
1687 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libc.a.meta_lic"),
1688 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1689 },
1690 {
1691 PackageName: "testdata-proprietary-lib-libd.so.meta_lic",
1692 PackageVersion: "NOASSERTION",
1693 PackageDownloadLocation: "NOASSERTION",
1694 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libd.so.meta_lic"),
1695 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1696 },
1697 },
1698 Relationships: []*spdx.Relationship{
1699 {
1700 RefA: common.MakeDocElementID("", "DOCUMENT"),
1701 RefB: common.MakeDocElementID("", "testdata-proprietary-highest.apex.meta_lic"),
1702 Relationship: "DESCRIBES",
1703 },
1704 {
1705 RefA: common.MakeDocElementID("", "testdata-proprietary-highest.apex.meta_lic"),
1706 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
1707 Relationship: "CONTAINS",
1708 },
1709 {
1710 RefA: common.MakeDocElementID("", "testdata-proprietary-highest.apex.meta_lic"),
1711 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin2.meta_lic"),
1712 Relationship: "CONTAINS",
1713 },
1714 {
1715 RefA: common.MakeDocElementID("", "testdata-proprietary-highest.apex.meta_lic"),
1716 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-liba.so.meta_lic"),
1717 Relationship: "CONTAINS",
1718 },
1719 {
1720 RefA: common.MakeDocElementID("", "testdata-proprietary-highest.apex.meta_lic"),
1721 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-libb.so.meta_lic"),
1722 Relationship: "CONTAINS",
1723 },
1724 {
1725 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
1726 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-liba.so.meta_lic"),
1727 Relationship: "CONTAINS",
1728 },
1729 {
1730 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
1731 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-libc.a.meta_lic"),
1732 Relationship: "CONTAINS",
1733 },
1734 {
1735 RefA: common.MakeDocElementID("", "testdata-proprietary-lib-libb.so.meta_lic"),
1736 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin2.meta_lic"),
1737 Relationship: "RUNTIME_DEPENDENCY_OF",
1738 },
1739 {
1740 RefA: common.MakeDocElementID("", "testdata-proprietary-lib-libd.so.meta_lic"),
1741 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin2.meta_lic"),
1742 Relationship: "RUNTIME_DEPENDENCY_OF",
1743 },
1744 },
1745 OtherLicenses: []*spdx.OtherLicense{
1746 {
1747 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1748 ExtractedText: "&&&First Party License&&&\n",
1749 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1750 },
1751 {
1752 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1753 ExtractedText: "%%%Notice License%%%\n",
1754 LicenseName: "testdata-notice-NOTICE_LICENSE",
1755 },
1756 {
1757 LicenseIdentifier: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1758 ExtractedText: "@@@Proprietary License@@@\n",
1759 LicenseName: "testdata-proprietary-PROPRIETARY_LICENSE",
1760 },
1761 {
1762 LicenseIdentifier: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1763 ExtractedText: "###Restricted License###\n",
1764 LicenseName: "testdata-restricted-RESTRICTED_LICENSE",
1765 },
1766 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001767 },
1768 expectedDeps: []string{
1769 "testdata/firstparty/FIRST_PARTY_LICENSE",
1770 "testdata/notice/NOTICE_LICENSE",
1771 "testdata/proprietary/PROPRIETARY_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001772 "testdata/proprietary/bin/bin1.meta_lic",
1773 "testdata/proprietary/bin/bin2.meta_lic",
1774 "testdata/proprietary/highest.apex.meta_lic",
1775 "testdata/proprietary/lib/liba.so.meta_lic",
1776 "testdata/proprietary/lib/libb.so.meta_lic",
1777 "testdata/proprietary/lib/libc.a.meta_lic",
1778 "testdata/proprietary/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001779 "testdata/restricted/RESTRICTED_LICENSE",
1780 },
1781 },
1782 {
1783 condition: "proprietary",
1784 name: "container",
1785 roots: []string{"container.zip.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001786 expectedOut: &spdx.Document{
1787 SPDXIdentifier: "DOCUMENT",
1788 CreationInfo: getCreationInfo(t),
1789 Packages: []*spdx.Package{
1790 {
1791 PackageName: "testdata-proprietary-container.zip.meta_lic",
1792 PackageVersion: "NOASSERTION",
1793 PackageDownloadLocation: "NOASSERTION",
1794 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-container.zip.meta_lic"),
1795 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1796 },
1797 {
1798 PackageName: "testdata-proprietary-bin-bin1.meta_lic",
1799 PackageVersion: "NOASSERTION",
1800 PackageDownloadLocation: "NOASSERTION",
1801 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-bin-bin1.meta_lic"),
1802 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1803 },
1804 {
1805 PackageName: "testdata-proprietary-bin-bin2.meta_lic",
1806 PackageVersion: "NOASSERTION",
1807 PackageDownloadLocation: "NOASSERTION",
1808 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-bin-bin2.meta_lic"),
1809 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1810 },
1811 {
1812 PackageName: "testdata-proprietary-lib-liba.so.meta_lic",
1813 PackageVersion: "NOASSERTION",
1814 PackageDownloadLocation: "NOASSERTION",
1815 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-liba.so.meta_lic"),
1816 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1817 },
1818 {
1819 PackageName: "testdata-proprietary-lib-libb.so.meta_lic",
1820 PackageVersion: "NOASSERTION",
1821 PackageDownloadLocation: "NOASSERTION",
1822 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libb.so.meta_lic"),
1823 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1824 },
1825 {
1826 PackageName: "testdata-proprietary-lib-libc.a.meta_lic",
1827 PackageVersion: "NOASSERTION",
1828 PackageDownloadLocation: "NOASSERTION",
1829 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libc.a.meta_lic"),
1830 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1831 },
1832 {
1833 PackageName: "testdata-proprietary-lib-libd.so.meta_lic",
1834 PackageVersion: "NOASSERTION",
1835 PackageDownloadLocation: "NOASSERTION",
1836 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libd.so.meta_lic"),
1837 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1838 },
1839 },
1840 Relationships: []*spdx.Relationship{
1841 {
1842 RefA: common.MakeDocElementID("", "DOCUMENT"),
1843 RefB: common.MakeDocElementID("", "testdata-proprietary-container.zip.meta_lic"),
1844 Relationship: "DESCRIBES",
1845 },
1846 {
1847 RefA: common.MakeDocElementID("", "testdata-proprietary-container.zip.meta_lic"),
1848 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
1849 Relationship: "CONTAINS",
1850 },
1851 {
1852 RefA: common.MakeDocElementID("", "testdata-proprietary-container.zip.meta_lic"),
1853 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin2.meta_lic"),
1854 Relationship: "CONTAINS",
1855 },
1856 {
1857 RefA: common.MakeDocElementID("", "testdata-proprietary-container.zip.meta_lic"),
1858 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-liba.so.meta_lic"),
1859 Relationship: "CONTAINS",
1860 },
1861 {
1862 RefA: common.MakeDocElementID("", "testdata-proprietary-container.zip.meta_lic"),
1863 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-libb.so.meta_lic"),
1864 Relationship: "CONTAINS",
1865 },
1866 {
1867 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
1868 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-liba.so.meta_lic"),
1869 Relationship: "CONTAINS",
1870 },
1871 {
1872 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
1873 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-libc.a.meta_lic"),
1874 Relationship: "CONTAINS",
1875 },
1876 {
1877 RefA: common.MakeDocElementID("", "testdata-proprietary-lib-libb.so.meta_lic"),
1878 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin2.meta_lic"),
1879 Relationship: "RUNTIME_DEPENDENCY_OF",
1880 },
1881 {
1882 RefA: common.MakeDocElementID("", "testdata-proprietary-lib-libd.so.meta_lic"),
1883 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin2.meta_lic"),
1884 Relationship: "RUNTIME_DEPENDENCY_OF",
1885 },
1886 },
1887 OtherLicenses: []*spdx.OtherLicense{
1888 {
1889 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1890 ExtractedText: "&&&First Party License&&&\n",
1891 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1892 },
1893 {
1894 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
1895 ExtractedText: "%%%Notice License%%%\n",
1896 LicenseName: "testdata-notice-NOTICE_LICENSE",
1897 },
1898 {
1899 LicenseIdentifier: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1900 ExtractedText: "@@@Proprietary License@@@\n",
1901 LicenseName: "testdata-proprietary-PROPRIETARY_LICENSE",
1902 },
1903 {
1904 LicenseIdentifier: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1905 ExtractedText: "###Restricted License###\n",
1906 LicenseName: "testdata-restricted-RESTRICTED_LICENSE",
1907 },
1908 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001909 },
1910 expectedDeps: []string{
1911 "testdata/firstparty/FIRST_PARTY_LICENSE",
1912 "testdata/notice/NOTICE_LICENSE",
1913 "testdata/proprietary/PROPRIETARY_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00001914 "testdata/proprietary/bin/bin1.meta_lic",
1915 "testdata/proprietary/bin/bin2.meta_lic",
1916 "testdata/proprietary/container.zip.meta_lic",
1917 "testdata/proprietary/lib/liba.so.meta_lic",
1918 "testdata/proprietary/lib/libb.so.meta_lic",
1919 "testdata/proprietary/lib/libc.a.meta_lic",
1920 "testdata/proprietary/lib/libd.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00001921 "testdata/restricted/RESTRICTED_LICENSE",
1922 },
1923 },
1924 {
1925 condition: "proprietary",
1926 name: "application",
1927 roots: []string{"application.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00001928 expectedOut: &spdx.Document{
1929 SPDXIdentifier: "DOCUMENT",
1930 CreationInfo: getCreationInfo(t),
1931 Packages: []*spdx.Package{
1932 {
1933 PackageName: "testdata-proprietary-application.meta_lic",
1934 PackageVersion: "NOASSERTION",
1935 PackageDownloadLocation: "NOASSERTION",
1936 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-application.meta_lic"),
1937 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1938 },
1939 {
1940 PackageName: "testdata-proprietary-bin-bin3.meta_lic",
1941 PackageVersion: "NOASSERTION",
1942 PackageDownloadLocation: "NOASSERTION",
1943 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-bin-bin3.meta_lic"),
1944 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1945 },
1946 {
1947 PackageName: "testdata-proprietary-lib-liba.so.meta_lic",
1948 PackageVersion: "NOASSERTION",
1949 PackageDownloadLocation: "NOASSERTION",
1950 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-liba.so.meta_lic"),
1951 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1952 },
1953 {
1954 PackageName: "testdata-proprietary-lib-libb.so.meta_lic",
1955 PackageVersion: "NOASSERTION",
1956 PackageDownloadLocation: "NOASSERTION",
1957 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libb.so.meta_lic"),
1958 PackageLicenseConcluded: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1959 },
1960 },
1961 Relationships: []*spdx.Relationship{
1962 {
1963 RefA: common.MakeDocElementID("", "DOCUMENT"),
1964 RefB: common.MakeDocElementID("", "testdata-proprietary-application.meta_lic"),
1965 Relationship: "DESCRIBES",
1966 },
1967 {
1968 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin3.meta_lic"),
1969 RefB: common.MakeDocElementID("", "testdata-proprietary-application.meta_lic"),
1970 Relationship: "BUILD_TOOL_OF",
1971 },
1972 {
1973 RefA: common.MakeDocElementID("", "testdata-proprietary-application.meta_lic"),
1974 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-liba.so.meta_lic"),
1975 Relationship: "CONTAINS",
1976 },
1977 {
1978 RefA: common.MakeDocElementID("", "testdata-proprietary-lib-libb.so.meta_lic"),
1979 RefB: common.MakeDocElementID("", "testdata-proprietary-application.meta_lic"),
1980 Relationship: "RUNTIME_DEPENDENCY_OF",
1981 },
1982 },
1983 OtherLicenses: []*spdx.OtherLicense{
1984 {
1985 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
1986 ExtractedText: "&&&First Party License&&&\n",
1987 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
1988 },
1989 {
1990 LicenseIdentifier: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
1991 ExtractedText: "@@@Proprietary License@@@\n",
1992 LicenseName: "testdata-proprietary-PROPRIETARY_LICENSE",
1993 },
1994 {
1995 LicenseIdentifier: "LicenseRef-testdata-restricted-RESTRICTED_LICENSE",
1996 ExtractedText: "###Restricted License###\n",
1997 LicenseName: "testdata-restricted-RESTRICTED_LICENSE",
1998 },
1999 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002000 },
2001 expectedDeps: []string{
2002 "testdata/firstparty/FIRST_PARTY_LICENSE",
2003 "testdata/proprietary/PROPRIETARY_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00002004 "testdata/proprietary/application.meta_lic",
2005 "testdata/proprietary/bin/bin3.meta_lic",
2006 "testdata/proprietary/lib/liba.so.meta_lic",
2007 "testdata/proprietary/lib/libb.so.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002008 "testdata/restricted/RESTRICTED_LICENSE",
2009 },
2010 },
2011 {
2012 condition: "proprietary",
2013 name: "binary",
2014 roots: []string{"bin/bin1.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002015 expectedOut: &spdx.Document{
2016 SPDXIdentifier: "DOCUMENT",
2017 CreationInfo: getCreationInfo(t),
2018 Packages: []*spdx.Package{
2019 {
2020 PackageName: "testdata-proprietary-bin-bin1.meta_lic",
2021 PackageVersion: "NOASSERTION",
2022 PackageDownloadLocation: "NOASSERTION",
2023 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-bin-bin1.meta_lic"),
2024 PackageLicenseConcluded: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
2025 },
2026 {
2027 PackageName: "testdata-proprietary-lib-liba.so.meta_lic",
2028 PackageVersion: "NOASSERTION",
2029 PackageDownloadLocation: "NOASSERTION",
2030 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-liba.so.meta_lic"),
2031 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
2032 },
2033 {
2034 PackageName: "testdata-proprietary-lib-libc.a.meta_lic",
2035 PackageVersion: "NOASSERTION",
2036 PackageDownloadLocation: "NOASSERTION",
2037 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libc.a.meta_lic"),
2038 PackageLicenseConcluded: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
2039 },
2040 },
2041 Relationships: []*spdx.Relationship{
2042 {
2043 RefA: common.MakeDocElementID("", "DOCUMENT"),
2044 RefB: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
2045 Relationship: "DESCRIBES",
2046 },
2047 {
2048 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
2049 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-liba.so.meta_lic"),
2050 Relationship: "CONTAINS",
2051 },
2052 {
2053 RefA: common.MakeDocElementID("", "testdata-proprietary-bin-bin1.meta_lic"),
2054 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-libc.a.meta_lic"),
2055 Relationship: "CONTAINS",
2056 },
2057 },
2058 OtherLicenses: []*spdx.OtherLicense{
2059 {
2060 LicenseIdentifier: "LicenseRef-testdata-firstparty-FIRST_PARTY_LICENSE",
2061 ExtractedText: "&&&First Party License&&&\n",
2062 LicenseName: "testdata-firstparty-FIRST_PARTY_LICENSE",
2063 },
2064 {
2065 LicenseIdentifier: "LicenseRef-testdata-proprietary-PROPRIETARY_LICENSE",
2066 ExtractedText: "@@@Proprietary License@@@\n",
2067 LicenseName: "testdata-proprietary-PROPRIETARY_LICENSE",
2068 },
2069 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002070 },
2071 expectedDeps: []string{
2072 "testdata/firstparty/FIRST_PARTY_LICENSE",
2073 "testdata/proprietary/PROPRIETARY_LICENSE",
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00002074 "testdata/proprietary/bin/bin1.meta_lic",
2075 "testdata/proprietary/lib/liba.so.meta_lic",
2076 "testdata/proprietary/lib/libc.a.meta_lic",
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002077 },
2078 },
2079 {
2080 condition: "proprietary",
2081 name: "library",
2082 roots: []string{"lib/libd.so.meta_lic"},
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002083 expectedOut: &spdx.Document{
2084 SPDXIdentifier: "DOCUMENT",
2085 CreationInfo: getCreationInfo(t),
2086 Packages: []*spdx.Package{
2087 {
2088 PackageName: "testdata-proprietary-lib-libd.so.meta_lic",
2089 PackageVersion: "NOASSERTION",
2090 PackageDownloadLocation: "NOASSERTION",
2091 PackageSPDXIdentifier: common.ElementID("testdata-proprietary-lib-libd.so.meta_lic"),
2092 PackageLicenseConcluded: "LicenseRef-testdata-notice-NOTICE_LICENSE",
2093 },
2094 },
2095 Relationships: []*spdx.Relationship{
2096 {
2097 RefA: common.MakeDocElementID("", "DOCUMENT"),
2098 RefB: common.MakeDocElementID("", "testdata-proprietary-lib-libd.so.meta_lic"),
2099 Relationship: "DESCRIBES",
2100 },
2101 },
2102 OtherLicenses: []*spdx.OtherLicense{
2103 {
2104 LicenseIdentifier: "LicenseRef-testdata-notice-NOTICE_LICENSE",
2105 ExtractedText: "%%%Notice License%%%\n",
2106 LicenseName: "testdata-notice-NOTICE_LICENSE",
2107 },
2108 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002109 },
Ibrahim Kanouche649b4d72022-11-12 05:46:12 +00002110 expectedDeps: []string{
2111 "testdata/notice/NOTICE_LICENSE",
2112 "testdata/proprietary/lib/libd.so.meta_lic",
2113 },
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002114 },
2115 }
2116 for _, tt := range tests {
2117 t.Run(tt.condition+" "+tt.name, func(t *testing.T) {
2118 stdout := &bytes.Buffer{}
2119 stderr := &bytes.Buffer{}
2120
2121 rootFiles := make([]string, 0, len(tt.roots))
2122 for _, r := range tt.roots {
2123 rootFiles = append(rootFiles, "testdata/"+tt.condition+"/"+r)
2124 }
2125
2126 ctx := context{stdout, stderr, compliance.GetFS(tt.outDir), "Android", []string{tt.stripPrefix}, fakeTime}
2127
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002128 spdxDoc, deps, err := sbomGenerator(&ctx, rootFiles...)
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002129 if err != nil {
2130 t.Fatalf("sbom: error = %v, stderr = %v", err, stderr)
2131 return
2132 }
2133 if stderr.Len() > 0 {
2134 t.Errorf("sbom: gotStderr = %v, want none", stderr)
2135 }
2136
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002137 gotData, err := json.Marshal(spdxDoc)
2138 if err != nil {
2139 t.Fatalf("sbom: failed to marshal spdx doc: %v", err)
2140 return
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002141 }
2142
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002143 t.Logf("Got SPDX Doc: %s", string(gotData))
2144
2145 expectedData, err := json.Marshal(tt.expectedOut)
2146 if err != nil {
2147 t.Fatalf("sbom: failed to marshal spdx doc: %v", err)
2148 return
2149 }
2150
2151 t.Logf("Want SPDX Doc: %s", string(expectedData))
2152
2153 // compare the spdx Docs
2154 compareSpdxDocs(t, spdxDoc, tt.expectedOut)
2155
2156 // compare deps
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002157 t.Logf("got deps: %q", deps)
2158
2159 t.Logf("want deps: %q", tt.expectedDeps)
2160
2161 if g, w := deps, tt.expectedDeps; !reflect.DeepEqual(g, w) {
2162 t.Errorf("unexpected deps, wanted:\n%s\ngot:\n%s\n",
2163 strings.Join(w, "\n"), strings.Join(g, "\n"))
2164 }
2165 })
2166 }
2167}
2168
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002169func getCreationInfo(t *testing.T) *spdx.CreationInfo {
2170 ci, err := builder2v2.BuildCreationInfoSection2_2("Organization", "Google LLC", nil)
2171 if err != nil {
2172 t.Errorf("Unable to get creation info: %v", err)
2173 return nil
2174 }
2175 return ci
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002176}
2177
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002178// compareSpdxDocs deep-compares two spdx docs by going through the info section, packages, relationships and licenses
2179func compareSpdxDocs(t *testing.T, actual, expected *spdx.Document) {
2180
2181 if actual == nil || expected == nil {
2182 t.Errorf("SBOM: SPDX Doc is nil! Got %v: Expected %v", actual, expected)
2183 }
2184 // compare creation info
2185 compareSpdxCreationInfo(t, actual.CreationInfo, expected.CreationInfo)
2186
2187 // compare packages
2188 if len(actual.Packages) != len(expected.Packages) {
2189 t.Errorf("SBOM: Number of Packages is different! Got %d: Expected %d", len(actual.Packages), len(expected.Packages))
2190 }
2191
2192 for i, pkg := range actual.Packages {
2193 if !compareSpdxPackages(t, i, pkg, expected.Packages[i]) {
2194 break
2195 }
2196 }
2197
2198 // compare licenses
2199 if len(actual.OtherLicenses) != len(expected.OtherLicenses) {
2200 t.Errorf("SBOM: Number of Licenses in actual is different! Got %d: Expected %d", len(actual.OtherLicenses), len(expected.OtherLicenses))
2201 }
2202 for i, license := range actual.OtherLicenses {
2203 if !compareLicenses(t, i, license, expected.OtherLicenses[i]) {
2204 break
2205 }
2206 }
2207
2208 //compare Relationships
2209 if len(actual.Relationships) != len(expected.Relationships) {
2210 t.Errorf("SBOM: Number of Licenses in actual is different! Got %d: Expected %d", len(actual.Relationships), len(expected.Relationships))
2211 }
2212 for i, rl := range actual.Relationships {
2213 if !compareRelationShips(t, i, rl, expected.Relationships[i]) {
2214 break
2215 }
2216 }
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002217}
2218
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002219func compareSpdxCreationInfo(t *testing.T, actual, expected *spdx.CreationInfo) {
2220 if actual == nil || expected == nil {
2221 t.Errorf("SBOM: Creation info is nil! Got %q: Expected %q", actual, expected)
2222 }
2223
2224 if actual.LicenseListVersion != expected.LicenseListVersion {
2225 t.Errorf("SBOM: Creation info license version Error! Got %s: Expected %s", actual.LicenseListVersion, expected.LicenseListVersion)
2226 }
2227
2228 if len(actual.Creators) != len(expected.Creators) {
2229 t.Errorf("SBOM: Creation info creators Error! Got %d: Expected %d", len(actual.Creators), len(expected.Creators))
2230 }
2231
2232 for i, info := range actual.Creators {
2233 if info != expected.Creators[i] {
2234 t.Errorf("SBOM: Creation info creators Error! Got %q: Expected %q", info, expected.Creators[i])
2235 }
2236 }
2237}
2238
2239func compareSpdxPackages(t *testing.T, i int, actual, expected *spdx.Package) bool {
2240 if actual == nil || expected == nil {
2241 t.Errorf("SBOM: Packages are nil at index %d! Got %v: Expected %v", i, actual, expected)
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002242 return false
2243 }
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002244 if actual.PackageName != expected.PackageName {
2245 t.Errorf("SBOM: Package name Error at index %d! Got %s: Expected %s", i, actual.PackageName, expected.PackageName)
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002246 return false
2247 }
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002248
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002249 if actual.PackageVersion != expected.PackageVersion {
2250 t.Errorf("SBOM: Package version Error at index %d! Got %s: Expected %s", i, actual.PackageVersion, expected.PackageVersion)
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002251 return false
2252 }
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002253
2254 if actual.PackageSPDXIdentifier != expected.PackageSPDXIdentifier {
2255 t.Errorf("SBOM: Package identifier Error at index %d! Got %s: Expected %s", i, actual.PackageSPDXIdentifier, expected.PackageSPDXIdentifier)
2256 return false
2257 }
2258
2259 if actual.PackageDownloadLocation != expected.PackageDownloadLocation {
2260 t.Errorf("SBOM: Package download location Error at index %d! Got %s: Expected %s", i, actual.PackageDownloadLocation, expected.PackageDownloadLocation)
2261 return false
2262 }
2263
2264 if actual.PackageLicenseConcluded != expected.PackageLicenseConcluded {
2265 t.Errorf("SBOM: Package license concluded Error at index %d! Got %s: Expected %s", i, actual.PackageLicenseConcluded, expected.PackageLicenseConcluded)
2266 return false
2267 }
2268 return true
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002269}
2270
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002271func compareRelationShips(t *testing.T, i int, actual, expected *spdx.Relationship) bool {
2272 if actual == nil || expected == nil {
2273 t.Errorf("SBOM: Relationships is nil at index %d! Got %v: Expected %v", i, actual, expected)
2274 return false
2275 }
2276
2277 if actual.RefA != expected.RefA {
2278 t.Errorf("SBOM: Relationship RefA Error at index %d! Got %s: Expected %s", i, actual.RefA, expected.RefA)
2279 return false
2280 }
2281
2282 if actual.RefB != expected.RefB {
2283 t.Errorf("SBOM: Relationship RefB Error at index %d! Got %s: Expected %s", i, actual.RefB, expected.RefB)
2284 return false
2285 }
2286
2287 if actual.Relationship != expected.Relationship {
2288 t.Errorf("SBOM: Relationship type Error at index %d! Got %s: Expected %s", i, actual.Relationship, expected.Relationship)
2289 return false
2290 }
2291 return true
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002292}
2293
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002294func compareLicenses(t *testing.T, i int, actual, expected *spdx.OtherLicense) bool {
2295 if actual == nil || expected == nil {
2296 t.Errorf("SBOM: Licenses is nil at index %d! Got %v: Expected %v", i, actual, expected)
2297 return false
2298 }
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002299
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002300 if actual.LicenseName != expected.LicenseName {
2301 t.Errorf("SBOM: License Name Error at index %d! Got %s: Expected %s", i, actual.LicenseName, expected.LicenseName)
2302 return false
2303 }
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002304
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002305 if actual.LicenseIdentifier != expected.LicenseIdentifier {
2306 t.Errorf("SBOM: License Identifier Error at index %d! Got %s: Expected %s", i, actual.LicenseIdentifier, expected.LicenseIdentifier)
2307 return false
2308 }
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002309
Ibrahim Kanouchee97adc52023-03-20 16:42:09 +00002310 if actual.ExtractedText != expected.ExtractedText {
2311 t.Errorf("SBOM: License Extracted Text Error at index %d! Got: %q want: %q", i, actual.ExtractedText, expected.ExtractedText)
2312 return false
2313 }
2314 return true
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002315}
2316
2317func fakeTime() time.Time {
Maciej Żenczykowski458f9022022-11-02 02:05:19 +00002318 return time.UnixMicro(0).UTC()
Ibrahim Kanouchebedf1a82022-10-22 01:28:05 +00002319}