provenant-cli 0.0.29

Rust-based ScanCode-compatible scanner for licenses, package metadata, SBOMs, and provenance data.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
// SPDX-FileCopyrightText: Provenant contributors
// SPDX-License-Identifier: Apache-2.0

use super::*;

#[test]
fn test_academy_copyright() {
    let input = "Academy Copyright 2008 by the VideoLAN team";
    let (c, _h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter().any(|cr| cr.copyright.contains("VideoLAN team")),
        "Should include holder after Academy Copyright, got: {:?}",
        c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
    );
}

#[test]
fn test_define_copyright() {
    let input = "#define COPYRIGHT       \"Copyright (c) 1999-2008 LSI Corporation\"\n#define MODULEAUTHOR    \"LSI Corporation\"";
    let (c, h, a) = detect_copyrights_from_text(input);
    assert!(
        c.iter()
            .any(|cr| cr.copyright == "Copyright (c) 1999-2008 LSI Corporation"),
        "Should detect 'Copyright (c) 1999-2008 LSI Corporation', got: {:?}",
        c
    );
    assert!(
        h.iter().any(|h| h.holder == "LSI Corporation"),
        "Should detect holder, got: {:?}",
        h
    );
    assert!(
        a.iter().any(|a| a.author == "LSI Corporation"),
        "Should detect author from MODULEAUTHOR, got: {:?}",
        a
    );
}

#[test]
fn test_trailing_year_included_in_copyright() {
    let cases = &[
        (
            "Copyright (c) IBM Corporation 2008",
            "Copyright (c) IBM Corporation 2008",
            "IBM Corporation",
        ),
        (
            "Copyright (c) Zeus Technology Limited 1996",
            "Copyright (c) Zeus Technology Limited 1996",
            "Zeus Technology Limited",
        ),
        (
            "Copyright IBM, Corp. 2007",
            "Copyright IBM, Corp. 2007",
            "IBM, Corp.",
        ),
        (
            "Copyright IBM Corp. 2004, 2010",
            "Copyright IBM Corp. 2004, 2010",
            "IBM Corp.",
        ),
    ];
    for (input, expected_cr, expected_h) in cases {
        let (c, h, _a) = detect_copyrights_from_text(input);
        assert!(
            c.iter().any(|cr| cr.copyright == *expected_cr),
            "For '{}': expected CR '{}', got {:?}",
            input,
            expected_cr,
            c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
        );
        assert!(
            h.iter().any(|hh| hh.holder == *expected_h),
            "For '{}': expected holder '{}', got {:?}",
            input,
            expected_h,
            h.iter().map(|hh| &hh.holder).collect::<Vec<_>>()
        );
    }
}

#[test]
fn test_holder_after_year_range_absorbed() {
    let input = "COPYRIGHT (c) 2006 - 2009 DIONYSOS";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter().any(|cr| cr.copyright.contains("DIONYSOS")),
        "Should include 'DIONYSOS' in copyright, got: {:?}",
        c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
    );
    assert!(
        h.iter().any(|hh| hh.holder.contains("DIONYSOS")),
        "Should include 'DIONYSOS' in holder, got: {:?}",
        h.iter().map(|hh| &hh.holder).collect::<Vec<_>>()
    );
}

#[test]
fn test_multi_word_holder_after_year_range() {
    let input = "Copyright (C) 1999-2000 VA Linux Systems";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter().any(|cr| cr.copyright.contains("VA Linux Systems")),
        "Should include full company name, got: {:?}",
        c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
    );
    assert!(
        h.iter().any(|hh| hh.holder.contains("VA Linux Systems")),
        "Should include full company name in holder, got: {:?}",
        h.iter().map(|hh| &hh.holder).collect::<Vec<_>>()
    );
}

#[test]
fn test_by_keyword_holder_captured() {
    let input = "Copyright (c) 1991, 2000, 2001 by Lucent Technologies.";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter()
            .any(|cr| cr.copyright.contains("Lucent Technologies")),
        "Should include holder after 'by', got: {:?}",
        c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
    );
    assert!(
        h.iter().any(|hh| hh.holder.contains("Lucent Technologies")),
        "Should include holder after 'by', got: {:?}",
        h.iter().map(|hh| &hh.holder).collect::<Vec<_>>()
    );
}

#[test]
fn test_holder_company_with_digits_absorbed() {
    let input = "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter().any(|cr| cr.copyright.contains("Group 42, Inc.")),
        "Should include full company name with digits, got: {:?}",
        c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
    );
    assert!(
        h.iter().any(|hh| hh.holder.contains("Group 42, Inc.")),
        "Should include full company name with digits in holder, got: {:?}",
        h.iter().map(|hh| &hh.holder).collect::<Vec<_>>()
    );
}

