Skip to content

Instantly share code, notes, and snippets.

@jamessom
Created April 3, 2018 20:44
Show Gist options
  • Save jamessom/bbda4df3965cfb38c10d5aa4cfa8711b to your computer and use it in GitHub Desktop.
Save jamessom/bbda4df3965cfb38c10d5aa4cfa8711b to your computer and use it in GitHub Desktop.
Generating fake data with Faker.js
var faker = require('faker');
var uuidV4 = require('uuid/v4');
var log = {
"v": "1.0",
"category": "ERRORLOG",
"level": "INFO",
"timestamp": "2016-11-04T22:02:02.365Z",
"application": {
"name": "My Fav application",
"version": "1.0.0-SNAPSHOT",
"thread": "default task-16",
"component": "com.AuditLogInterceptor"
},
"context": {
"tenantId": "saml-demo",
"principalId": "griduser",
"userGuid" : "c92c7642-777a-41a2-87d6-79a8acec1d7f",
"sessionId": "123456789",
"globalAccessId": "593b740b-d53e-490a-b5d1-fb3fa2fc1c4c",
"policyId": "c92c7642-777a-41a2-87d6-79a8acec1d7f",
"policyName": "Default",
"scenarioId": "0011c00d-b48b-b82c-4a66-1d394b64ff67",
"scenarioName": "trusted network",
"applicationId" : "c92c7642-777a-41a2-87d6-79a8acec1d7f",
"applicationName" : "Office 365",
},
"details": {
"type": "ACCESS REQUEST",
"state": "",
"action" : "",
"credentials" : [
{
type: "OTP",
state: ""
},
{
type: "Password",
state: ""
}
]
}
}
var state = ["Initiated", "Accepted", "Denied" ,"Waiting"];
var action = ["auth", "change password", "push", "restart"];
var cred_state = ["Pending", "VerifiedInSession","Verified" ];
function genlog() {
log.timestamp = faker.date.recent();
log.context.tenantId = faker.company.companyName().replace(/\s+/g, ''); //remove space in name
log.context.principalId = faker.internet.userName();
log.context.userGuid = uuidV4(); //generate guid
log.context.sessionId = uuidV4();
log.context.globalAccessId = uuidV4();
log.context.policyId = uuidV4();
log.context.policyName = faker.commerce.productName();
log.context.scenarioId = uuidV4();
log.context.scenarioName = faker.commerce.productName();
log.context.applicationId = uuidV4();
log.context.applicationName = faker.commerce.productName();
var state_randon = faker.random.number({min:0, max:state.length});
var action_random = faker.random.number({min:0, max:action.length});
var cred_random = faker.random.number({min:0, max:cred_state.length});
var cred_random2 = faker.random.number({min:0, max:cred_state.length});
log.details.state = state[state_randon];
log.details.action = action[action_random];
log.details.credentials[0].state = cred_state[cred_random];
log.details.credentials[1].state = cred_state[cred_random2];
console.log("%j", log);
}
genlog();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment