207 lines
4.4 KiB
JavaScript
207 lines
4.4 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Assets = db.assets;
|
|
|
|
const ComplianceReports = db.compliance_reports;
|
|
|
|
const Vulnerabilities = db.vulnerabilities;
|
|
|
|
const AssetsData = [
|
|
{
|
|
name: 'Web Server',
|
|
|
|
type: 'Linux Server',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Database Server',
|
|
|
|
type: 'PostgreSQL',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Application Server',
|
|
|
|
type: 'Java Application',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'File Server',
|
|
|
|
type: 'Windows Server',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const ComplianceReportsData = [
|
|
{
|
|
report_name: 'Q3 Security Audit',
|
|
|
|
generated_on: new Date('2023-10-05T12:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
report_name: 'Annual Compliance Review',
|
|
|
|
generated_on: new Date('2023-09-01T09:00:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
report_name: 'Monthly Vulnerability Report',
|
|
|
|
generated_on: new Date('2023-08-15T15:30:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
report_name: 'Penetration Test Results',
|
|
|
|
generated_on: new Date('2023-07-20T10:45:00Z'),
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const VulnerabilitiesData = [
|
|
{
|
|
title: 'SQL Injection',
|
|
|
|
description: 'SQL injection vulnerability in login form',
|
|
|
|
severity: 'Low',
|
|
|
|
discovered_on: new Date('2023-10-01T10:00:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Cross-Site Scripting',
|
|
|
|
description: 'XSS vulnerability in user comments',
|
|
|
|
severity: 'Medium',
|
|
|
|
discovered_on: new Date('2023-09-15T14:30:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Buffer Overflow',
|
|
|
|
description: 'Buffer overflow in image processing module',
|
|
|
|
severity: 'Medium',
|
|
|
|
discovered_on: new Date('2023-08-20T09:45:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Insecure Deserialization',
|
|
|
|
description: 'Insecure deserialization in API endpoint',
|
|
|
|
severity: 'Critical',
|
|
|
|
discovered_on: new Date('2023-07-10T11:15:00Z'),
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateVulnerabilityWithReported_by() {
|
|
const relatedReported_by0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Vulnerability0 = await Vulnerabilities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Vulnerability0?.setReported_by) {
|
|
await Vulnerability0.setReported_by(relatedReported_by0);
|
|
}
|
|
|
|
const relatedReported_by1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Vulnerability1 = await Vulnerabilities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Vulnerability1?.setReported_by) {
|
|
await Vulnerability1.setReported_by(relatedReported_by1);
|
|
}
|
|
|
|
const relatedReported_by2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Vulnerability2 = await Vulnerabilities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Vulnerability2?.setReported_by) {
|
|
await Vulnerability2.setReported_by(relatedReported_by2);
|
|
}
|
|
|
|
const relatedReported_by3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Vulnerability3 = await Vulnerabilities.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Vulnerability3?.setReported_by) {
|
|
await Vulnerability3.setReported_by(relatedReported_by3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Assets.bulkCreate(AssetsData);
|
|
|
|
await ComplianceReports.bulkCreate(ComplianceReportsData);
|
|
|
|
await Vulnerabilities.bulkCreate(VulnerabilitiesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateVulnerabilityWithReported_by(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('assets', null, {});
|
|
|
|
await queryInterface.bulkDelete('compliance_reports', null, {});
|
|
|
|
await queryInterface.bulkDelete('vulnerabilities', null, {});
|
|
},
|
|
};
|