feat(api, web): implement short install link functionality for agents
- Added new API endpoints for creating, retrieving, and revoking install links for agents. - Enhanced the agent installation process with short links accessible via `/agent-install/:id` and `/:slug`. - Updated the README and documentation to reflect the new installation method and usage instructions. - Refactored relevant components in the web application to support the new install link feature. - Improved error handling and validation for install link operations. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { describe, it, expect, afterAll } from 'vitest'
|
||||
import { buildApp } from '../app.js'
|
||||
import type { AppConfig } from '../config.js'
|
||||
|
||||
const testConfig: AppConfig = {
|
||||
databaseUrl: 'sqlite::memory:',
|
||||
jwtSecret: 'test',
|
||||
jwtTtlHours: 24,
|
||||
serverPort: 8080,
|
||||
staticDir: null,
|
||||
logLevel: 'error',
|
||||
authRequired: false,
|
||||
authIssuer: 'https://auth.test',
|
||||
authPortalUrl: 'http://localhost:5175',
|
||||
publicBaseUrl: 'https://fw.example.com',
|
||||
enrollSeed: 'test-seed',
|
||||
}
|
||||
|
||||
describe('install-links', () => {
|
||||
const appPromise = buildApp({ memory: true, config: testConfig })
|
||||
|
||||
afterAll(async () => {
|
||||
const app = await appPromise
|
||||
await app.close()
|
||||
})
|
||||
|
||||
it('creates link and serves scripts by id and slug', async () => {
|
||||
const app = await appPromise
|
||||
await app.ready()
|
||||
|
||||
const created = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/v1/install-links',
|
||||
payload: { name: 'web-01', platform: 'linux' },
|
||||
})
|
||||
expect(created.statusCode).toBe(201)
|
||||
const body = created.json() as {
|
||||
id: string
|
||||
slug: string
|
||||
curl: { by_id: string; by_slug: string }
|
||||
}
|
||||
expect(body.id).toBeTruthy()
|
||||
expect(body.slug).toBeTruthy()
|
||||
expect(body.curl.by_id).toContain(`/agent-install/${body.id}`)
|
||||
|
||||
const byId = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/agent-install/${body.id}`,
|
||||
})
|
||||
expect(byId.statusCode).toBe(200)
|
||||
expect(byId.headers['content-type']).toContain('text/x-shellscript')
|
||||
expect(byId.body).toContain("EVOFW_CLIENT_NAME='web-01'")
|
||||
expect(byId.body).toContain("EVOFW_SEED='test-seed'")
|
||||
|
||||
const bySlug = await app.inject({
|
||||
method: 'GET',
|
||||
url: `/${body.slug}`,
|
||||
})
|
||||
expect(bySlug.statusCode).toBe(200)
|
||||
expect(bySlug.body).toContain("EVOFW_CP_URL='https://fw.example.com'")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user