| | 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', () => { |
| | |
| | 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) |
| |
|
| | |
| | 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'] |
| |
|
| | |
| | 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) |
| |
|
| | |
| | expect(isActorExcluded(mixedExcludedActors, 'unmapped_actor', actorTypeMap)).toBe(false) |
| | }) |
| |
|
| | test('verifies independent filtering of server_to_server and user_to_server', () => { |
| | |
| | const onlyServerExcluded = ['server_to_server'] |
| | expect(isActorExcluded(onlyServerExcluded, 'server_to_server')).toBe(true) |
| | expect(isActorExcluded(onlyServerExcluded, 'user_to_server')).toBe(false) |
| |
|
| | |
| | const onlyUserExcluded = ['user_to_server'] |
| | expect(isActorExcluded(onlyUserExcluded, 'server_to_server')).toBe(false) |
| | expect(isActorExcluded(onlyUserExcluded, 'user_to_server')).toBe(true) |
| |
|
| | |
| | const bothExcluded = ['server_to_server', 'user_to_server'] |
| | expect(isActorExcluded(bothExcluded, 'server_to_server')).toBe(true) |
| | expect(isActorExcluded(bothExcluded, 'user_to_server')).toBe(true) |
| |
|
| | |
| | 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', () => { |
| | |
| | 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) |
| |
|
| | |
| | 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', |
| | ] |
| |
|
| | |
| | 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) |
| |
|
| | |
| | expect(isActorExcluded(mixedExcludedActors, 'unmapped_actor', actorTypeMap)).toBe(false) |
| | }) |
| |
|
| | test('handles UserProgrammaticAccess alias for fine_grained_pat', () => { |
| | |
| | expect(isActorExcluded(['UserProgrammaticAccess'], 'fine_grained_pat')).toBe(true) |
| |
|
| | |
| | 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) |
| |
|
| | |
| | const bothValues = ['fine_grained_personal_access_token', 'UserProgrammaticAccess'] |
| | expect(isActorExcluded(bothValues, 'fine_grained_pat', actorTypeMap)).toBe(true) |
| | }) |
| | }) |
| |
|