-
Notifications
You must be signed in to change notification settings - Fork 1
fix: add CI workflow, tests, linting, and security hardening #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, master] | ||
| pull_request: | ||
| branches: [main, master] | ||
|
|
||
| jobs: | ||
| lint-and-test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [18, 20, 22] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Test | ||
| run: npm test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| node_modules/ | ||
| .env | ||
| *.log | ||
| /tmp/ | ||
| dist/ | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| const request = require('supertest'); | ||
| const { app, shellEscape } = require('../server'); | ||
|
|
||
| describe('Health endpoint', () => { | ||
| test('GET /health returns healthy status', async () => { | ||
| const res = await request(app).get('/health'); | ||
| expect(res.status).toBe(200); | ||
| expect(res.body.status).toBe('healthy'); | ||
| expect(res.body.service).toBe('road-deploy'); | ||
| expect(res.body.version).toBe('1.0.0'); | ||
| expect(res.body.timestamp).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Deploy endpoint validation', () => { | ||
| test('POST /api/deploy rejects missing domain', async () => { | ||
| const res = await request(app) | ||
| .post('/api/deploy') | ||
| .send({ repo_url: 'https://github.com/test/repo.git' }); | ||
| expect(res.status).toBe(400); | ||
| expect(res.body.success).toBe(false); | ||
| expect(res.body.error).toMatch(/domain.*required/i); | ||
| }); | ||
|
|
||
| test('POST /api/deploy rejects missing repo_url', async () => { | ||
| const res = await request(app) | ||
| .post('/api/deploy') | ||
| .send({ domain: 'test.blackroad.io' }); | ||
| expect(res.status).toBe(400); | ||
| expect(res.body.success).toBe(false); | ||
| expect(res.body.error).toMatch(/repo_url.*required/i); | ||
| }); | ||
|
|
||
| test('POST /api/deploy rejects empty body', async () => { | ||
| const res = await request(app) | ||
| .post('/api/deploy') | ||
| .send({}); | ||
| expect(res.status).toBe(400); | ||
| expect(res.body.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Deployment status endpoint', () => { | ||
| test('GET /api/deploy/:id returns status for unknown id', async () => { | ||
| const res = await request(app).get('/api/deploy/nonexistent-id'); | ||
| expect(res.status).toBe(200); | ||
| expect(res.body.success).toBe(true); | ||
| expect(res.body.deployment_id).toBe('nonexistent-id'); | ||
| expect(res.body.status).toBe('completed_or_failed'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Webhook validation', () => { | ||
| test('POST /api/webhook/github rejects invalid payload', async () => { | ||
| const res = await request(app) | ||
| .post('/api/webhook/github') | ||
| .send({}); | ||
| expect(res.status).toBe(400); | ||
| expect(res.body.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('shellEscape', () => { | ||
| test('escapes single quotes', () => { | ||
| expect(shellEscape("it's")).toBe("'it'\\''s'"); | ||
| }); | ||
|
|
||
| test('wraps normal strings in single quotes', () => { | ||
| expect(shellEscape('hello')).toBe("'hello'"); | ||
| }); | ||
|
|
||
| test('handles empty string', () => { | ||
| expect(shellEscape('')).toBe("''"); | ||
| }); | ||
|
|
||
| test('returns empty string for non-string input', () => { | ||
| expect(shellEscape(undefined)).toBe(''); | ||
| expect(shellEscape(null)).toBe(''); | ||
| }); | ||
|
|
||
| test('escapes command injection attempts', () => { | ||
| const malicious = '; rm -rf /'; | ||
| const escaped = shellEscape(malicious); | ||
| expect(escaped).toBe("'; rm -rf /'"); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| const js = require('@eslint/js'); | ||
|
|
||
| module.exports = [ | ||
| js.configs.recommended, | ||
| { | ||
| languageOptions: { | ||
| ecmaVersion: 2022, | ||
| sourceType: 'commonjs', | ||
| globals: { | ||
| console: 'readonly', | ||
| process: 'readonly', | ||
| require: 'readonly', | ||
| module: 'readonly', | ||
| __dirname: 'readonly', | ||
| __filename: 'readonly', | ||
| setTimeout: 'readonly', | ||
| clearTimeout: 'readonly', | ||
| setInterval: 'readonly', | ||
| clearInterval: 'readonly', | ||
| Buffer: 'readonly', | ||
| describe: 'readonly', | ||
| it: 'readonly', | ||
| test: 'readonly', | ||
| expect: 'readonly', | ||
| beforeAll: 'readonly', | ||
| afterAll: 'readonly', | ||
| beforeEach: 'readonly', | ||
| afterEach: 'readonly', | ||
| }, | ||
|
Comment on lines
+21
to
+29
|
||
| }, | ||
| rules: { | ||
| 'no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }], | ||
| 'no-console': 'off', | ||
| 'no-empty': ['error', { allowEmptyCatch: true }], | ||
| }, | ||
| }, | ||
| { | ||
| ignores: ['node_modules/', 'coverage/'], | ||
| }, | ||
| ]; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new CI matrix runs
npm run linton Node 18, but this commit also upgrades toeslint@10.0.3, whose lockfile entry requiresnode: ^20.19.0 || ^22.13.0 || >=24(package-lock.json), so the Node 18 leg will fail consistently and keep the workflow red for pushes/PRs targetingmain/master. Either remove Node 18 from the matrix or pin ESLint to a Node-18-compatible major.Useful? React with 👍 / 👎.