All checks were successful
ci/woodpecker/push/push Pipeline was successful
## 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
104 lines
3.6 KiB
JavaScript
104 lines
3.6 KiB
JavaScript
import { describe, it, expect } from 'vitest'
|
|
import { buildUpdateQuery, getAllowedColumns } from '../../server/utils/queryBuilder.js'
|
|
|
|
describe('queryBuilder', () => {
|
|
describe('buildUpdateQuery', () => {
|
|
it('builds valid UPDATE query for devices', () => {
|
|
const { query, params } = buildUpdateQuery('devices', null, {
|
|
name: 'Test Device',
|
|
lat: 40.7128,
|
|
})
|
|
expect(query).toBe('UPDATE devices SET name = ?, lat = ? WHERE id = ?')
|
|
expect(params).toEqual(['Test Device', 40.7128])
|
|
})
|
|
|
|
it('builds valid UPDATE query for users', () => {
|
|
const { query, params } = buildUpdateQuery('users', null, {
|
|
role: 'admin',
|
|
identifier: 'testuser',
|
|
})
|
|
expect(query).toBe('UPDATE users SET role = ?, identifier = ? WHERE id = ?')
|
|
expect(params).toEqual(['admin', 'testuser'])
|
|
})
|
|
|
|
it('builds valid UPDATE query for pois', () => {
|
|
const { query, params } = buildUpdateQuery('pois', null, {
|
|
label: 'Test POI',
|
|
lat: 40.7128,
|
|
lng: -74.0060,
|
|
})
|
|
expect(query).toBe('UPDATE pois SET label = ?, lat = ?, lng = ? WHERE id = ?')
|
|
expect(params).toEqual(['Test POI', 40.7128, -74.0060])
|
|
})
|
|
|
|
it('returns empty query when no updates', () => {
|
|
const { query, params } = buildUpdateQuery('devices', null, {})
|
|
expect(query).toBe('')
|
|
expect(params).toEqual([])
|
|
})
|
|
|
|
it('throws error for unknown table', () => {
|
|
expect(() => {
|
|
buildUpdateQuery('unknown_table', null, { name: 'test' })
|
|
}).toThrow('Unknown table: unknown_table')
|
|
})
|
|
|
|
it('throws error for invalid column name', () => {
|
|
expect(() => {
|
|
buildUpdateQuery('devices', null, { invalid_column: 'test' })
|
|
}).toThrow('Invalid column: invalid_column for table: devices')
|
|
})
|
|
|
|
it('prevents SQL injection attempts in column names', () => {
|
|
expect(() => {
|
|
buildUpdateQuery('devices', null, { 'name\'; DROP TABLE devices; --': 'test' })
|
|
}).toThrow('Invalid column')
|
|
})
|
|
|
|
it('allows custom allowedColumns set', () => {
|
|
const customColumns = new Set(['name', 'custom_field'])
|
|
const { query, params } = buildUpdateQuery('devices', customColumns, {
|
|
name: 'Test',
|
|
custom_field: 'value',
|
|
})
|
|
expect(query).toBe('UPDATE devices SET name = ?, custom_field = ? WHERE id = ?')
|
|
expect(params).toEqual(['Test', 'value'])
|
|
})
|
|
|
|
it('rejects columns not in custom allowedColumns', () => {
|
|
const customColumns = new Set(['name'])
|
|
expect(() => {
|
|
buildUpdateQuery('devices', customColumns, { name: 'Test', lat: 40.7128 })
|
|
}).toThrow('Invalid column: lat')
|
|
})
|
|
})
|
|
|
|
describe('getAllowedColumns', () => {
|
|
it('returns allowed columns for devices', () => {
|
|
const columns = getAllowedColumns('devices')
|
|
expect(columns).toBeInstanceOf(Set)
|
|
expect(columns.has('name')).toBe(true)
|
|
expect(columns.has('lat')).toBe(true)
|
|
expect(columns.has('invalid')).toBe(false)
|
|
})
|
|
|
|
it('returns allowed columns for users', () => {
|
|
const columns = getAllowedColumns('users')
|
|
expect(columns.has('role')).toBe(true)
|
|
expect(columns.has('identifier')).toBe(true)
|
|
})
|
|
|
|
it('returns allowed columns for pois', () => {
|
|
const columns = getAllowedColumns('pois')
|
|
expect(columns.has('label')).toBe(true)
|
|
expect(columns.has('lat')).toBe(true)
|
|
})
|
|
|
|
it('returns empty set for unknown table', () => {
|
|
const columns = getAllowedColumns('unknown')
|
|
expect(columns).toBeInstanceOf(Set)
|
|
expect(columns.size).toBe(0)
|
|
})
|
|
})
|
|
})
|