-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathexcluded-actors.ts
More file actions
133 lines (107 loc) · 6.34 KB
/
excluded-actors.ts
File metadata and controls
133 lines (107 loc) · 6.34 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
import { describe, expect, test } from 'vitest'
import { isActorExcluded, actorTypeMap } from '../scripts/sync'
describe('excluded_actors filtering', () => {
test('returns false when excludedActors is undefined', () => {
expect(isActorExcluded(undefined, 'server_to_server')).toBe(false)
})
test('returns false when excludedActors is null', () => {
expect(isActorExcluded(null, 'server_to_server')).toBe(false)
})
test('returns false when excludedActors is not an array', () => {
expect(isActorExcluded('not-an-array', 'server_to_server')).toBe(false)
expect(isActorExcluded({}, 'server_to_server')).toBe(false)
})
test('returns false when excludedActors is empty array', () => {
expect(isActorExcluded([], 'server_to_server')).toBe(false)
})
test('returns true when actorType is in excludedActors', () => {
expect(isActorExcluded(['server_to_server'], 'server_to_server')).toBe(true)
expect(isActorExcluded(['server_to_server', 'fine_grained_pat'], 'server_to_server')).toBe(true)
expect(isActorExcluded(['user_to_server', 'fine_grained_pat'], 'fine_grained_pat')).toBe(true)
})
test('returns false when actorType is not in excludedActors', () => {
expect(isActorExcluded(['server_to_server'], 'fine_grained_pat')).toBe(false)
expect(isActorExcluded(['user_to_server'], 'server_to_server')).toBe(false)
expect(isActorExcluded(['server_to_server', 'user_to_server'], 'fine_grained_pat')).toBe(false)
})
test('handles various actor type values', () => {
const excludedActors = ['server_to_server', 'fine_grained_pat', 'user_to_server']
expect(isActorExcluded(excludedActors, 'server_to_server')).toBe(true)
expect(isActorExcluded(excludedActors, 'fine_grained_pat')).toBe(true)
expect(isActorExcluded(excludedActors, 'user_to_server')).toBe(true)
expect(isActorExcluded(excludedActors, 'some_other_actor')).toBe(false)
})
test('handles actor type mapping from generic to YAML values', () => {
// Test with actual YAML values that would come from the config files
expect(isActorExcluded(['UserProgrammaticAccess'], 'fine_grained_pat', actorTypeMap)).toBe(true)
expect(isActorExcluded(['github_app'], 'server_to_server', actorTypeMap)).toBe(true)
expect(isActorExcluded(['user_access_token'], 'user_to_server', actorTypeMap)).toBe(true)
// Test fallback when no mapping exists
expect(isActorExcluded(['some_unmapped_actor'], 'some_unmapped_actor')).toBe(true)
expect(isActorExcluded(['some_unmapped_actor'], 'different_actor')).toBe(false)
})
test('handles mixed generic and YAML actor type values', () => {
const mixedExcludedActors = ['UserProgrammaticAccess', 'github_app', 'user_access_token']
// Should match mapped values
expect(isActorExcluded(mixedExcludedActors, 'fine_grained_pat', actorTypeMap)).toBe(true)
expect(isActorExcluded(mixedExcludedActors, 'server_to_server', actorTypeMap)).toBe(true)
expect(isActorExcluded(mixedExcludedActors, 'user_to_server', actorTypeMap)).toBe(true)
// Should not match unmapped values
expect(isActorExcluded(mixedExcludedActors, 'unmapped_actor', actorTypeMap)).toBe(false)
})
test('verifies independent filtering of server_to_server and user_to_server', () => {
// Only server_to_server excluded
const onlyServerExcluded = ['server_to_server']
expect(isActorExcluded(onlyServerExcluded, 'server_to_server')).toBe(true)
expect(isActorExcluded(onlyServerExcluded, 'user_to_server')).toBe(false)
// Only user_to_server excluded
const onlyUserExcluded = ['user_to_server']
expect(isActorExcluded(onlyUserExcluded, 'server_to_server')).toBe(false)
expect(isActorExcluded(onlyUserExcluded, 'user_to_server')).toBe(true)
// Both excluded
const bothExcluded = ['server_to_server', 'user_to_server']
expect(isActorExcluded(bothExcluded, 'server_to_server')).toBe(true)
expect(isActorExcluded(bothExcluded, 'user_to_server')).toBe(true)
// Neither excluded
const neitherExcluded = ['fine_grained_pat']
expect(isActorExcluded(neitherExcluded, 'server_to_server')).toBe(false)
expect(isActorExcluded(neitherExcluded, 'user_to_server')).toBe(false)
})
test('handles actor type mapping from generic to YAML values', () => {
// Test with actual YAML values that would come from the config files
expect(
isActorExcluded(['fine_grained_personal_access_token'], 'fine_grained_pat', actorTypeMap),
).toBe(true)
expect(isActorExcluded(['github_app'], 'server_to_server', actorTypeMap)).toBe(true)
expect(isActorExcluded(['user_access_token'], 'user_to_server', actorTypeMap)).toBe(true)
// Test fallback when no mapping exists
expect(isActorExcluded(['some_unmapped_actor'], 'some_unmapped_actor')).toBe(true)
expect(isActorExcluded(['some_unmapped_actor'], 'different_actor')).toBe(false)
})
test('handles mixed generic and YAML actor type values', () => {
const mixedExcludedActors = [
'fine_grained_personal_access_token',
'github_app',
'user_access_token',
]
// Should match mapped values
expect(isActorExcluded(mixedExcludedActors, 'fine_grained_pat', actorTypeMap)).toBe(true)
expect(isActorExcluded(mixedExcludedActors, 'server_to_server', actorTypeMap)).toBe(true)
// Should match mapped values
expect(isActorExcluded(mixedExcludedActors, 'user_to_server', actorTypeMap)).toBe(true)
// Should not match unmapped values
expect(isActorExcluded(mixedExcludedActors, 'unmapped_actor', actorTypeMap)).toBe(false)
})
test('handles UserProgrammaticAccess alias for fine_grained_pat', () => {
// Test that UserProgrammaticAccess (actual source data value) is recognized as fine_grained_pat
expect(isActorExcluded(['UserProgrammaticAccess'], 'fine_grained_pat')).toBe(true)
// Test mixed scenarios with UserProgrammaticAccess
const mixedWithUserProgrammatic = ['UserProgrammaticAccess', 'github_app']
expect(isActorExcluded(mixedWithUserProgrammatic, 'fine_grained_pat')).toBe(true)
expect(isActorExcluded(mixedWithUserProgrammatic, 'server_to_server', actorTypeMap)).toBe(true)
expect(isActorExcluded(mixedWithUserProgrammatic, 'user_to_server')).toBe(false)
// Test that both mapped value and alias work
const bothValues = ['fine_grained_personal_access_token', 'UserProgrammaticAccess']
expect(isActorExcluded(bothValues, 'fine_grained_pat', actorTypeMap)).toBe(true)
})
})