#[test]
fn test_copyright_dash_email_tail_absorbed() {
    let input = "Copyright (c) 1999, Bob Withers - bwit@pobox.com";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter().any(|cr| cr.copyright.contains("bwit@pobox.com")),
        "Should include dash-email tail in copyright, got: {:?}",
        c.iter().map(|cr| &cr.copyright).collect::<Vec<_>>()
    );
    assert!(
        h.iter().any(|hh| hh.holder == "Bob Withers"),
        "Expected holder 'Bob Withers', got: {:?}",
        h.iter().map(|hh| &hh.holder).collect::<Vec<_>>()
    );
}

#[test]
fn test_w3c_paren_group_debug() {
    let input = "(c) 1998-2008 (W3C) MIT, ERCIM, Keio University";
    let (c, _h, _a) = detect_copyrights_from_text(input);
    assert!(
        c.iter()
            .any(|cr| cr.copyright.contains("MIT, ERCIM, Keio University")),
        "expected W3C copyright with MIT/ERCIM/Keio, got: {c:#?}"
    );
}

#[test]
fn test_detect_copyright_with_dots_single_line() {
    let input = "Copyright . 2008 Foo Name, Inc.";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert_eq!(c.len(), 1, "Should detect one copyright, got: {:?}", c);
    assert_eq!(
        c[0].copyright, "Copyright 2008 Foo Name, Inc.",
        "Should detect full copyright with company name"
    );
    assert_eq!(h.len(), 1, "Should detect one holder, got: {:?}", h);
    assert_eq!(h[0].holder, "Foo Name, Inc.");
}

#[test]
fn test_detect_copyright_with_dots_multiline() {
    let input = "Copyright . 2008 company name, inc.";
    let (c, h, _a) = detect_copyrights_from_text(input);
    assert!(
        !c.is_empty(),
        "Should detect at least one copyright, got: {:?}",
        c
    );
    assert!(
        c.iter().any(|cr| cr.copyright.contains("2008")),
        "Should detect copyright with year 2008, got: {:?}",
        c
    );
    assert!(
        c.iter()
            .any(|cr| cr.copyright.to_lowercase().contains("company name")),
        "Should detect full company name, got: {:?}",
        c
    );
    assert!(
        h.iter()
            .any(|hr| hr.holder.to_lowercase().contains("company name")),
        "Should detect holder with company name, got: {:?}",
        h
    );
}

#[test]
fn test_opensharedmap_inc_holder_detected() {
    let input = "Copyright (C) OpenSharedMap Inc.";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        copyrights
            .iter()
            .any(|c| c.copyright.contains("OpenSharedMap Inc")),
        "Expected OpenSharedMap copyright detection, got: {copyrights:?}"
    );
    assert!(
        holders
            .iter()
            .any(|h| h.holder.contains("OpenSharedMap Inc")),
        "Expected OpenSharedMap holder detection, got: {holders:?}"
    );
}

#[test]
fn test_disclaimer_tail_with_inc_as_does_not_create_holder() {
    let input = "Copyright Owner Inc. AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES";
    let (_copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        holders.is_empty(),
        "Unexpected disclaimer-derived holders: {holders:?}"
    );
}

#[test]
fn test_platformdirs_lowercase_holder_detected() {
    let input = "Copyright (c) 2010-202x The platformdirs developers";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        copyrights.iter().any(|c| c
            .copyright
            .contains("2010-202x The platformdirs developers")),
        "Expected platformdirs copyright, got: {copyrights:?}"
    );
    assert!(
        holders
            .iter()
            .any(|h| h.holder == "The platformdirs developers"),
        "Expected platformdirs holder, got: {holders:?}"
    );
}

#[test]
fn test_square_c_sign_detected() {
    let input = "[C] The Regents of the University of Michigan and Merit Network, Inc. 1992, 1993, 1994, 1995 All Rights Reserved";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        copyrights.iter().any(|c| c
            .copyright
            .contains("Regents of the University of Michigan")),
        "Expected Regents copyright detection, got: {copyrights:?}"
    );
    assert!(
        holders
            .iter()
            .any(|h| h.holder.contains("Regents of the University of Michigan")),
        "Expected Regents holder detection, got: {holders:?}"
    );
}

#[test]
fn test_template_literal_copyright_holder_detected() {
    let input = "copyright: `Copyright 2010–${new Date().getUTCFullYear()} Mike Bostock`";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        copyrights
            .iter()
            .any(|c| c.copyright == "Copyright 2010-${new Date .getUTCFullYear } Mike Bostock"),
        "copyrights: {copyrights:?}"
    );
    assert!(
        holders.iter().any(|h| h.holder == "Mike Bostock"),
        "holders: {holders:?}"
    );
    assert!(
        !copyrights.iter().any(|c| c.copyright == "Copyright 2010-$"),
        "copyrights: {copyrights:?}"
    );
}

