1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Convert audit-logs JS files to TypeScript (#55597)

This commit is contained in:
Kevin Heis
2025-05-19 16:25:56 -07:00
committed by GitHub
parent b7ae01e777
commit e3b78a67d7
2 changed files with 36 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ describe('audit log events docs', () => {
path: '/authentication/keeping-your-account-and-data-secure/security-log-events', path: '/authentication/keeping-your-account-and-data-secure/security-log-events',
type: 'user', type: 'user',
}, },
] ] as const
// This test ensures that the audit log event page components and Markdown // This test ensures that the audit log event page components and Markdown
// file are in sync. Additionally, it checks all event categories are // file are in sync. Additionally, it checks all event categories are
@@ -32,7 +32,7 @@ describe('audit log events docs', () => {
// the enterprise events page has no FPT versioned audit log data // the enterprise events page has no FPT versioned audit log data
if (page.type === 'enterprise' && version === 'free-pro-team@latest') continue if (page.type === 'enterprise' && version === 'free-pro-team@latest') continue
const auditLogEvents = getCategorizedAuditLogEvents(page.type, version, true) const auditLogEvents = getCategorizedAuditLogEvents(page.type, version)
if (Object.keys(auditLogEvents).length === 0) { if (Object.keys(auditLogEvents).length === 0) {
console.warn(`There are no audit log events for ${page.path} with version '${version}'.`) console.warn(`There are no audit log events for ${page.path} with version '${version}'.`)

View File

@@ -1,70 +1,90 @@
import { describe, expect, test } from 'vitest' import { describe, expect, test } from 'vitest'
import { filterByAllowlistValues, filterAndUpdateGhesDataByAllowlistValues } from '../../lib' import { filterByAllowlistValues, filterAndUpdateGhesDataByAllowlistValues } from '../../lib'
import type { RawAuditLogEventT, VersionedAuditLogData } from '../../types'
describe('audit log event fitering', () => { describe('audit log event fitering', () => {
test('matches single allowlist value', () => { test('matches single allowlist value', () => {
const eventsToProcess = [ const eventsToProcess: RawAuditLogEventT[] = [
{ {
action: 'repo.create', action: 'repo.create',
_allowlists: ['user'], _allowlists: ['user'],
description: 'repo was created', description: 'repo was created',
docs_reference_links: '',
ghes: {},
}, },
] ]
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user') const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user', [], {
sha: '',
appendedDescriptions: {},
})
expect(filteredEvents[0].action).toEqual('repo.create') expect(filteredEvents[0].action).toEqual('repo.create')
}) })
test('matches multiple allowlist values', () => { test('matches multiple allowlist values', () => {
const eventsToProcess = [ const eventsToProcess: RawAuditLogEventT[] = [
{ {
action: 'repo.create', action: 'repo.create',
_allowlists: ['user'], _allowlists: ['user'],
description: 'repo was created', description: 'repo was created',
docs_reference_links: '',
ghes: {},
}, },
{ {
action: 'repo.delete', action: 'repo.delete',
_allowlists: ['organization'], _allowlists: ['organization'],
description: 'repo was deleted', description: 'repo was deleted',
docs_reference_links: '',
ghes: {},
}, },
] ]
const filteredEvents = filterByAllowlistValues(eventsToProcess, ['user', 'organization']) const filteredEvents = filterByAllowlistValues(eventsToProcess, ['user', 'organization'], [], {
sha: '',
appendedDescriptions: {},
})
expect(filteredEvents[0].action).toEqual('repo.create') expect(filteredEvents[0].action).toEqual('repo.create')
expect(filteredEvents.length).toEqual(2) expect(filteredEvents.length).toEqual(2)
}) })
test('does not match non-matching allowlist value', () => { test('does not match non-matching allowlist value', () => {
const eventsToProcess = [ const eventsToProcess: RawAuditLogEventT[] = [
{ {
action: 'repo.create', action: 'repo.create',
_allowlists: ['user'], _allowlists: ['user'],
description: 'repo was created', description: 'repo was created',
docs_reference_links: '',
ghes: {},
}, },
] ]
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'organization') const filteredEvents = filterByAllowlistValues(eventsToProcess, 'organization', [], {
sha: '',
appendedDescriptions: {},
})
expect(filteredEvents.length).toBe(0) expect(filteredEvents.length).toBe(0)
}) })
test('ghes filters and updates multiple ghes versions', () => { test('ghes filters and updates multiple ghes versions', () => {
const eventsToProcess = [ const eventsToProcess: RawAuditLogEventT[] = [
{ {
action: 'repo.create', action: 'repo.create',
description: 'repo was created', description: 'repo was created',
docs_reference_links: '',
_allowlists: [],
ghes: { ghes: {
'3.10': { '3.10': {
_allowlists: ['user'], _allowlists: ['user'],
}, },
3.11: { '3.11': {
_allowlists: ['user'], _allowlists: ['user'],
}, },
}, },
}, },
] ]
const currentEvents = { const currentEvents: VersionedAuditLogData = {
'ghes-3.11': { 'ghes-3.11': {
organization: [ organization: [
{ {
@@ -90,10 +110,13 @@ describe('audit log event fitering', () => {
eventsToProcess, eventsToProcess,
'user', 'user',
currentEvents, currentEvents,
{}, {
sha: '',
appendedDescriptions: {},
},
auditLogPage, auditLogPage,
) )
const getActions = (version) => const getActions = (version: string) =>
currentEvents[version][auditLogPage].map((event) => event.action) currentEvents[version][auditLogPage].map((event) => event.action)
expect(getActions('ghes-3.10').includes('repo.create')).toBe(true) expect(getActions('ghes-3.10').includes('repo.create')).toBe(true)
expect(getActions('ghes-3.11').includes('repo.create')).toBe(true) expect(getActions('ghes-3.11').includes('repo.create')).toBe(true)