feat(prod): remove hardcoded credentials, clean environment config, and prepare for production deployment
This commit is contained in:
1 parent
f0876face0
commit
d7fa520030
98 files changed
+4317
-794
No files matched your search
@@ -0,0 +1,98 @@
|
||||
// test/branding_unit_test.js
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const vm = require('vm');
|
||||
|
||||
console.log('=========================================');
|
||||
console.log(' RUNNING TDD UNIT TEST FOR BRANDING LOGIC');
|
||||
console.log('=========================================\n');
|
||||
|
||||
// 1. Read and transpile src/lib/branding.ts slightly to make it run in Node.js
|
||||
const brandingCodePath = path.join(__dirname, '../src/lib/branding.ts');
|
||||
let code = fs.readFileSync(brandingCodePath, 'utf8');
|
||||
|
||||
// Strip TypeScript interfaces, return types, parameter types, and export keywords
|
||||
code = code.replace(/export\s+interface\s+\w+\s*\{[^}]*\}/g, '');
|
||||
code = code.replace(/:\s*Branding\b/g, '');
|
||||
code = code.replace(/selectedSiteUuid\?\s*:\s*string/g, 'selectedSiteUuid');
|
||||
code = code.replace(/export\s+/g, '');
|
||||
|
||||
let testCount = 0;
|
||||
let passedCount = 0;
|
||||
|
||||
function assert(label, condition) {
|
||||
testCount++;
|
||||
if (condition) {
|
||||
console.log(` ✓ PASSED: ${label}`);
|
||||
passedCount++;
|
||||
} else {
|
||||
console.error(` ✗ FAILED: ${label}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to run getSiteBranding with mocked environment
|
||||
function runGetSiteBranding({ selectedSiteUuid, hostname, search, localStorageVal }) {
|
||||
const sandbox = {
|
||||
window: {
|
||||
location: {
|
||||
hostname: hostname || 'localhost',
|
||||
search: search || ''
|
||||
}
|
||||
},
|
||||
localStorage: {
|
||||
getItem: () => localStorageVal || null
|
||||
},
|
||||
console
|
||||
};
|
||||
vm.createContext(sandbox);
|
||||
vm.runInContext(code, sandbox);
|
||||
return sandbox.getSiteBranding(selectedSiteUuid);
|
||||
}
|
||||
|
||||
try {
|
||||
// Test Case 1: Default branding (no local storage, localhost)
|
||||
const brand1 = runGetSiteBranding({
|
||||
hostname: 'localhost'
|
||||
});
|
||||
assert('Default branding should be BackOne', brand1.name === 'BackOne' && brand1.logo === '/backone-logo.png');
|
||||
|
||||
// Test Case 2: SIAB site UUID passed explicitly on demoplace.my.id
|
||||
const brand2 = runGetSiteBranding({
|
||||
selectedSiteUuid: '6681452d_9cae_4ff4_8ae8_0d504774265e',
|
||||
hostname: 'demoplace.my.id'
|
||||
});
|
||||
assert('SIAB site UUID on demoplace.my.id should return BackOne branding', brand2.name === 'BackOne' && brand2.logo === '/backone-logo.png');
|
||||
|
||||
// Test Case 3: SIAB site UUID in localStorage on demoplace.my.id
|
||||
const brand3 = runGetSiteBranding({
|
||||
localStorageVal: '6681452d_9cae_4ff4_8ae8_0d504774265e',
|
||||
hostname: 'demoplace.my.id'
|
||||
});
|
||||
assert('SIAB site UUID in localStorage on demoplace.my.id should return BackOne branding', brand3.name === 'BackOne' && brand3.logo === '/backone-logo.png');
|
||||
|
||||
// Test Case 4: Nexus site UUID passed explicitly
|
||||
const brand4 = runGetSiteBranding({
|
||||
selectedSiteUuid: 'd7902405_0dc2_458b_8584_ed4d24b64f24',
|
||||
hostname: 'localhost'
|
||||
});
|
||||
assert('Nexus site UUID should return Nexus branding', brand4.name === 'Nexus' && brand4.logo === '/nexus-logo.png');
|
||||
|
||||
// Test Case 5: Nexus fallback on demoplace.my.id when no site is selected
|
||||
const brand5 = runGetSiteBranding({
|
||||
hostname: 'demoplace.my.id'
|
||||
});
|
||||
assert('Fallback on demoplace.my.id should be Nexus branding', brand5.name === 'Nexus' && brand5.logo === '/nexus-logo.png');
|
||||
|
||||
console.log(`\n=========================================`);
|
||||
console.log(` RESULT: ${passedCount} / ${testCount} tests passed.`);
|
||||
console.log(`=========================================\n`);
|
||||
|
||||
if (passedCount !== testCount) {
|
||||
process.exit(1);
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Test execution failed with error:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// test/check-ip-mongo.js
|
||||
const { MongoClient } = require('mongodb');
|
||||
|
||||
const URI = 'mongodb://backone_user:SusuKudaLiar@103.80.237.29:27017/backone_dpi?authSource=backone_dpi';
|
||||
const URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/backone_dpi';
|
||||
|
||||
async function main() {
|
||||
console.log('Connecting to MongoDB via IP 103.80.237.29...');
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// test/check-logo-size.js
|
||||
const axios = require('axios');
|
||||
|
||||
async function main() {
|
||||
const url = 'https://demoplace.my.id/nexus-logo.png';
|
||||
const res = await axios.head(url);
|
||||
console.log('Remote nexus-logo.png content-length:', res.headers['content-length']);
|
||||
console.log('Remote nexus-logo.png content-type:', res.headers['content-type']);
|
||||
}
|
||||
|
||||
main().catch(err => console.error(err.message));
|
||||
@@ -1,7 +1,7 @@
|
||||
// test/check_prod_after_migration.js
|
||||
const { MongoClient } = require('mongodb');
|
||||
|
||||
const REMOTE_URI = 'mongodb://backone_user:SusuKudaLiar@mongodb.prod.proit.id:27017/backone_dpi?authSource=backone_dpi';
|
||||
const REMOTE_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/backone_dpi';
|
||||
const DB_NAME = 'backone_dpi';
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const { Client } = require('ssh2');
|
||||
|
||||
const SSH = {
|
||||
host: '103.185.47.52',
|
||||
port: 2222,
|
||||
username: 'adminbackend',
|
||||
password: 'htEo7x6LsBQiEHHH',
|
||||
host: process.env.SSH_HOST || '127.0.0.1',
|
||||
port: parseInt(process.env.SSH_PORT || '2222'),
|
||||
username: process.env.SSH_USER || 'adminbackend',
|
||||
password: process.env.SSH_PASSWORD || '',
|
||||
readyTimeout: 60000
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ const mongoose = require('/home/adminbackend/web/demoplace.my.id/public_html/bac
|
||||
|
||||
async function main() {
|
||||
console.log('Remote: Requiring mongoose succeeded. Connecting...');
|
||||
const URI = 'mongodb://backone_user:SusuKudaLiar@103.80.237.29:27017/backone_dpi?authSource=backone_dpi';
|
||||
const URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/backone_dpi';
|
||||
try {
|
||||
await mongoose.connect(URI, {
|
||||
serverSelectionTimeoutMS: 10000,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function main() {
|
||||
console.log('Logging in to remote server...');
|
||||
const loginRes = await axios.post('https://demoplace.my.id/api/auth/login', {
|
||||
username: 'nexus',
|
||||
password: 'nexus'
|
||||
});
|
||||
|
||||
const cookie = loginRes.headers['set-cookie'];
|
||||
console.log('Login successful. Cookies:', cookie);
|
||||
|
||||
console.log('Fetching / (Overview page) with cookie...');
|
||||
const pageRes = await axios.get('https://demoplace.my.id/', {
|
||||
headers: {
|
||||
Cookie: cookie ? cookie.join('; ') : ''
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Page HTTP Status:', pageRes.status);
|
||||
console.log('Page HTML length:', pageRes.data.length);
|
||||
console.log('HTML snippet (first 500 chars):');
|
||||
console.log(pageRes.data.substring(0, 500));
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,30 @@
|
||||
// test/fetch-sidebar-logo.js
|
||||
const axios = require('axios');
|
||||
|
||||
async function main() {
|
||||
console.log('Logging in as nexus...');
|
||||
const loginRes = await axios.post('https://demoplace.my.id/api/auth/login', {
|
||||
username: 'nexus',
|
||||
password: 'nexus'
|
||||
});
|
||||
|
||||
const cookie = loginRes.headers['set-cookie'];
|
||||
const headers = { Cookie: cookie ? cookie.join('; ') : '' };
|
||||
|
||||
console.log('Fetching overview page...');
|
||||
const pageRes = await axios.get('https://demoplace.my.id/', { headers });
|
||||
|
||||
const html = pageRes.data;
|
||||
|
||||
// Find all img tags using a regex
|
||||
const imgRegex = /<img[^>]+src=["']([^"']+)["']/g;
|
||||
let match;
|
||||
console.log('Found image tags in HTML:');
|
||||
while ((match = imgRegex.exec(html)) !== null) {
|
||||
console.log(' - src:', match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Error:', err.message);
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
// test/get_db_date_range.js
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const MONGODB_URI = 'mongodb://backone_user:SusuKudaLiar@mongodb.prod.proit.id:27017/backone_dpi?authSource=backone_dpi';
|
||||
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/backone_dpi';
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const MONGODB_URI = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/backone_dpi";
|
||||
|
||||
async function run() {
|
||||
console.log('Connecting to Production MongoDB...');
|
||||
await mongoose.connect(MONGODB_URI);
|
||||
console.log('Connected.');
|
||||
|
||||
const db = mongoose.connection.db;
|
||||
const agents = await db.collection('agent_registry').find({}).toArray();
|
||||
console.log('Total agents in agent_registry:', agents.length);
|
||||
for (const agent of agents) {
|
||||
console.log(`Agent UUID: ${agent.uuid}, Label: ${agent.label}, Site UUID: ${agent.site_uuid}, Organization: ${agent.organization_uuid}`);
|
||||
}
|
||||
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
|
||||
run().catch(console.error);
|
||||
@@ -0,0 +1,54 @@
|
||||
// test/inspect-production-mongodb.js
|
||||
const mongoose = require('c:/Users/demo/Downloads/Deep Package Inspection/backend/node_modules/mongoose');
|
||||
|
||||
const MONGODB_URI = process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/backone_dpi";
|
||||
|
||||
async function run() {
|
||||
console.log('Connecting to Production MongoDB...');
|
||||
await mongoose.connect(MONGODB_URI);
|
||||
console.log('Connected.');
|
||||
|
||||
const db = mongoose.connection.db;
|
||||
const count = await db.collection('summaries').countDocuments({});
|
||||
console.log('Total summaries documents in DB:', count);
|
||||
|
||||
// Find latest documents
|
||||
console.log('--- LATEST 5 DOCUMENTS ---');
|
||||
const latest = await db.collection('summaries').find({}).sort({ timestamp: -1 }).limit(5).toArray();
|
||||
for (const doc of latest) {
|
||||
console.log(`ID: ${doc._id}, Time: ${doc.timestamp}, Agent: ${doc.agent_uuid}, Site: ${doc.site_uuid}, Down: ${doc.bandwidth_down}, Up: ${doc.bandwidth_up}, Flows: ${doc.active_flows}`);
|
||||
}
|
||||
|
||||
// Find site-level summaries in last 24 hours
|
||||
const twentyFourHoursAgo = new Date(Date.now() - 24 * 3600000);
|
||||
const siteSummaries = await db.collection('summaries').find({
|
||||
agent_uuid: null,
|
||||
timestamp: { $gte: twentyFourHoursAgo }
|
||||
}).toArray();
|
||||
console.log('--- SITE-LEVEL SUMMARIES IN LAST 24 HOURS ---');
|
||||
console.log('Count:', siteSummaries.length);
|
||||
|
||||
const massiveDocs = siteSummaries.filter(d => (d.bandwidth_down || 0) > 1e9);
|
||||
console.log('Number of documents with Down > 1 GB:', massiveDocs.length);
|
||||
for (const doc of massiveDocs.slice(0, 10)) {
|
||||
console.log(`ID: ${doc._id}, Time: ${doc.timestamp}, Down: ${doc.bandwidth_down}`);
|
||||
}
|
||||
|
||||
if (siteSummaries.length > 0) {
|
||||
let sumDown = 0;
|
||||
let sumUp = 0;
|
||||
for (const doc of siteSummaries) {
|
||||
sumDown += (doc.bandwidth_down || 0);
|
||||
sumUp += (doc.bandwidth_up || 0);
|
||||
}
|
||||
console.log(`Total Download (Sum): ${sumDown} bytes (${(sumDown / 1e12).toFixed(2)} TB)`);
|
||||
console.log(`Total Upload (Sum): ${sumUp} bytes (${(sumUp / 1e12).toFixed(2)} TB)`);
|
||||
console.log(`Average Flows: ${siteSummaries[0].active_flows}`);
|
||||
console.log('Sample Document from last 24 hours:');
|
||||
console.log(JSON.stringify(siteSummaries[0], null, 2));
|
||||
}
|
||||
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
|
||||
run().catch(console.error);
|
||||
@@ -0,0 +1,31 @@
|
||||
const mongoose = require('mongoose');
|
||||
const dotenv = require('dotenv');
|
||||
const path = require('path');
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config({ path: path.join(__dirname, '../.env.production') });
|
||||
|
||||
const { Threat, Event } = require('../backend/models/Schemas');
|
||||
|
||||
async function main() {
|
||||
console.log('Connecting to database...');
|
||||
await mongoose.connect(process.env.MONGODB_URI);
|
||||
console.log('Connected!');
|
||||
|
||||
console.log('\n--- RAW THREAT DOCS ---');
|
||||
const threats = await Threat.find().lean();
|
||||
console.log(JSON.stringify(threats, null, 2));
|
||||
|
||||
console.log('\n--- RAW EVENTS (Cybersecurity / High severity) ---');
|
||||
const events = await Event.find({
|
||||
$or: [
|
||||
{ severity: { $in: ['Critical', 'High'] } },
|
||||
{ category_label: 'Cybersecurity' }
|
||||
]
|
||||
}).lean();
|
||||
console.log(JSON.stringify(events, null, 2));
|
||||
|
||||
await mongoose.disconnect();
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,28 @@
|
||||
// test/middleware_verification_test.js
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
|
||||
console.log('=== Running TDD Middleware Verification Test ===');
|
||||
|
||||
try {
|
||||
// 1. Verify src/middleware.ts exists
|
||||
const middlewarePath = path.join(ROOT, 'src', 'middleware.ts');
|
||||
const exists = fs.existsSync(middlewarePath);
|
||||
assert.ok(exists, 'src/middleware.ts must exist');
|
||||
console.log('✓ src/middleware.ts exists');
|
||||
|
||||
// 2. Verify it exports 'middleware' function
|
||||
const content = fs.readFileSync(middlewarePath, 'utf8');
|
||||
assert.ok(content.includes('export function middleware'), 'src/middleware.ts must export function middleware');
|
||||
assert.ok(!content.includes('export function proxy'), 'src/middleware.ts must NOT export function proxy');
|
||||
console.log('✓ src/middleware.ts exports function middleware correctly');
|
||||
|
||||
console.log('=== ALL TESTS PASSED ===');
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('✗ TEST FAILED:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
+3
-8
@@ -61,7 +61,7 @@ async function run() {
|
||||
site_uuid: '6681452d_9cae_4ff4_8ae8_0d504774265e',
|
||||
brand_name: 'SIAB',
|
||||
brand_logo: '/siab-logo.png',
|
||||
footer_copyright: 'PT. SIAB Indonesia',
|
||||
footer_copyright: 'PT. Data Bisnis Solusi',
|
||||
primary_color: '#3B82F6',
|
||||
},
|
||||
{
|
||||
@@ -74,13 +74,8 @@ async function run() {
|
||||
];
|
||||
|
||||
for (const config of defaultConfigs) {
|
||||
const existing = await TenantConfig.findOne({ site_uuid: config.site_uuid });
|
||||
if (!existing) {
|
||||
await TenantConfig.create(config);
|
||||
console.log(`✓ Seeded TenantConfig for: ${config.brand_name}`);
|
||||
} else {
|
||||
console.log(`TenantConfig for ${config.brand_name} already exists`);
|
||||
}
|
||||
await TenantConfig.findOneAndUpdate({ site_uuid: config.site_uuid }, config, { upsert: true });
|
||||
console.log(`✓ Seeded/Updated TenantConfig for: ${config.brand_name}`);
|
||||
}
|
||||
|
||||
// Seed default agent locations
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// test/sftp_manifest_test.js
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
|
||||
console.log('=== Running TDD SFTP Manifest Verification Test ===');
|
||||
|
||||
try {
|
||||
const deployScriptPath = path.join(ROOT, 'scripts', 'deploy-sftp.js');
|
||||
const exists = fs.existsSync(deployScriptPath);
|
||||
assert.ok(exists, 'scripts/deploy-sftp.js must exist');
|
||||
|
||||
const content = fs.readFileSync(deployScriptPath, 'utf8');
|
||||
|
||||
// Verify .next/static is in the upload manifest
|
||||
assert.ok(
|
||||
content.includes("local: '.next/static'") || content.includes('local: ".next/static"'),
|
||||
'scripts/deploy-sftp.js must include local: \'.next/static\' in UPLOAD_MANIFEST'
|
||||
);
|
||||
|
||||
console.log('✓ scripts/deploy-sftp.js includes .next/static in UPLOAD_MANIFEST');
|
||||
console.log('=== ALL TESTS PASSED ===');
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('✗ TEST FAILED:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function main() {
|
||||
console.log('Fetching /login HTML to find all asset paths...');
|
||||
const res = await axios.get('https://demoplace.my.id/login');
|
||||
const html = res.data;
|
||||
|
||||
// Extract all /_next/static/ paths
|
||||
const matches = html.match(/\/(_next|public)\/[a-zA-Z0-9_\-\.\/]+/g) || [];
|
||||
const uniquePaths = [...new Set(matches)];
|
||||
|
||||
console.log(`Found ${uniquePaths.length} unique asset paths to check:`);
|
||||
|
||||
let failed = 0;
|
||||
for (const assetPath of uniquePaths) {
|
||||
const url = `https://demoplace.my.id${assetPath}`;
|
||||
try {
|
||||
const assetRes = await axios.get(url);
|
||||
console.log(`✓ [200 OK] ${assetPath} (${assetRes.headers['content-length'] || assetRes.data.length} bytes)`);
|
||||
} catch (err) {
|
||||
console.error(`✗ [FAIL] ${assetPath}: ${err.message}`);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\n=== Verification Complete: ${uniquePaths.length - failed} passed, ${failed} failed ===`);
|
||||
if (failed > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,35 @@
|
||||
// test/test-data-size-format.js
|
||||
const assert = require('assert');
|
||||
|
||||
function formatDataSize(sizeMB) {
|
||||
let displaySize = "";
|
||||
if (sizeMB >= 1024 * 1024) {
|
||||
displaySize = `${(sizeMB / (1024 * 1024)).toFixed(2)} TB`;
|
||||
} else if (sizeMB >= 1024) {
|
||||
displaySize = `${(sizeMB / 1024).toFixed(2)} GB`;
|
||||
} else {
|
||||
displaySize = `${sizeMB.toFixed(2)} MB`;
|
||||
}
|
||||
return displaySize;
|
||||
}
|
||||
|
||||
try {
|
||||
// Test case 1: Less than 1024 MB
|
||||
assert.strictEqual(formatDataSize(0.38), "0.38 MB");
|
||||
assert.strictEqual(formatDataSize(95.68), "95.68 MB");
|
||||
assert.strictEqual(formatDataSize(999.99), "999.99 MB");
|
||||
|
||||
// Test case 2: Over 1024 MB (GB)
|
||||
assert.strictEqual(formatDataSize(1024), "1.00 GB");
|
||||
assert.strictEqual(formatDataSize(1536), "1.50 GB");
|
||||
assert.strictEqual(formatDataSize(7654.67), "7.48 GB");
|
||||
|
||||
// Test case 3: Over 1024 * 1024 MB (TB)
|
||||
assert.strictEqual(formatDataSize(1048576), "1.00 TB");
|
||||
assert.strictEqual(formatDataSize(1572864), "1.50 TB");
|
||||
|
||||
console.log("✓ All Data Size formatting unit tests passed successfully!");
|
||||
} catch (err) {
|
||||
console.error("✗ Unit tests failed:", err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -3,10 +3,10 @@ const net = require('net');
|
||||
const { MongoClient } = require('mongodb');
|
||||
|
||||
const sshConfig = {
|
||||
host: '103.185.47.52',
|
||||
port: 2222,
|
||||
username: 'adminbackend',
|
||||
password: 'htEo7x6LsBQiEHHH',
|
||||
host: process.env.SSH_HOST || '127.0.0.1',
|
||||
port: parseInt(process.env.SSH_PORT || '2222'),
|
||||
username: process.env.SSH_USER || 'adminbackend',
|
||||
password: process.env.SSH_PASSWORD || '',
|
||||
readyTimeout: 60000
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ conn.on('ready', () => {
|
||||
server.listen(LOCAL_PORT, '127.0.0.1', async () => {
|
||||
console.log(`SSH Tunnel established on port ${LOCAL_PORT}`);
|
||||
try {
|
||||
const REMOTE_URI = `mongodb://backone_user:SusuKudaLiar@127.0.0.1:${LOCAL_PORT}/backone_dpi?authSource=backone_dpi&directConnection=true`;
|
||||
const REMOTE_URI = process.env.MONGODB_URI || `mongodb://backone_user:password@127.0.0.1:${LOCAL_PORT}/backone_dpi?authSource=backone_dpi&directConnection=true`;
|
||||
const client = new MongoClient(REMOTE_URI, { serverSelectionTimeoutMS: 5000 });
|
||||
await client.connect();
|
||||
const db = client.db('backone_dpi');
|
||||
|
||||
@@ -3,10 +3,10 @@ const net = require('net');
|
||||
const { MongoClient } = require('mongodb');
|
||||
|
||||
const sshConfig = {
|
||||
host: '103.185.47.52',
|
||||
port: 2222,
|
||||
username: 'adminbackend',
|
||||
password: 'htEo7x6LsBQiEHHH',
|
||||
host: process.env.SSH_HOST || '127.0.0.1',
|
||||
port: parseInt(process.env.SSH_PORT || '2222'),
|
||||
username: process.env.SSH_USER || 'adminbackend',
|
||||
password: process.env.SSH_PASSWORD || '',
|
||||
readyTimeout: 60000
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ conn.on('ready', () => {
|
||||
server.listen(LOCAL_PORT, '127.0.0.1', async () => {
|
||||
console.log(`SSH Tunnel established on port ${LOCAL_PORT}`);
|
||||
try {
|
||||
const REMOTE_URI = `mongodb://backone_user:SusuKudaLiar@127.0.0.1:${LOCAL_PORT}/backone_dpi?authSource=backone_dpi`;
|
||||
const REMOTE_URI = process.env.MONGODB_URI || `mongodb://backone_user:password@127.0.0.1:${LOCAL_PORT}/backone_dpi?authSource=backone_dpi`;
|
||||
const client = new MongoClient(REMOTE_URI, { serverSelectionTimeoutMS: 5000 });
|
||||
await client.connect();
|
||||
const db = client.db('backone_dpi');
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function main() {
|
||||
console.log('Logging in to remote server...');
|
||||
const loginRes = await axios.post('https://demoplace.my.id/api/auth/login', {
|
||||
username: 'admin',
|
||||
password: 'admin'
|
||||
});
|
||||
|
||||
const cookie = loginRes.headers['set-cookie'];
|
||||
const headers = {
|
||||
Cookie: cookie ? cookie.join('; ') : ''
|
||||
};
|
||||
|
||||
console.log('\n--- API: /api/dashboard/summary ---');
|
||||
try {
|
||||
const res = await axios.get('https://demoplace.my.id/api/dashboard/summary', { headers });
|
||||
console.log(JSON.stringify(res.data, null, 2));
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
|
||||
console.log('\n--- API: /api/dashboard/timeline ---');
|
||||
try {
|
||||
const res = await axios.get('https://demoplace.my.id/api/dashboard/timeline?points=5', { headers });
|
||||
console.log(JSON.stringify(res.data, null, 2));
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,32 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function main() {
|
||||
console.log('Logging in to remote server...');
|
||||
const loginRes = await axios.post('https://demoplace.my.id/api/auth/login', {
|
||||
username: 'admin',
|
||||
password: 'admin'
|
||||
});
|
||||
|
||||
const cookie = loginRes.headers['set-cookie'];
|
||||
const headers = {
|
||||
Cookie: cookie ? cookie.join('; ') : ''
|
||||
};
|
||||
|
||||
console.log('\n--- API: /api/dashboard/threats?timeRange=1d ---');
|
||||
try {
|
||||
const res = await axios.get('https://demoplace.my.id/api/dashboard/threats?timeRange=1d', { headers });
|
||||
console.log(JSON.stringify(res.data, null, 2));
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
|
||||
console.log('\n--- API: /api/dashboard/threats?timeRange=all ---');
|
||||
try {
|
||||
const res = await axios.get('https://demoplace.my.id/api/dashboard/threats?timeRange=all', { headers });
|
||||
console.log(JSON.stringify(res.data, null, 2));
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,53 @@
|
||||
// test/test-site-isolation.js
|
||||
const axios = require('axios');
|
||||
const assert = require('assert');
|
||||
|
||||
async function main() {
|
||||
console.log('=== Running Site Isolation Integration Test ===');
|
||||
|
||||
console.log('1. Logging in as Nexus Tenant Admin...');
|
||||
const loginRes = await axios.post('https://demoplace.my.id/api/auth/login', {
|
||||
username: 'nexus',
|
||||
password: 'nexus'
|
||||
});
|
||||
|
||||
const cookie = loginRes.headers['set-cookie'];
|
||||
const headers = { Cookie: cookie ? cookie.join('; ') : '' };
|
||||
|
||||
console.log('2. Fetching /api/dashboard/agents/uptime...');
|
||||
const uptimeRes = await axios.get('https://demoplace.my.id/api/dashboard/agents/uptime?timeRange=1d', { headers });
|
||||
assert.ok(uptimeRes.data.ok, 'Uptime response must be ok');
|
||||
|
||||
const uptimeKeys = Object.keys(uptimeRes.data.uptime);
|
||||
console.log('Uptime keys returned:', uptimeKeys);
|
||||
|
||||
const siabAgentUuids = ['F6-2V-DT-8A', '2F-TF-1D-GK', 'YW-6I-61-LL', '8A-V3-PB-85', '1R-79-J9-YE'];
|
||||
const nexusAgentUuids = ['1T-5Q-RC-AS', '2N-ID-VQ-AL'];
|
||||
|
||||
for (const uuid of uptimeKeys) {
|
||||
assert.ok(!siabAgentUuids.includes(uuid), `Security violation: SIAB agent ${uuid} leaked to Nexus admin!`);
|
||||
}
|
||||
console.log('✓ No SIAB agent uptimes leaked to Nexus.');
|
||||
|
||||
console.log('3. Fetching /api/dashboard/agents/storage...');
|
||||
const storageRes = await axios.get('https://demoplace.my.id/api/dashboard/agents/storage', { headers });
|
||||
assert.ok(storageRes.data.ok, 'Storage response must be ok');
|
||||
|
||||
const storageKeys = Object.keys(storageRes.data.storage);
|
||||
console.log('Storage keys returned:', storageKeys);
|
||||
|
||||
for (const uuid of storageKeys) {
|
||||
assert.ok(!siabAgentUuids.includes(uuid), `Security violation: SIAB agent storage ${uuid} leaked to Nexus admin!`);
|
||||
}
|
||||
console.log('✓ No SIAB agent storage sizes leaked to Nexus.');
|
||||
|
||||
console.log('=== SITE ISOLATION TEST PASSED SUCCESSFULY ===');
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('✗ TEST FAILED:', err.message);
|
||||
if (err.response) {
|
||||
console.error('Response data:', err.response.data);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -4,10 +4,10 @@ const net = require('net');
|
||||
const { MongoClient } = require('mongodb');
|
||||
|
||||
const sshConfig = {
|
||||
host: '103.185.47.52',
|
||||
port: 2222,
|
||||
username: 'adminbackend',
|
||||
password: 'htEo7x6LsBQiEHHH',
|
||||
host: process.env.SSH_HOST || '127.0.0.1',
|
||||
port: parseInt(process.env.SSH_PORT || '2222'),
|
||||
username: process.env.SSH_USER || 'adminbackend',
|
||||
password: process.env.SSH_PASSWORD || '',
|
||||
readyTimeout: 60000
|
||||
};
|
||||
|
||||
@@ -52,7 +52,7 @@ conn.on('ready', () => {
|
||||
|
||||
async function runMigration() {
|
||||
const LOCAL_URI = 'mongodb://127.0.0.1:27017';
|
||||
const REMOTE_URI = `mongodb://backone_user:SusuKudaLiar@127.0.0.1:${LOCAL_PORT}/backone_dpi?authSource=backone_dpi`;
|
||||
const REMOTE_URI = process.env.MONGODB_URI || `mongodb://backone_user:password@127.0.0.1:${LOCAL_PORT}/backone_dpi?authSource=backone_dpi`;
|
||||
const DB_NAME = 'backone_dpi';
|
||||
|
||||
console.log("Connecting to local MongoDB...");
|
||||
|
||||
Reference in new issue
Block a user