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
122 lines
3.9 KiB
JavaScript
122 lines
3.9 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
import { info, error, warn, debug, setContext, clearContext, runWithContext } from '../../server/utils/logger.js'
|
|
|
|
describe('logger', () => {
|
|
const testState = {
|
|
originalLog: null,
|
|
originalError: null,
|
|
originalWarn: null,
|
|
originalDebug: null,
|
|
logCalls: [],
|
|
errorCalls: [],
|
|
warnCalls: [],
|
|
debugCalls: [],
|
|
}
|
|
|
|
beforeEach(() => {
|
|
testState.logCalls = []
|
|
testState.errorCalls = []
|
|
testState.warnCalls = []
|
|
testState.debugCalls = []
|
|
testState.originalLog = console.log
|
|
testState.originalError = console.error
|
|
testState.originalWarn = console.warn
|
|
testState.originalDebug = console.debug
|
|
console.log = vi.fn((...args) => testState.logCalls.push(args))
|
|
console.error = vi.fn((...args) => testState.errorCalls.push(args))
|
|
console.warn = vi.fn((...args) => testState.warnCalls.push(args))
|
|
console.debug = vi.fn((...args) => testState.debugCalls.push(args))
|
|
})
|
|
|
|
afterEach(() => {
|
|
console.log = testState.originalLog
|
|
console.error = testState.originalError
|
|
console.warn = testState.originalWarn
|
|
console.debug = testState.originalDebug
|
|
})
|
|
|
|
it('logs info message', () => {
|
|
info('Test message')
|
|
expect(testState.logCalls.length).toBe(1)
|
|
const logMsg = testState.logCalls[0][0]
|
|
expect(logMsg).toContain('[INFO]')
|
|
expect(logMsg).toContain('Test message')
|
|
})
|
|
|
|
it('includes request context when set', async () => {
|
|
await runWithContext('req-123', 'user-456', async () => {
|
|
info('Test message')
|
|
const logMsg = testState.logCalls[0][0]
|
|
expect(logMsg).toContain('req-123')
|
|
expect(logMsg).toContain('user-456')
|
|
})
|
|
})
|
|
|
|
it('includes additional context', () => {
|
|
info('Test message', { key: 'value', count: 42 })
|
|
const logMsg = testState.logCalls[0][0]
|
|
expect(logMsg).toContain('key')
|
|
expect(logMsg).toContain('value')
|
|
expect(logMsg).toContain('42')
|
|
})
|
|
|
|
it('logs error with stack trace', () => {
|
|
const err = new Error('Test error')
|
|
error('Failed', { error: err })
|
|
expect(testState.errorCalls.length).toBe(1)
|
|
const errorMsg = testState.errorCalls[0][0]
|
|
expect(errorMsg).toContain('[ERROR]')
|
|
expect(errorMsg).toContain('Failed')
|
|
expect(errorMsg).toContain('stack')
|
|
})
|
|
|
|
it('logs warning', () => {
|
|
warn('Warning message')
|
|
expect(testState.warnCalls.length).toBe(1)
|
|
const warnMsg = testState.warnCalls[0][0]
|
|
expect(warnMsg).toContain('[WARN]')
|
|
})
|
|
|
|
it('logs debug only in development', () => {
|
|
const originalEnv = process.env.NODE_ENV
|
|
process.env.NODE_ENV = 'development'
|
|
debug('Debug message')
|
|
expect(testState.debugCalls.length).toBe(1)
|
|
process.env.NODE_ENV = originalEnv
|
|
})
|
|
|
|
it('does not log debug in production', () => {
|
|
const originalEnv = process.env.NODE_ENV
|
|
process.env.NODE_ENV = 'production'
|
|
debug('Debug message')
|
|
expect(testState.debugCalls.length).toBe(0)
|
|
process.env.NODE_ENV = originalEnv
|
|
})
|
|
|
|
it('clears context', async () => {
|
|
await runWithContext('req-123', 'user-456', async () => {
|
|
info('Test with context')
|
|
const logMsg = testState.logCalls[0][0]
|
|
expect(logMsg).toContain('req-123')
|
|
})
|
|
// Context should be cleared after runWithContext completes
|
|
info('Test without context')
|
|
const logMsg = testState.logCalls[testState.logCalls.length - 1][0]
|
|
expect(logMsg).not.toContain('req-123')
|
|
})
|
|
|
|
it('supports deprecated setContext/clearContext API', async () => {
|
|
await runWithContext(null, null, async () => {
|
|
setContext('req-123', 'user-456')
|
|
info('Test message')
|
|
const logMsg = testState.logCalls[0][0]
|
|
expect(logMsg).toContain('req-123')
|
|
expect(logMsg).toContain('user-456')
|
|
clearContext()
|
|
info('Test after clear')
|
|
const logMsg2 = testState.logCalls[1][0]
|
|
expect(logMsg2).not.toContain('req-123')
|
|
})
|
|
})
|
|
})
|