-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
PoetryAnalyzerTest.java
75 lines (66 loc) · 2.51 KB
/
PoetryAnalyzerTest.java
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
/*
* This file is part of dependency-check-core.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright (c) 2019 Nima Yahyazadeh. All Rights Reserved.
*/
package org.owasp.dependencycheck.analyzer;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.File;
import org.junit.Before;
import org.junit.Test;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.Engine;
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
import org.owasp.dependencycheck.dependency.Dependency;
public class PoetryAnalyzerTest extends BaseTest {
private PoetryAnalyzer analyzer;
private Engine engine;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
analyzer = new PoetryAnalyzer();
engine = new Engine(this.getSettings());
}
@Test
public void testName() {
assertEquals("Analyzer name wrong.", "Poetry Analyzer",
analyzer.getName());
}
@Test
public void testSupportsFiles() {
assertThat(analyzer.accept(new File("poetry.lock")), is(true));
}
@Test
public void testPoetryLock() throws AnalysisException {
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, "poetry.lock"));
analyzer.analyze(result, engine);
assertEquals(88, engine.getDependencies().length);
boolean found = false;
for (Dependency d : engine.getDependencies()) {
if ("urllib3".equals(d.getName())) {
found = true;
assertEquals("1.26.12", d.getVersion());
assertThat(d.getDisplayFileName(), equalTo("urllib3:1.26.12"));
assertEquals(PythonDistributionAnalyzer.DEPENDENCY_ECOSYSTEM, d.getEcosystem());
}
}
assertTrue("Expeced to find PyYAML", found);
}
}