Fix jwt-token
This commit is contained in:
@@ -61,19 +61,19 @@ class AlertService {
|
|||||||
const droneTypeInfo = getDroneTypeInfo(droneType);
|
const droneTypeInfo = getDroneTypeInfo(droneType);
|
||||||
|
|
||||||
// Adjust threat level based on drone type and category
|
// Adjust threat level based on drone type and category
|
||||||
if (droneTypeInfo.threat_level === 'critical' || droneTypeInfo.category.includes('Military')) {
|
if (droneType === 2) { // Orlan - always critical regardless of distance
|
||||||
// Military/Combat drones - ALWAYS CRITICAL regardless of distance
|
|
||||||
threatLevel = 'critical';
|
threatLevel = 'critical';
|
||||||
description = `CRITICAL THREAT: ${droneTypeInfo.name.toUpperCase()} DETECTED - IMMEDIATE RESPONSE REQUIRED`;
|
description = `CRITICAL THREAT: ${droneTypeInfo.name.toUpperCase()} DETECTED - IMMEDIATE RESPONSE REQUIRED`;
|
||||||
actionRequired = true;
|
actionRequired = true;
|
||||||
console.log(`🚨 MILITARY DRONE DETECTED: ${droneTypeInfo.name} - Force escalating to CRITICAL threat level (RSSI: ${rssi})`);
|
console.log(`🚨 ORLAN DRONE DETECTED: ${droneTypeInfo.name} - Force escalating to CRITICAL threat level (RSSI: ${rssi})`);
|
||||||
} else if (droneTypeInfo.threat_level === 'high' || droneTypeInfo.category.includes('Professional')) {
|
} else if (droneTypeInfo.threat_level === 'high' || droneTypeInfo.category.includes('Professional')) {
|
||||||
// Professional/Commercial drone - escalate threat one level
|
// Professional/Commercial drone - escalate threat one level only if close enough
|
||||||
if (threatLevel === 'low') threatLevel = 'medium';
|
if (rssi >= -70) { // Only escalate if medium distance or closer
|
||||||
if (threatLevel === 'medium') threatLevel = 'high';
|
if (threatLevel === 'low') threatLevel = 'medium';
|
||||||
if (threatLevel === 'high') threatLevel = 'critical';
|
if (threatLevel === 'medium') threatLevel = 'high';
|
||||||
description += ` - ${droneTypeInfo.name.toUpperCase()} DETECTED`;
|
description += ` - ${droneTypeInfo.name.toUpperCase()} DETECTED`;
|
||||||
actionRequired = true;
|
actionRequired = true;
|
||||||
|
}
|
||||||
} else if (droneTypeInfo.category.includes('Racing')) {
|
} else if (droneTypeInfo.category.includes('Racing')) {
|
||||||
// Racing/Fast drone - escalate if close
|
// Racing/Fast drone - escalate if close
|
||||||
if (rssi >= -55 && threatLevel !== 'critical') {
|
if (rssi >= -55 && threatLevel !== 'critical') {
|
||||||
|
|||||||
@@ -112,21 +112,38 @@ async function cleanDatabase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Global counter for unique test data
|
||||||
|
let testCounter = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a unique suffix for test data
|
||||||
|
*/
|
||||||
|
function getUniqueTestSuffix() {
|
||||||
|
testCounter++;
|
||||||
|
return Date.now() + '-' + testCounter + '-' + Math.random().toString(36).substr(2, 5);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create test user with specified role and tenant
|
* Create test user with specified role and tenant
|
||||||
*/
|
*/
|
||||||
async function createTestUser(userData = {}) {
|
async function createTestUser(userData = {}) {
|
||||||
const { User, Tenant } = models;
|
const { User, Tenant } = models;
|
||||||
|
|
||||||
// Create default tenant if not exists with unique domain
|
// Generate unique suffix for this test run
|
||||||
const userUniqueSuffix = Date.now() + '-' + Math.random().toString(36).substr(2, 5);
|
const uniqueSuffix = getUniqueTestSuffix();
|
||||||
let tenant = await Tenant.findOne({ where: { slug: 'test-tenant-' + userUniqueSuffix } });
|
|
||||||
|
// Create or find tenant
|
||||||
|
let tenant;
|
||||||
|
if (userData.tenant_id) {
|
||||||
|
tenant = await Tenant.findByPk(userData.tenant_id);
|
||||||
|
}
|
||||||
|
|
||||||
if (!tenant) {
|
if (!tenant) {
|
||||||
try {
|
try {
|
||||||
tenant = await Tenant.create({
|
tenant = await Tenant.create({
|
||||||
name: 'Test Tenant',
|
name: 'Test Tenant',
|
||||||
slug: 'test-tenant-' + userUniqueSuffix,
|
slug: 'test-tenant-' + uniqueSuffix,
|
||||||
domain: 'test-' + userUniqueSuffix + '.example.com',
|
domain: 'test-' + uniqueSuffix + '.example.com',
|
||||||
is_active: true
|
is_active: true
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -136,9 +153,6 @@ async function createTestUser(userData = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a unique username to avoid conflicts
|
|
||||||
const uniqueSuffix = Date.now() + '-' + Math.random().toString(36).substr(2, 5);
|
|
||||||
|
|
||||||
const defaultUserData = {
|
const defaultUserData = {
|
||||||
username: userData.username || 'testuser-' + uniqueSuffix,
|
username: userData.username || 'testuser-' + uniqueSuffix,
|
||||||
email: userData.email || 'test-' + uniqueSuffix + '@example.com',
|
email: userData.email || 'test-' + uniqueSuffix + '@example.com',
|
||||||
@@ -158,14 +172,20 @@ async function createTestUser(userData = {}) {
|
|||||||
async function createTestDevice(deviceData = {}) {
|
async function createTestDevice(deviceData = {}) {
|
||||||
const { Device, Tenant } = models;
|
const { Device, Tenant } = models;
|
||||||
|
|
||||||
// Create default tenant if not exists with unique domain
|
// Generate unique suffix for this test run
|
||||||
const deviceUniqueSuffix = Date.now() + '-' + Math.random().toString(36).substr(2, 5);
|
const uniqueSuffix = getUniqueTestSuffix();
|
||||||
let tenant = await Tenant.findOne({ where: { slug: 'test-tenant-' + deviceUniqueSuffix } });
|
|
||||||
|
// Create or find tenant
|
||||||
|
let tenant;
|
||||||
|
if (deviceData.tenant_id) {
|
||||||
|
tenant = await Tenant.findByPk(deviceData.tenant_id);
|
||||||
|
}
|
||||||
|
|
||||||
if (!tenant) {
|
if (!tenant) {
|
||||||
tenant = await Tenant.create({
|
tenant = await Tenant.create({
|
||||||
name: 'Test Tenant',
|
name: 'Test Tenant',
|
||||||
slug: 'test-tenant-' + deviceUniqueSuffix,
|
slug: 'test-tenant-' + uniqueSuffix,
|
||||||
domain: 'test-' + deviceUniqueSuffix + '.example.com',
|
domain: 'test-' + uniqueSuffix + '.example.com',
|
||||||
is_active: true
|
is_active: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -222,7 +242,7 @@ async function createTestDetection(detectionData = {}) {
|
|||||||
async function createTestTenant(tenantData = {}) {
|
async function createTestTenant(tenantData = {}) {
|
||||||
const { Tenant } = models;
|
const { Tenant } = models;
|
||||||
|
|
||||||
const uniqueSuffix = Date.now() + '-' + Math.random().toString(36).substr(2, 5);
|
const uniqueSuffix = getUniqueTestSuffix();
|
||||||
|
|
||||||
const defaultTenantData = {
|
const defaultTenantData = {
|
||||||
name: 'Test Tenant',
|
name: 'Test Tenant',
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const DRONE_TYPES = {
|
|||||||
0: {
|
0: {
|
||||||
name: "None",
|
name: "None",
|
||||||
category: "Unknown",
|
category: "Unknown",
|
||||||
threat_level: "monitoring",
|
threat_level: "low",
|
||||||
description: "No drone detected or signal below threshold"
|
description: "No drone detected or signal below threshold"
|
||||||
},
|
},
|
||||||
1: {
|
1: {
|
||||||
@@ -49,45 +49,45 @@ const DRONE_TYPES = {
|
|||||||
description: "Russian kamikaze loitering munition"
|
description: "Russian kamikaze loitering munition"
|
||||||
},
|
},
|
||||||
7: {
|
7: {
|
||||||
name: "FPV CrossFire",
|
name: "FPV_CrossFire",
|
||||||
category: "FPV/Racing",
|
category: "FPV/Racing",
|
||||||
threat_level: "high",
|
threat_level: "low",
|
||||||
description: "FPV drone using CrossFire protocol"
|
description: "FPV drone using CrossFire protocol"
|
||||||
},
|
},
|
||||||
8: {
|
8: {
|
||||||
name: "FPV ELRS",
|
name: "FPV_ELRS",
|
||||||
category: "FPV/Racing",
|
category: "FPV/Racing",
|
||||||
threat_level: "high",
|
threat_level: "low",
|
||||||
description: "FPV drone using ExpressLRS protocol"
|
description: "FPV drone using ExpressLRS protocol"
|
||||||
},
|
},
|
||||||
9: {
|
9: {
|
||||||
name: "Maybe Orlan",
|
name: "Maybe Orlan",
|
||||||
category: "Military/Reconnaissance",
|
category: "Military/Reconnaissance/Probable",
|
||||||
threat_level: "high",
|
threat_level: "high",
|
||||||
description: "Possible Orlan drone (uncertain identification)"
|
description: "Possible Orlan drone (uncertain identification)"
|
||||||
},
|
},
|
||||||
10: {
|
10: {
|
||||||
name: "Maybe Zala",
|
name: "Maybe Zala",
|
||||||
category: "Military/Surveillance",
|
category: "Military/Surveillance/Probable",
|
||||||
threat_level: "high",
|
threat_level: "high",
|
||||||
description: "Possible Zala drone (uncertain identification)"
|
description: "Possible Zala drone (uncertain identification)"
|
||||||
},
|
},
|
||||||
11: {
|
11: {
|
||||||
name: "Maybe Lancet",
|
name: "Maybe Lancet",
|
||||||
category: "Military/Kamikaze",
|
category: "Military/Kamikaze/Probable",
|
||||||
threat_level: "high",
|
threat_level: "high",
|
||||||
description: "Possible Lancet drone (uncertain identification)"
|
description: "Possible Lancet drone (uncertain identification)"
|
||||||
},
|
},
|
||||||
12: {
|
12: {
|
||||||
name: "Maybe Eleron",
|
name: "Maybe Eleron",
|
||||||
category: "Military/Tactical",
|
category: "Military/Tactical/Probable",
|
||||||
threat_level: "high",
|
threat_level: "high",
|
||||||
description: "Possible Eleron drone (uncertain identification)"
|
description: "Possible Eleron drone (uncertain identification)"
|
||||||
},
|
},
|
||||||
13: {
|
13: {
|
||||||
name: "DJI",
|
name: "DJI",
|
||||||
category: "Commercial/Professional",
|
category: "Commercial/Professional",
|
||||||
threat_level: "medium",
|
threat_level: "low",
|
||||||
description: "DJI consumer/commercial drone"
|
description: "DJI consumer/commercial drone"
|
||||||
},
|
},
|
||||||
14: {
|
14: {
|
||||||
@@ -98,18 +98,18 @@ const DRONE_TYPES = {
|
|||||||
},
|
},
|
||||||
15: {
|
15: {
|
||||||
name: "Maybe Supercam",
|
name: "Maybe Supercam",
|
||||||
category: "Military/Surveillance",
|
category: "Military/Surveillance/Probable",
|
||||||
threat_level: "high",
|
threat_level: "high",
|
||||||
description: "Possible Supercam drone (uncertain identification)"
|
description: "Possible Supercam drone (uncertain identification)"
|
||||||
},
|
},
|
||||||
16: {
|
16: {
|
||||||
name: "REB",
|
name: "REB",
|
||||||
category: "Military/Electronic Warfare",
|
category: "Military/Electronic Warfare",
|
||||||
threat_level: "critical",
|
threat_level: "high",
|
||||||
description: "Russian Electronic Warfare (REB) drone"
|
description: "Russian Electronic Warfare (REB) drone"
|
||||||
},
|
},
|
||||||
17: {
|
17: {
|
||||||
name: "Crypto Orlan",
|
name: "CryptoOrlan",
|
||||||
category: "Military/Reconnaissance",
|
category: "Military/Reconnaissance",
|
||||||
threat_level: "critical",
|
threat_level: "critical",
|
||||||
description: "Encrypted Orlan drone with enhanced security"
|
description: "Encrypted Orlan drone with enhanced security"
|
||||||
@@ -140,7 +140,7 @@ function getDroneTypeInfo(droneTypeId) {
|
|||||||
// Return default for unknown types
|
// Return default for unknown types
|
||||||
return {
|
return {
|
||||||
id: droneTypeId,
|
id: droneTypeId,
|
||||||
name: `Unknown Type ${droneTypeId}`,
|
name: "Unknown",
|
||||||
category: "Unknown/Unclassified",
|
category: "Unknown/Unclassified",
|
||||||
threat_level: "medium",
|
threat_level: "medium",
|
||||||
description: `Unrecognized drone type ID: ${droneTypeId}`
|
description: `Unrecognized drone type ID: ${droneTypeId}`
|
||||||
@@ -186,11 +186,27 @@ function getDroneTypesByThreatLevel(threatLevel) {
|
|||||||
.map(([id, info]) => ({ id: parseInt(id), ...info }));
|
.map(([id, info]) => ({ id: parseInt(id), ...info }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a drone type ID is valid
|
||||||
|
* @param {number} droneTypeId - The integer drone type ID
|
||||||
|
* @returns {boolean} True if valid, false otherwise
|
||||||
|
*/
|
||||||
|
function isValidDroneType(droneTypeId) {
|
||||||
|
// Handle string inputs
|
||||||
|
if (typeof droneTypeId === 'string') {
|
||||||
|
droneTypeId = parseInt(droneTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a valid number and exists in our mapping
|
||||||
|
return Number.isInteger(droneTypeId) && DRONE_TYPES.hasOwnProperty(droneTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
DRONE_TYPES,
|
DRONE_TYPES,
|
||||||
getDroneTypeInfo,
|
getDroneTypeInfo,
|
||||||
getDroneTypeName,
|
getDroneTypeName,
|
||||||
getAllDroneTypes,
|
getAllDroneTypes,
|
||||||
getDroneTypesByCategory,
|
getDroneTypesByCategory,
|
||||||
getDroneTypesByThreatLevel
|
getDroneTypesByThreatLevel,
|
||||||
|
isValidDroneType
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user