Files
EvoFirewall/apps/api/src/services/sync-script.test.ts
T
Denozordec d552f4f326
Build and Push EvoFirewall Docker Image / build-and-push (push) Successful in 1m45s
Build and Push EvoFirewall Docker Image / create-release (push) Skipped
feat(api): implement self-update mechanism for Linux agents
- Added a `maybe_self_update` function in `evofw-firewall.sh` to allow agents to pull the latest version of the sync script from the server, enhancing the agent's ability to stay updated.
- Updated the `/v1/agent/sync-script` endpoint to return ETag and script SHA256 headers, enabling efficient caching and conditional requests.
- Modified the agent policy response to include `script_sha256`, providing visibility into the current version of the sync script.
- Enhanced tests to verify the self-update functionality and ensure correct behavior of the sync script endpoint.

These changes improve the maintainability and reliability of Linux agents by enabling automatic updates of critical scripts.
2026-08-15 16:56:00 +07:00

22 lines
836 B
TypeScript

import { describe, it, expect } from 'vitest'
import { ifNoneMatchHits, getSyncScriptMeta } from './sync-script.js'
describe('sync-script meta', () => {
it('hashes evofw-firewall.sh and matches ETag', () => {
const meta = getSyncScriptMeta()
expect(meta.sha256).toMatch(/^[a-f0-9]{64}$/)
expect(meta.etag).toBe(`"${meta.sha256}"`)
expect(meta.body.subarray(0, 2).toString()).toBe('#!')
})
it('ifNoneMatchHits understands quoted, weak, and star', () => {
const etag = '"abc"'
expect(ifNoneMatchHits('"abc"', etag)).toBe(true)
expect(ifNoneMatchHits('abc', etag)).toBe(true)
expect(ifNoneMatchHits('W/"abc"', etag)).toBe(true)
expect(ifNoneMatchHits('*', etag)).toBe(true)
expect(ifNoneMatchHits('"nope"', etag)).toBe(false)
expect(ifNoneMatchHits(undefined, etag)).toBe(false)
})
})