blob: c451b8604036ec95b5dba8a483a4e2a911674844 [file] [log] [blame]
Bob Badour9ee7d032021-10-25 16:51:48 -07001// Copyright 2021 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 compliance
16
17import (
18 "bytes"
19 "testing"
20)
21
22func TestResolveSourceSharing(t *testing.T) {
23 tests := []struct {
24 name string
25 roots []string
26 edges []annotated
27 expectedResolutions []res
28 }{
29 {
30 name: "independentmodulerestricted",
31 roots: []string{"apacheBin.meta_lic"},
32 edges: []annotated{
33 {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}},
34 },
35 expectedResolutions: []res{},
36 },
37 {
38 name: "independentmodulerestrictedshipped",
39 roots: []string{"apacheBin.meta_lic", "gplWithClasspathException.meta_lic"},
40 edges: []annotated{
41 {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}},
42 },
43 expectedResolutions: []res{
44 {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
45 },
46 },
47 {
48 name: "independentmodulestaticrestricted",
49 roots: []string{"apacheBin.meta_lic"},
50 edges: []annotated{
51 {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", []string{"static"}},
52 },
53 expectedResolutions: []res{
54 {"apacheBin.meta_lic", "apacheBin.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
55 {"apacheBin.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
56 },
57 },
58 {
59 name: "dependentmodulerestricted",
60 roots: []string{"dependentModule.meta_lic"},
61 edges: []annotated{
62 {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}},
63 },
64 expectedResolutions: []res{
65 {"dependentModule.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
66 },
67 },
68 {
69 name: "dependentmodulerestrictedshipclasspath",
70 roots: []string{"dependentModule.meta_lic", "gplWithClasspathException.meta_lic"},
71 edges: []annotated{
72 {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", []string{"dynamic"}},
73 },
74 expectedResolutions: []res{
75 {"dependentModule.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
76 {"dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
77 {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
78 },
79 },
80 {
81 name: "lgplonfprestricted",
82 roots: []string{"lgplBin.meta_lic"},
83 edges: []annotated{
84 {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
85 },
86 expectedResolutions: []res{
87 {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"},
88 {"lgplBin.meta_lic", "apacheLib.meta_lic", "lgplBin.meta_lic", "restricted"},
89 },
90 },
91 {
92 name: "lgplonfpdynamicrestricted",
93 roots: []string{"lgplBin.meta_lic"},
94 edges: []annotated{
95 {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}},
96 },
97 expectedResolutions: []res{
98 {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"},
99 },
100 },
101 {
102 name: "lgplonfpdynamicrestrictedshiplib",
103 roots: []string{"lgplBin.meta_lic", "apacheLib.meta_lic"},
104 edges: []annotated{
105 {"lgplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}},
106 },
107 expectedResolutions: []res{
108 {"lgplBin.meta_lic", "lgplBin.meta_lic", "lgplBin.meta_lic", "restricted"},
109 },
110 },
111 {
112 name: "gplonfprestricted",
113 roots: []string{"gplBin.meta_lic"},
114 edges: []annotated{
115 {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
116 },
117 expectedResolutions: []res{
118 {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"},
119 {"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
120 },
121 },
122 {
123 name: "gplcontainerrestricted",
124 roots: []string{"gplContainer.meta_lic"},
125 edges: []annotated{
126 {"gplContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}},
127 },
128 expectedResolutions: []res{
129 {"gplContainer.meta_lic", "gplContainer.meta_lic", "gplContainer.meta_lic", "restricted"},
130 {"gplContainer.meta_lic", "apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"},
131 {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplContainer.meta_lic", "restricted"},
132 },
133 },
134 {
135 name: "gploncontainerrestricted",
136 roots: []string{"apacheContainer.meta_lic"},
137 edges: []annotated{
138 {"apacheContainer.meta_lic", "apacheLib.meta_lic", []string{"static"}},
139 {"apacheContainer.meta_lic", "gplLib.meta_lic", []string{"static"}},
140 },
141 expectedResolutions: []res{
142 {"apacheContainer.meta_lic", "apacheContainer.meta_lic", "gplLib.meta_lic", "restricted"},
143 {"apacheContainer.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
144 {"gplLib.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
145 },
146 },
147 {
148 name: "gplonbinrestricted",
149 roots: []string{"apacheBin.meta_lic"},
150 edges: []annotated{
151 {"apacheBin.meta_lic", "apacheLib.meta_lic", []string{"static"}},
152 {"apacheBin.meta_lic", "gplLib.meta_lic", []string{"static"}},
153 },
154 expectedResolutions: []res{
155 {"apacheBin.meta_lic", "apacheBin.meta_lic", "gplLib.meta_lic", "restricted"},
156 {"apacheBin.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
157 {"apacheBin.meta_lic", "apacheLib.meta_lic", "gplLib.meta_lic", "restricted"},
158 },
159 },
160 {
161 name: "gplonfpdynamicrestricted",
162 roots: []string{"gplBin.meta_lic"},
163 edges: []annotated{
164 {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}},
165 },
166 expectedResolutions: []res{
167 {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"},
168 },
169 },
170 {
171 name: "gplonfpdynamicrestrictedshiplib",
172 roots: []string{"gplBin.meta_lic", "apacheLib.meta_lic"},
173 edges: []annotated{
174 {"gplBin.meta_lic", "apacheLib.meta_lic", []string{"dynamic"}},
175 },
176 expectedResolutions: []res{
177 {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"},
178 {"gplBin.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
Bob Badourb2855152021-12-08 12:52:59 -0800179 {"apacheLib.meta_lic", "apacheLib.meta_lic", "gplBin.meta_lic", "restricted"},
Bob Badour9ee7d032021-10-25 16:51:48 -0700180 },
181 },
182 {
183 name: "independentmodulereverserestricted",
184 roots: []string{"gplWithClasspathException.meta_lic"},
185 edges: []annotated{
186 {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"dynamic"}},
187 },
188 expectedResolutions: []res{
189 {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
190 },
191 },
192 {
193 name: "independentmodulereversestaticrestricted",
194 roots: []string{"gplWithClasspathException.meta_lic"},
195 edges: []annotated{
196 {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", []string{"static"}},
197 },
198 expectedResolutions: []res{
199 {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
200 {"gplWithClasspathException.meta_lic", "apacheBin.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
201 },
202 },
203 {
204 name: "dependentmodulereverserestricted",
205 roots: []string{"gplWithClasspathException.meta_lic"},
206 edges: []annotated{
207 {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}},
208 },
209 expectedResolutions: []res{
210 {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
211 },
212 },
213 {
214 name: "dependentmodulereverserestrictedshipdependent",
215 roots: []string{"gplWithClasspathException.meta_lic", "dependentModule.meta_lic"},
216 edges: []annotated{
217 {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", []string{"dynamic"}},
218 },
219 expectedResolutions: []res{
220 {"gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
221 {"gplWithClasspathException.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
Bob Badourb2855152021-12-08 12:52:59 -0800222 {"dependentModule.meta_lic", "dependentModule.meta_lic", "gplWithClasspathException.meta_lic", "restricted"},
Bob Badour9ee7d032021-10-25 16:51:48 -0700223 },
224 },
225 {
226 name: "ponrrestricted",
227 roots: []string{"proprietary.meta_lic"},
228 edges: []annotated{
229 {"proprietary.meta_lic", "gplLib.meta_lic", []string{"static"}},
230 },
231 expectedResolutions: []res{
232 {"proprietary.meta_lic", "proprietary.meta_lic", "gplLib.meta_lic", "restricted"},
233 {"proprietary.meta_lic", "gplLib.meta_lic", "gplLib.meta_lic", "restricted"},
234 },
235 },
236 {
237 name: "ronprestricted",
238 roots: []string{"gplBin.meta_lic"},
239 edges: []annotated{
240 {"gplBin.meta_lic", "proprietary.meta_lic", []string{"static"}},
241 },
242 expectedResolutions: []res{
243 {"gplBin.meta_lic", "gplBin.meta_lic", "gplBin.meta_lic", "restricted"},
244 {"gplBin.meta_lic", "proprietary.meta_lic", "gplBin.meta_lic", "restricted"},
245 },
246 },
247 {
248 name: "noticeonb_e_orestricted",
249 roots: []string{"mitBin.meta_lic"},
250 edges: []annotated{
251 {"mitBin.meta_lic", "by_exception.meta_lic", []string{"static"}},
252 },
253 expectedResolutions: []res{},
254 },
255 {
256 name: "b_e_oonnoticerestricted",
257 roots: []string{"by_exception.meta_lic"},
258 edges: []annotated{
259 {"by_exception.meta_lic", "mitLib.meta_lic", []string{"static"}},
260 },
261 expectedResolutions: []res{},
262 },
263 {
264 name: "noticeonreciprecip",
265 roots: []string{"mitBin.meta_lic"},
266 edges: []annotated{
267 {"mitBin.meta_lic", "mplLib.meta_lic", []string{"static"}},
268 },
269 expectedResolutions: []res{
270 {"mitBin.meta_lic", "mplLib.meta_lic", "mplLib.meta_lic", "reciprocal"},
271 },
272 },
273 {
274 name: "reciponnoticerecip",
275 roots: []string{"mplBin.meta_lic"},
276 edges: []annotated{
277 {"mplBin.meta_lic", "mitLib.meta_lic", []string{"static"}},
278 },
279 expectedResolutions: []res{
280 {"mplBin.meta_lic", "mplBin.meta_lic", "mplBin.meta_lic", "reciprocal"},
281 },
282 },
283 }
284 for _, tt := range tests {
285 t.Run(tt.name, func(t *testing.T) {
286 stderr := &bytes.Buffer{}
287 lg, err := toGraph(stderr, tt.roots, tt.edges)
288 if err != nil {
Colin Cross179ec3e2022-01-27 15:47:09 -0800289 t.Errorf("unexpected test data error: got %s, want no error", err)
Bob Badour9ee7d032021-10-25 16:51:48 -0700290 return
291 }
292 expectedRs := toResolutionSet(lg, tt.expectedResolutions)
293 actualRs := ResolveSourceSharing(lg)
Bob Badour103eb0f2022-01-10 13:50:57 -0800294 checkResolves(actualRs, expectedRs, t)
Bob Badour9ee7d032021-10-25 16:51:48 -0700295 })
296 }
297}