-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathCondaLockComponentDetectorTests.cs
More file actions
150 lines (135 loc) · 5.78 KB
/
Copy pathCondaLockComponentDetectorTests.cs
File metadata and controls
150 lines (135 loc) · 5.78 KB
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
#nullable disable
namespace Microsoft.ComponentDetection.Detectors.Tests;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AwesomeAssertions;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Contracts.TypedComponent;
using Microsoft.ComponentDetection.Detectors.Poetry;
using Microsoft.ComponentDetection.TestsUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
[TestCategory("Governance/All")]
[TestCategory("Governance/ComponentDetection")]
public class CondaLockComponentDetectorTests
{
private readonly DetectorTestUtilityBuilder<CondaLockComponentDetector> detectorTestUtility = new();
[TestMethod]
public async Task CondaComponentDetector_TestCondaLockFileAsync()
{
// A reduced version of the full conda lock file is used for this test
var condaLockContent =
@"version: 1
metadata:
content_hash:
osx-64: 1448e343b4d8a617cda801da72ad04b5aa5d3bf7d8ad17ad1d86ab3788216bd2
linux-64: 0fc90bb13c2014c59b9d5dfb6d82f86db309d511aae307c0868310f170841c96
win-64: c88dea8cfbca2f9ce0cae14272db0bbed3788d286f04153a898f49743a7311f7
channels:
- url: defaults
used_env_vars: []
platforms:
- osx-64
- linux-64
- win-64
sources:
- environment.yml
package:
- name: requests
version: 2.31.0
manager: pip
platform: linux-64
dependencies:
certifi: '>=2017.4.17'
url: https://files.pythonhosted.org/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl
hash:
sha256: 58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f
category: main
optional: false
- name: certifi
version: 2023.5.7
manager: pip
platform: linux-64
dependencies: {}
url: https://files.pythonhosted.org/packages/9d/19/59961b522e6757f0c9097e4493fa906031b95b3ebe9360b2c3083561a6b4/certifi-2023.5.7-py3-none-any.whl
hash:
sha256: c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716
category: main
optional: false
- name: conda-lock
version: 2.1.0
manager: conda
platform: linux-64
dependencies:
urllib3: '>=1.26.5,<2.0'
url: https://conda.anaconda.org/conda-forge/noarch/conda-lock-2.1.0-pyhd8ed1ab_0.conda
hash:
md5: 1e07afcf3d3e371fc3a3681fe9b78e90
sha256: 05319e84cbd36f6a05563954d2dbff041de6ece406a59650784918026080c98c
category: main
optional: false
- name: urllib3
version: 1.26.16
manager: conda
platform: linux-64
dependencies: {}
url: https://repo.anaconda.com/pkgs/main/linux-64/urllib3-1.26.16-py311h06a4308_0.conda
hash:
md5: 4b62a74f7e797800039971833968e23f
sha256: b9e919a9bcb4cb291fe60952895bf0c3ce9dbcbeaa3d5706131f862756fabc40
category: main
optional: false
";
var (scanResult, componentRecorder) = await this.detectorTestUtility
.WithFile("conda-lock.yml", condaLockContent)
.ExecuteDetectorAsync();
var detectedComponents = componentRecorder.GetDetectedComponents();
scanResult.ResultCode.Should().Be(ProcessingResultCode.Success);
// packages from the conda section
this.AssertCondaLockComponentNameAndVersion(detectedComponents, "conda-lock", "2.1.0");
this.AssertCondaLockComponentNameAndVersion(detectedComponents, "urllib3", "1.26.16");
// packages from the pip section
this.AssertPipComponentNameAndVersion(detectedComponents, "certifi", "2023.5.7");
this.AssertPipComponentNameAndVersion(detectedComponents, "requests", "2.31.0");
detectedComponents.Should().HaveCount(4);
var condaLockTop = detectedComponents.Single(c =>
c.Component is CondaComponent cl &&
cl.Name.Equals("conda-lock") &&
cl.Version.Equals("2.1.0")).Component as CondaComponent;
condaLockTop!.MD5.Should().Be("1e07afcf3d3e371fc3a3681fe9b78e90");
condaLockTop.Sha256.Should().Be("05319e84cbd36f6a05563954d2dbff041de6ece406a59650784918026080c98c");
var urllib = detectedComponents.Single(c =>
c.Component is CondaComponent u &&
u.Name.Equals("urllib3") &&
u.Version.Equals("1.26.16")).Component as CondaComponent;
urllib!.MD5.Should().Be("4b62a74f7e797800039971833968e23f");
urllib.Sha256.Should().Be("b9e919a9bcb4cb291fe60952895bf0c3ce9dbcbeaa3d5706131f862756fabc40");
var requests = detectedComponents.Single(c =>
c.Component is PipComponent r &&
r.Name.Equals("requests") &&
r.Version.Equals("2.31.0")).Component as PipComponent;
requests!.Sha256.Should().Be("58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f");
var certifi = detectedComponents.Single(c =>
c.Component is PipComponent cf &&
cf.Name.Equals("certifi") &&
cf.Version.Equals("2023.5.7")).Component as PipComponent;
certifi!.Sha256.Should().Be("c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716");
}
private void AssertCondaLockComponentNameAndVersion(IEnumerable<DetectedComponent> detectedComponents, string name, string version)
{
detectedComponents.SingleOrDefault(c =>
c.Component is CondaComponent component &&
component.Name.Equals(name) &&
component.Version.Equals(version)).Should().NotBeNull(
$"Component with name {name} and version {version} was not found");
}
private void AssertPipComponentNameAndVersion(IEnumerable<DetectedComponent> detectedComponents, string name, string version)
{
detectedComponents.SingleOrDefault(c =>
c.Component is PipComponent component &&
component.Name.Equals(name) &&
component.Version.Equals(version)).Should().NotBeNull(
$"Component with name {name} and version {version} was not found");
}
}