Files
workspace/.opencode-sandbox/tests/ssh.test.ts

85 lines
2.6 KiB
TypeScript

import { exec } from 'child_process'
import { promisify } from 'util'
import * as fs from 'fs'
import * as path from 'path'
const execAsync = promisify(exec)
describe('SSH/Gitea Integration', () => {
const SSH_DIR = '/root/.ssh'
const SSH_KEY = path.join(SSH_DIR, 'id_ed25519')
const KNOWN_HOSTS = path.join(SSH_DIR, 'known_hosts')
describe('SSH Key Setup', () => {
test('SSH directory exists', () => {
expect(fs.existsSync(SSH_DIR)).toBe(true)
})
test('SSH directory has correct permissions (0700)', () => {
const stats = fs.statSync(SSH_DIR)
const mode = stats.mode & 0o777
expect(mode).toBe(0o700)
})
test('SSH key file exists', () => {
expect(fs.existsSync(SSH_KEY)).toBe(true)
})
test('SSH key has correct permissions (0600)', () => {
const stats = fs.statSync(SSH_KEY)
const mode = stats.mode & 0o777
expect(mode).toBe(0o600)
})
})
describe('Gitea Server', () => {
test('known_hosts file exists', () => {
expect(fs.existsSync(KNOWN_HOSTS)).toBe(true)
})
test('known_hosts contains git.processhub.work', () => {
const content = fs.readFileSync(KNOWN_HOSTS, 'utf8')
expect(content).toContain('git.processhub.work')
})
})
describe('Git Configuration', () => {
test('git user.email is configured', async () => {
const { stdout } = await execAsync('git config --global user.email')
expect(stdout.trim()).toBe('gabriel.pereira@protonmail.com')
})
test('git user.name is configured', async () => {
const { stdout } = await execAsync('git config --global user.name')
expect(stdout.trim()).toBe('gabspereira')
})
})
describe('Gitea SSH Connection', () => {
test('SSH connection to Gitea succeeds', async () => {
try {
const { stdout, stderr } = await execAsync(
'ssh -T -o ConnectTimeout=10 git@git.processhub.work',
{ timeout: 15000 }
)
const output = stdout + stderr
expect(output).toContain('successfully authenticated')
} catch (error: any) {
const output = error.stdout + error.stderr
expect(output).toContain('gabspereira')
expect(output).toContain('successfully authenticated')
}
}, 20000)
})
describe('Git Remote Access', () => {
test('Can access Gitea repository', async () => {
const { stdout, stderr } = await execAsync(
'git ls-remote git@git.processhub.work:gabspereira/workspace.git HEAD',
{ timeout: 15000 }
)
expect(stdout).toMatch(/[a-f0-9]+\s+HEAD/)
}, 20000)
})
})