Files
kestrelos/test/unit/cotStore.spec.js
Keli Grubb e61e6bc7e3
All checks were successful
ci/woodpecker/push/push Pipeline was successful
major: kestrel is now a tak server (#6)
## Added

- CoT (Cursor on Target) server on port 8089 enabling ATAK/iTAK device connectivity
- Support for TAK stream protocol and traditional XML CoT messages
- TLS/SSL support with automatic fallback to plain TCP
- Username/password authentication for CoT connections
- Real-time device position tracking with TTL-based expiration (90s default)
- API endpoints: `/api/cot/config`, `/api/cot/server-package`, `/api/cot/truststore`, `/api/me/cot-password`
- TAK Server section in Settings with QR code for iTAK setup
- ATAK password management in Account page for OIDC users
- CoT device markers on map showing real-time positions
- Comprehensive documentation in `docs/` directory
- Environment variables: `COT_PORT`, `COT_TTL_MS`, `COT_REQUIRE_AUTH`, `COT_SSL_CERT`, `COT_SSL_KEY`, `COT_DEBUG`
- Dependencies: `fast-xml-parser`, `jszip`, `qrcode`

## Changed

- Authentication system supports CoT password management for OIDC users
- Database schema includes `cot_password_hash` field
- Test suite refactored to follow functional design principles

## Removed

- Consolidated utility modules: `authConfig.js`, `authSkipPaths.js`, `bootstrap.js`, `poiConstants.js`, `session.js`

## Security

- XML entity expansion protection in CoT parser
- Enhanced input validation and SQL injection prevention
- Authentication timeout to prevent hanging connections

## Breaking Changes

- Port 8089 must be exposed for CoT server. Update firewall rules and Docker/Kubernetes configurations.

## Migration Notes

- OIDC users must set ATAK password via Account settings before connecting
- Docker: expose port 8089 (`-p 8089:8089`)
- Kubernetes: update Helm values to expose port 8089

Co-authored-by: Madison Grubb <madison@elastiflow.com>
Reviewed-on: #6
2026-02-17 16:41:41 +00:00

59 lines
2.1 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest'
import { updateFromCot, getActiveEntities, clearCotStore } from '../../../server/utils/cotStore.js'
describe('cotStore', () => {
beforeEach(() => {
clearCotStore()
})
it('upserts entity by id', async () => {
await updateFromCot({ id: 'uid-1', lat: 37.7, lng: -122.4, label: 'Alpha' })
const active = await getActiveEntities()
expect(active).toHaveLength(1)
expect(active[0].id).toBe('uid-1')
expect(active[0].lat).toBe(37.7)
expect(active[0].lng).toBe(-122.4)
expect(active[0].label).toBe('Alpha')
})
it('updates same uid', async () => {
await updateFromCot({ id: 'uid-1', lat: 37.7, lng: -122.4 })
await updateFromCot({ id: 'uid-1', lat: 38, lng: -123, label: 'Updated' })
const active = await getActiveEntities()
expect(active).toHaveLength(1)
expect(active[0].lat).toBe(38)
expect(active[0].lng).toBe(-123)
expect(active[0].label).toBe('Updated')
})
it('ignores invalid parsed (no id)', async () => {
await updateFromCot({ lat: 37, lng: -122 })
const active = await getActiveEntities()
expect(active).toHaveLength(0)
})
it('ignores invalid parsed (bad coords)', async () => {
await updateFromCot({ id: 'x', lat: Number.NaN, lng: -122 })
await updateFromCot({ id: 'y', lat: 37, lng: Infinity })
const active = await getActiveEntities()
expect(active).toHaveLength(0)
})
it('prunes expired entities after getActiveEntities', async () => {
await updateFromCot({ id: 'uid-1', lat: 37, lng: -122 })
const active1 = await getActiveEntities(100)
expect(active1).toHaveLength(1)
await new Promise(r => setTimeout(r, 150))
const active2 = await getActiveEntities(100)
expect(active2).toHaveLength(0)
})
it('returns multiple active entities within TTL', async () => {
await updateFromCot({ id: 'a', lat: 1, lng: 2, label: 'A' })
await updateFromCot({ id: 'b', lat: 3, lng: 4, label: 'B' })
const active = await getActiveEntities()
expect(active).toHaveLength(2)
expect(active.map(e => e.id).sort()).toEqual(['a', 'b'])
})
})