|
|
@ -415,6 +415,121 @@ async function saveLargeObject(obj, filename) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function realPayloadGenerator(preferedPayload={},user,{restricted=false,workingTimeLimit=true,canRefreshSession=true,passwordLogin=true,otpLogin=true}={}) { |
|
|
|
|
|
|
|
user = user || await createUser(); |
|
|
|
|
|
|
|
const roleId = preferedPayload?.roleId || 23; |
|
|
|
|
|
|
|
const networkId = preferedPayload?.networkId || 10001; |
|
|
|
|
|
|
|
let network = await db.network.findByPk(networkId,{ |
|
|
|
|
|
|
|
raw:true, |
|
|
|
|
|
|
|
paranoid:false |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!network) { |
|
|
|
|
|
|
|
network = await db.network.create({ |
|
|
|
|
|
|
|
id: networkId, |
|
|
|
|
|
|
|
name: `GodNetwork${networkId}`, |
|
|
|
|
|
|
|
level: preferedPayload?.level || 1, |
|
|
|
|
|
|
|
[`level${preferedPayload?.level || 1}Id`]:networkId, |
|
|
|
|
|
|
|
siamId: uuidv4() |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let role = await db.role.findByPk(roleId,{ |
|
|
|
|
|
|
|
raw:true, |
|
|
|
|
|
|
|
paranoid:false |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!role) { |
|
|
|
|
|
|
|
role = await db.role.create({ |
|
|
|
|
|
|
|
id: roleId, |
|
|
|
|
|
|
|
name: `GodRole ${roleId}`, |
|
|
|
|
|
|
|
description: `Test Role ${roleId} Description`, |
|
|
|
|
|
|
|
workingTimeLimit, |
|
|
|
|
|
|
|
canRefreshSession, |
|
|
|
|
|
|
|
passwordLogin, |
|
|
|
|
|
|
|
otpLogin, |
|
|
|
|
|
|
|
restricted |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let position = await db.position.create({ |
|
|
|
|
|
|
|
name: "Test Position 1", |
|
|
|
|
|
|
|
description: "Test Position 1 With 1 Max User", |
|
|
|
|
|
|
|
maxUsers: preferedPayload?.maxUsers || 1, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let userRole = await db.userRole.create({ |
|
|
|
|
|
|
|
id: -getRandomNumber(1e7, 1e8-1), |
|
|
|
|
|
|
|
userId: user.id, |
|
|
|
|
|
|
|
roleId: role.id, |
|
|
|
|
|
|
|
networkId: network.id, |
|
|
|
|
|
|
|
positionId: position.id, |
|
|
|
|
|
|
|
description: `Test UserRole ${user.id} Description`, |
|
|
|
|
|
|
|
expirationTime:preferedPayload?.expirationTime || null, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let networkPosition = await db.networkPosition.create({ |
|
|
|
|
|
|
|
networkId: +await network.id, |
|
|
|
|
|
|
|
positionId: +await position.id, |
|
|
|
|
|
|
|
level: +await network.level |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let positionRole = await db.positionRole.create({ |
|
|
|
|
|
|
|
roleId: role.id, |
|
|
|
|
|
|
|
positionId: position.id, |
|
|
|
|
|
|
|
level: +await network.level |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
payload:{ |
|
|
|
|
|
|
|
username: user.username, |
|
|
|
|
|
|
|
userId: user.id.toString(), |
|
|
|
|
|
|
|
userRoleId: userRole.id.toString(), |
|
|
|
|
|
|
|
networkId: network.id.toString(), |
|
|
|
|
|
|
|
level:+network.level, |
|
|
|
|
|
|
|
roleId:role.id.toString(), |
|
|
|
|
|
|
|
include:[], |
|
|
|
|
|
|
|
exclude:[], |
|
|
|
|
|
|
|
positionId: position.id.toString(), |
|
|
|
|
|
|
|
timestamp: Date.now(), |
|
|
|
|
|
|
|
jwtId: getRandomNumber(1, 1e3), |
|
|
|
|
|
|
|
ip:getRandomIp(), |
|
|
|
|
|
|
|
agent:null, |
|
|
|
|
|
|
|
...preferedPayload |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
network, |
|
|
|
|
|
|
|
role, |
|
|
|
|
|
|
|
position, |
|
|
|
|
|
|
|
userRole, |
|
|
|
|
|
|
|
user, |
|
|
|
|
|
|
|
networkPosition, |
|
|
|
|
|
|
|
positionRole |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const hash = (data) => |
|
|
|
|
|
|
|
crypto.createHash("sha256").update(JSON.stringify(data)).digest("hex"); |
|
|
|
|
|
|
|
async function createUser(data){ |
|
|
|
|
|
|
|
const newUser = await db.user.create({ |
|
|
|
|
|
|
|
firstName: `createUserTestName${getRandomNumber(1, 1e3)}`, |
|
|
|
|
|
|
|
lastName: `createUserTestLastName${getRandomNumber(1, 1e3)}`, |
|
|
|
|
|
|
|
nationalId: getRandomNumber(1e9, 9e9).toString(), |
|
|
|
|
|
|
|
username: `baseuser${getRandomNumber(1e6, 1e9-1)}`, |
|
|
|
|
|
|
|
cellphone: `0965${getRandomNumber(1e6, 9e6)}`, |
|
|
|
|
|
|
|
password: await bcrypt.hash("Password@123",10), |
|
|
|
|
|
|
|
hash:hash("Password@123"), |
|
|
|
|
|
|
|
status: 0, |
|
|
|
|
|
|
|
consecutiveLoginFailures:0, |
|
|
|
|
|
|
|
birthDate:`${getRandomNumber(1350, 1400)}/${getRandomNumber(1, 12)}/${getRandomNumber(1, 31)}`, |
|
|
|
|
|
|
|
...data |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return newUser; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getRandomIp(){ |
|
|
|
|
|
|
|
return `${getRandomNumber(1, 254)}.${getRandomNumber(1, 254)}.${getRandomNumber(1, 254)}.${getRandomNumber(1, 254)}`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
|
module.exports = { |
|
|
|
sleep, |
|
|
|
sleep, |
|
|
|
convertStringToJson, |
|
|
|
convertStringToJson, |
|
|
@ -429,5 +544,9 @@ module.exports = { |
|
|
|
checkingConditionTypes, |
|
|
|
checkingConditionTypes, |
|
|
|
checkingOptions, |
|
|
|
checkingOptions, |
|
|
|
checkCondition, |
|
|
|
checkCondition, |
|
|
|
saveLargeObject |
|
|
|
saveLargeObject, |
|
|
|
|
|
|
|
realPayloadGenerator, |
|
|
|
|
|
|
|
hash, |
|
|
|
|
|
|
|
createUser, |
|
|
|
|
|
|
|
getRandomIp |
|
|
|
} |
|
|
|
} |