#[test]
fn test_tomcat_footer_trademark_line_not_absorbed_into_copyright() {
    let input = "Copyright (c) 1999-2026, The Apache Software Foundation\nApache Tomcat, Tomcat, Apache, the Apache Tomcat logo and the Apache logo\nare either registered trademarks or trademarks of the Apache Software Foundation.";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        copyrights
            .iter()
            .any(|c| c.copyright == "Copyright (c) 1999-2026, The Apache Software Foundation"),
        "copyrights: {copyrights:?}"
    );
    assert!(
        !copyrights.iter().any(|c| c
            .copyright
            .contains("Apache Tomcat, Tomcat, Apache, the Apache Tomcat")),
        "copyrights: {copyrights:?}"
    );
    assert!(
        holders
            .iter()
            .any(|h| h.holder == "The Apache Software Foundation"),
        "holders: {holders:?}"
    );
    assert!(
        !holders.iter().any(|h| h
            .holder
            .contains("Apache Tomcat, Tomcat, Apache, the Apache Tomcat")),
        "holders: {holders:?}"
    );
}

#[test]
fn test_gsoc_spdx_sentence_not_copyright_or_holder() {
    let input = "Software Package Data Exchange (SPDX) is a set of standards for communicating the components, licenses, and copyrights associated with software.";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(copyrights.is_empty(), "copyrights: {copyrights:?}");
    assert!(holders.is_empty(), "holders: {holders:?}");
}

#[test]
fn test_json_description_and_sponsor_not_copyright_or_holder() {
    let input = r#""description": "Software Package Data Exchange (SPDX) is a set of standards for communicating the components, licenses, and copyrights associated with software.", "sponsor": { "@type": "Organization", "name": "FOSSology", "disambiguatingDescription": "Open Source License Compliance by Open Source Software", "url": "http://example.com/logo" }"#;
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(copyrights.is_empty(), "copyrights: {copyrights:?}");
    assert!(holders.is_empty(), "holders: {holders:?}");
}

#[test]
fn test_mit_intro_not_copyright_or_holder() {
    let input = "These files are covered by the following copyright and MIT License, reproduced from the original project:";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        !copyrights
            .iter()
            .any(|c| c.copyright == "copyright and MIT"),
        "copyrights: {copyrights:?}"
    );
    assert!(
        !holders.iter().any(|h| h.holder == "MIT"),
        "holders: {holders:?}"
    );
}

#[test]
fn test_rest_api_description_not_holder_or_copyright() {
    let input = "We provide developers, researchers, and students the ability to access any model using a simple REST API call. The REST API description.";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(copyrights.is_empty(), "copyrights: {copyrights:?}");
    assert!(holders.is_empty(), "holders: {holders:?}");
}

#[test]
fn test_bare_rest_marker_not_copyright() {
    let input = "(c) REST";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(copyrights.is_empty(), "copyrights: {copyrights:?}");
    assert!(holders.is_empty(), "holders: {holders:?}");
}

#[test]
fn test_semicolon_joined_copyright_list_does_not_keep_combined_variant() {
    let input =
        "(C) 2019--2020 Vinnie Falco; (C) 2020 Krystian Stasiowski; (C) 2022 Dmitry Arkhipov";
    let (copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert!(
        !copyrights.iter().any(|c| {
            c
            .copyright
            == "(c) 2019-2020 Vinnie Falco; (c) 2020 Krystian Stasiowski; (c) 2022 Dmitry Arkhipov"
        }),
        "copyrights: {copyrights:?}"
    );
    assert!(
        copyrights
            .iter()
            .any(|c| c.copyright == "(c) 2019-2020 Vinnie Falco"),
        "copyrights: {copyrights:?}"
    );
    assert!(
        copyrights
            .iter()
            .any(|c| c.copyright == "(c) 2020 Krystian Stasiowski"),
        "copyrights: {copyrights:?}"
    );
    assert!(
        copyrights
            .iter()
            .any(|c| c.copyright == "(c) 2022 Dmitry Arkhipov"),
        "copyrights: {copyrights:?}"
    );
    assert!(
        holders.iter().any(|h| h.holder == "Vinnie Falco")
            && holders.iter().any(|h| h.holder == "Krystian Stasiowski")
            && holders.iter().any(|h| h.holder == "Dmitry Arkhipov"),
        "holders: {holders:?}"
    );
}

#[test]
fn test_normalize_company_suffix_period_holder_variants() {
    let input = "Copyright (c) 2020 Foo, Inc\nCopyright (c) 2021 Foo, Inc.";
    let (_copyrights, holders, _authors) = detect_copyrights_from_text(input);

    assert_eq!(holders.len(), 2, "holders: {holders:?}");
    assert!(
        holders.iter().all(|h| h.holder == "Foo, Inc."),
        "holders: {holders:?}"
    );
}