-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathifc_test.go
More file actions
366 lines (315 loc) · 11.1 KB
/
Copy pathifc_test.go
File metadata and controls
366 lines (315 loc) · 11.1 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
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
package ifc
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLabelListIssues(t *testing.T) {
t.Parallel()
t.Run("public repo issues are untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelListIssues(false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private repo issues are trusted and private", func(t *testing.T) {
t.Parallel()
label := LabelListIssues(true)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelRepoUserContent(t *testing.T) {
t.Parallel()
t.Run("public repo user content is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelRepoUserContent(false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private repo user content is trusted and private", func(t *testing.T) {
t.Parallel()
label := LabelRepoUserContent(true)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelSearchIssues(t *testing.T) {
t.Parallel()
tests := []struct {
name string
visibilities []bool // true == private
wantIntegrity Integrity
wantConfidential Confidentiality
}{
{
name: "empty result is treated as public",
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPublic,
},
{
name: "single public repo",
visibilities: []bool{false},
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPublic,
},
{
name: "all public repos stay public",
visibilities: []bool{false, false, false},
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPublic,
},
{
name: "mixed public and private repos become untrusted private",
visibilities: []bool{false, true, false},
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPrivate,
},
{
name: "all private repos stay trusted private",
visibilities: []bool{true, true},
wantIntegrity: IntegrityTrusted,
wantConfidential: ConfidentialityPrivate,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
label := LabelSearchIssues(tc.visibilities)
assert.Equal(t, tc.wantIntegrity, label.Integrity)
assert.Equal(t, tc.wantConfidential, label.Confidentiality)
})
}
}
func TestLabelRepoMetadata(t *testing.T) {
t.Parallel()
t.Run("public repo metadata is trusted and public", func(t *testing.T) {
t.Parallel()
label := LabelRepoMetadata(false)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private repo metadata is trusted and private", func(t *testing.T) {
t.Parallel()
label := LabelRepoMetadata(true)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelGetMe(t *testing.T) {
t.Parallel()
// get_me exposes private_gists/total_private_repos/owned_private_repos,
// which are not part of the public profile, so the result is trusted but
// private — never public.
label := LabelGetMe()
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
}
func TestLabelRelease(t *testing.T) {
t.Parallel()
t.Run("public repo with no draft is trusted and public", func(t *testing.T) {
t.Parallel()
label := LabelRelease(false, false)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("public repo with a draft release is private", func(t *testing.T) {
t.Parallel()
// Draft releases are visible only to push-access users, so a draft on
// a public repo must not be labeled public.
label := LabelRelease(false, true)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
t.Run("private repo is private regardless of draft", func(t *testing.T) {
t.Parallel()
for _, hasDraft := range []bool{false, true} {
label := LabelRelease(true, hasDraft)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
}
})
}
func TestLabelCollaboratorRoster(t *testing.T) {
t.Parallel()
// A collaborator roster requires push access to list, so it is never
// world-readable — always trusted and private.
label := LabelCollaboratorRoster()
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
}
func TestLabelCommitContents(t *testing.T) {
t.Parallel()
t.Run("public repo commit content is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelCommitContents(false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private repo commit content is trusted and private", func(t *testing.T) {
t.Parallel()
label := LabelCommitContents(true)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelActionsResult(t *testing.T) {
t.Parallel()
t.Run("public repo actions result is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelActionsResult(false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private repo actions result is untrusted and private", func(t *testing.T) {
t.Parallel()
label := LabelActionsResult(true)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelSecurityAlert(t *testing.T) {
t.Parallel()
label := LabelSecurityAlert()
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality,
"security alerts are access-restricted regardless of repo visibility")
}
func TestLabelGlobalSecurityAdvisory(t *testing.T) {
t.Parallel()
label := LabelGlobalSecurityAdvisory()
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
}
func TestLabelRepositorySecurityAdvisory(t *testing.T) {
t.Parallel()
t.Run("public repo with all published advisories is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelRepositorySecurityAdvisory(false, true)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("public repo with an unpublished advisory is untrusted and private", func(t *testing.T) {
t.Parallel()
// draft/triage/closed advisories are not world-readable even on a
// public repo, so confidentiality must be private.
label := LabelRepositorySecurityAdvisory(false, false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
t.Run("private repo advisory is untrusted and private", func(t *testing.T) {
t.Parallel()
label := LabelRepositorySecurityAdvisory(true, true)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
t.Run("private repo with unpublished advisory is untrusted and private", func(t *testing.T) {
t.Parallel()
label := LabelRepositorySecurityAdvisory(true, false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelGist(t *testing.T) {
t.Parallel()
t.Run("public gist is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelGist()
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("secret gist is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelGist()
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
}
func TestLabelGistList(t *testing.T) {
t.Parallel()
label := LabelGistList()
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
}
func TestLabelProject(t *testing.T) {
t.Parallel()
t.Run("public project is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelProject(false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private project metadata is trusted and private", func(t *testing.T) {
t.Parallel()
label := LabelProject(true)
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelProjectList(t *testing.T) {
t.Parallel()
tests := []struct {
name string
visibilities []bool // true == private
wantIntegrity Integrity
wantConfidential Confidentiality
}{
{
name: "empty result is treated as public",
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPublic,
},
{
name: "all public projects stay public",
visibilities: []bool{false, false},
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPublic,
},
{
name: "mixed public and private projects become untrusted private",
visibilities: []bool{false, true},
wantIntegrity: IntegrityUntrusted,
wantConfidential: ConfidentialityPrivate,
},
{
name: "all private projects stay trusted private",
visibilities: []bool{true, true},
wantIntegrity: IntegrityTrusted,
wantConfidential: ConfidentialityPrivate,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
label := LabelProjectList(tc.visibilities)
assert.Equal(t, tc.wantIntegrity, label.Integrity)
assert.Equal(t, tc.wantConfidential, label.Confidentiality)
})
}
}
func TestLabelProjectContent(t *testing.T) {
t.Parallel()
t.Run("public project content is untrusted and public", func(t *testing.T) {
t.Parallel()
label := LabelProjectContent(false)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPublic, label.Confidentiality)
})
t.Run("private project content is untrusted and private", func(t *testing.T) {
t.Parallel()
label := LabelProjectContent(true)
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
})
}
func TestLabelTeam(t *testing.T) {
t.Parallel()
label := LabelTeam()
assert.Equal(t, IntegrityTrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
}
func TestLabelNotificationDetails(t *testing.T) {
t.Parallel()
label := LabelNotificationDetails()
assert.Equal(t, IntegrityUntrusted, label.Integrity)
assert.Equal(t, ConfidentialityPrivate, label.Confidentiality)
}