mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-28 11:25:00 +00:00
Add 36 test cases covering: - Path traversal and symlink attack prevention in archive extraction - SkillHubClient error handling (401/403/404/network) for all endpoints - Inventory store concurrent writes and stale lock recovery - Config store read/write round-trip - Platform utilities (package-manager, updater, paths) - Output formatting (printResult, humanize) Tests use cross-platform commands (node) instead of shell builtins for CI compatibility across macOS/Linux/Windows.
27 lines
909 B
TypeScript
27 lines
909 B
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { stat } from 'node:fs/promises'
|
|
import { mkdtemp, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { applyCredentialPermissions, userStateDir } from '../../../src/platform/paths'
|
|
|
|
describe('userStateDir', () => {
|
|
test('throws when home is empty string', () => {
|
|
expect(() => userStateDir('')).toThrow('Cannot resolve user home directory')
|
|
})
|
|
})
|
|
|
|
describe('applyCredentialPermissions', () => {
|
|
test('sets 0o600 on unix', async () => {
|
|
const tempDir = await mkdtemp(join(tmpdir(), 'skillhub-test-'))
|
|
const tempFile = join(tempDir, 'credential.json')
|
|
await writeFile(tempFile, '{}')
|
|
|
|
await applyCredentialPermissions(tempFile)
|
|
|
|
if (process.platform !== 'win32') {
|
|
const stats = await stat(tempFile)
|
|
expect(stats.mode & 0o777).toBe(0o600)
|
|
}
|
|
})
|
|
})
|