greybel-mock-environment 2.4.32 → 2.4.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import NetworkGenerator from './generators/network';
5
5
  import UserGenerator from './generators/user';
6
6
  import VulnerabilityGenerator from './generators/vulnerability';
7
7
  import { Computer, Device, EMail, LibraryManager, Location, Port, Router, Session, Switch } from './types';
8
+ import { PasswordManager, PasswordObject } from './types/password-object';
8
9
  export interface RouterLocation {
9
10
  distance: number;
10
11
  percentage: number;
@@ -12,7 +13,7 @@ export interface RouterLocation {
12
13
  }
13
14
  export declare type InitalUserCredentials = {
14
15
  username: string;
15
- password: string;
16
+ password: PasswordObject;
16
17
  };
17
18
  export interface MockEnvironmentOptions {
18
19
  seed?: string;
@@ -21,6 +22,7 @@ export interface MockEnvironmentOptions {
21
22
  }
22
23
  export default class MockEnvironment {
23
24
  readonly WIFI_MAX_DISTANCE: number;
25
+ passwordManager: PasswordManager;
24
26
  seed: string;
25
27
  basicGenerator: BasicGenerator;
26
28
  emailGenerator: EmailGenerator;
@@ -37,15 +37,17 @@ var network_1 = __importDefault(require("./generators/network"));
37
37
  var user_1 = __importDefault(require("./generators/user"));
38
38
  var vulnerability_1 = __importDefault(require("./generators/vulnerability"));
39
39
  var types_1 = require("./types");
40
+ var password_object_1 = require("./types/password-object");
40
41
  var utils_1 = require("./utils");
41
42
  var MockEnvironment = /** @class */ (function () {
42
43
  function MockEnvironment(options) {
43
44
  this.WIFI_MAX_DISTANCE = 10;
45
+ this.passwordManager = password_object_1.PasswordManager.singleton;
44
46
  var me = this;
45
47
  var seed = options.seed || 'test';
46
48
  var initalUser = options.localUser || {
47
49
  username: 'test',
48
- password: 'test'
50
+ password: password_object_1.PasswordManager.create('test')
49
51
  };
50
52
  me.libraryManager = new types_1.LibraryManager();
51
53
  me.seed = seed;
@@ -107,7 +109,7 @@ var MockEnvironment = /** @class */ (function () {
107
109
  var username = _a.username, password = _a.password;
108
110
  var me = this;
109
111
  var user = me.userGenerator.generate(username, password);
110
- var computer = me.networkGenerator.generateLocalComputer([user], 'test');
112
+ var computer = me.networkGenerator.generateLocalComputer([user], password_object_1.PasswordManager.create('test'));
111
113
  var currentPath = computer.getHome(user);
112
114
  var programPath = new types_1.File({
113
115
  name: 'myprogram',
@@ -237,7 +239,7 @@ var MockEnvironment = /** @class */ (function () {
237
239
  MockEnvironment.prototype.getEmailViaLogin = function (email, password) {
238
240
  var me = this;
239
241
  var emails = me.emailGenerator.emails;
240
- return emails.find(function (v) { return v.email === email && v.password === password; });
242
+ return emails.find(function (v) { return v.email === email && v.password.value === password; });
241
243
  };
242
244
  MockEnvironment.prototype.getEmail = function (email) {
243
245
  var me = this;
package/dist/fs.js CHANGED
@@ -111,8 +111,8 @@ function getEtcFiles(options) {
111
111
  permissions: 'rw-r-----',
112
112
  owner: 'root',
113
113
  content: options.users
114
- .map(function (v) { return "".concat(v.username, ":").concat(v.passwordHashed); })
115
- .join('\n'),
114
+ .map(function (v) { return "".concat(v.username, ":").concat(v.password.hashed); })
115
+ .join('\n') + '\n',
116
116
  type: file_system_1.FileType.Source
117
117
  }, options.parent), new file_system_1.File({
118
118
  name: 'xorg.conf',
@@ -1,5 +1,6 @@
1
1
  import { RandomSeed } from 'random-seed';
2
2
  import { Location } from '../types/location';
3
+ import { PasswordObject } from '../types/password-object';
3
4
  import { WordGenerator } from './word-generator';
4
5
  export interface BasicGeneratorOptions {
5
6
  seed: string;
@@ -22,7 +23,7 @@ export default class BasicGenerator {
22
23
  constructor({ seed }: BasicGeneratorOptions);
23
24
  generateDomain(): string;
24
25
  generateUsername(): string;
25
- generatePassword(): string;
26
+ generatePassword(): PasswordObject;
26
27
  generateName(): string;
27
28
  generateBankNumber(): string;
28
29
  generateMAC(): string;
@@ -36,6 +36,7 @@ var passwords_1 = __importDefault(require("../data/passwords"));
36
36
  var surname_1 = __importDefault(require("../data/surname"));
37
37
  var usernames_1 = __importDefault(require("../data/usernames"));
38
38
  var location_1 = require("../types/location");
39
+ var password_object_1 = require("../types/password-object");
39
40
  var utils_1 = require("../utils");
40
41
  var word_generator_1 = require("./word-generator");
41
42
  var BasicGenerator = /** @class */ (function () {
@@ -65,8 +66,8 @@ var BasicGenerator = /** @class */ (function () {
65
66
  return username.toLowerCase();
66
67
  };
67
68
  BasicGenerator.prototype.generatePassword = function () {
68
- var password = this.passwordWordGenerator.next();
69
- return password;
69
+ var value = this.passwordWordGenerator.next();
70
+ return password_object_1.PasswordManager.create(value);
70
71
  };
71
72
  BasicGenerator.prototype.generateName = function () {
72
73
  var me = this;
@@ -1,4 +1,5 @@
1
1
  import { EMail } from '../types';
2
+ import { PasswordObject } from '../types/password-object';
2
3
  import BasicGenerator from './basic';
3
4
  export interface EmailGeneratorOptions {
4
5
  seed: string;
@@ -7,11 +8,11 @@ export interface EmailGeneratorOptions {
7
8
  export interface EmailGenerateOptions {
8
9
  name?: string;
9
10
  domain?: string;
10
- password?: string;
11
+ password?: PasswordObject;
11
12
  }
12
13
  export interface EmailGenerateByEmailOptions {
13
14
  email: string;
14
- password?: string;
15
+ password?: PasswordObject;
15
16
  }
16
17
  export default class EmailGenerator {
17
18
  basicGenerator: BasicGenerator;
@@ -1,6 +1,7 @@
1
1
  import { RandomSeed } from 'random-seed';
2
2
  import { Computer, MetaOwnerLevel, NetworkDevice, Port, Router, Switch, User } from '../types';
3
3
  import { LibraryManager } from '../types/library-manager';
4
+ import { PasswordObject } from '../types/password-object';
4
5
  import { RouterOptions } from '../types/router';
5
6
  import { SwitchOptions } from '../types/switch';
6
7
  import BasicGenerator from './basic';
@@ -26,8 +27,8 @@ export declare class ServerMapGenerator {
26
27
  constructor({ router, networkRng, portRng, basicGenerator, userGenerator, networkGenerator, libraryManager }: ServerMapGeneratorOptions);
27
28
  generateLocalIp(router: Router): string;
28
29
  generateSwitch(options?: Partial<SwitchOptions>): Switch;
29
- generateComputer(router: Router, users: User[], rootPassword?: string): Computer;
30
- generateLocalComputer(users: User[], rootPassword?: string): Computer;
30
+ generateComputer(router: Router, users: User[], rootPassword?: PasswordObject): Computer;
31
+ generateLocalComputer(users: User[], rootPassword?: PasswordObject): Computer;
31
32
  generatePorts(): Map<number, Port>;
32
33
  }
33
34
  export interface NetworkGeneratorOptions {
@@ -48,7 +49,7 @@ export default class NetworkGenerator {
48
49
  constructor({ seed, basicGenerator, userGenerator, emailGenerator, libraryManager }: NetworkGeneratorOptions);
49
50
  generateIp(): string;
50
51
  generateDifficulty(): MetaOwnerLevel;
51
- generateLocalComputer(users: User[], rootPassword?: string): Computer;
52
+ generateLocalComputer(users: User[], rootPassword?: PasswordObject): Computer;
52
53
  generateRouter(options?: Partial<RouterOptions>): Router;
53
54
  generateNetworkDevice(): NetworkDevice;
54
55
  }
@@ -1,4 +1,5 @@
1
1
  import { User } from '../types';
2
+ import { PasswordObject } from '../types/password-object';
2
3
  import BankGenerator from './bank';
3
4
  import BasicGenerator from './basic';
4
5
  import EmailGenerator from './email';
@@ -14,5 +15,5 @@ export default class UserGenerator {
14
15
  bankGenerator: BankGenerator;
15
16
  users: User[];
16
17
  constructor({ basicGenerator, emailGenerator, bankGenerator }: UserGeneratorOptions);
17
- generate(username: string, password: string): User;
18
+ generate(username: string, password: PasswordObject): User;
18
19
  }
@@ -1,10 +1,10 @@
1
+ import { PasswordObject } from './password-object';
1
2
  export interface BankAccountOptions {
2
3
  id: string;
3
- password: string;
4
+ password: PasswordObject;
4
5
  }
5
6
  export declare class BankAccount {
6
7
  id: string;
7
- password: string;
8
- passwordHashed: string;
8
+ password: PasswordObject;
9
9
  constructor(options: BankAccountOptions);
10
10
  }
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.BankAccount = void 0;
7
- var blueimp_md5_1 = __importDefault(require("blueimp-md5"));
8
4
  var BankAccount = /** @class */ (function () {
9
5
  function BankAccount(options) {
10
6
  this.id = options.id;
11
7
  this.password = options.password;
12
- this.passwordHashed = (0, blueimp_md5_1.default)(this.password);
13
8
  }
14
9
  return BankAccount;
15
10
  }());
@@ -5,6 +5,7 @@ import { Location } from './location';
5
5
  import { MetaDeviceType, MetaInfo } from './meta-info';
6
6
  import { NetCard } from './net-card';
7
7
  import { NetworkDevice } from './network-device';
8
+ import { PasswordObject } from './password-object';
8
9
  import { Port } from './port';
9
10
  import { Process, ProcessOptions } from './process';
10
11
  import { Service, ServiceType } from './service';
@@ -48,7 +49,7 @@ export declare class Device {
48
49
  unforward(port: number): boolean;
49
50
  getNetworkDeviceMap(): Map<string, NetworkDevice>;
50
51
  findNetworkDevicesByNetCard(netCard: NetCard): NetworkDevice[];
51
- addUser(userName: string, password: string): boolean;
52
+ addUser(userName: string, password: PasswordObject): boolean;
52
53
  removeUser(userName: string): boolean;
53
54
  updatePasswd(): boolean;
54
55
  createUserFolder(userName: string): boolean;
@@ -34,6 +34,7 @@ var file_system_1 = require("./file-system");
34
34
  var library_1 = require("./library");
35
35
  var meta_info_1 = require("./meta-info");
36
36
  var net_card_1 = require("./net-card");
37
+ var password_object_1 = require("./password-object");
37
38
  var port_1 = require("./port");
38
39
  var process_1 = require("./process");
39
40
  var service_1 = require("./service");
@@ -187,8 +188,8 @@ var Device = /** @class */ (function () {
187
188
  permissions: 'rw-r-----',
188
189
  owner: 'root',
189
190
  content: Array.from(this.users.values())
190
- .map(function (v) { return "".concat(v.username, ":").concat(v.passwordHashed); })
191
- .join('\n'),
191
+ .map(function (v) { return "".concat(v.username, ":").concat(v.password.hashed); })
192
+ .join('\n') + '\n',
192
193
  type: file_system_1.FileType.Source
193
194
  });
194
195
  etcFolder.putEntity(file);
@@ -346,7 +347,7 @@ var Device = /** @class */ (function () {
346
347
  }
347
348
  return new user_1.User({
348
349
  username: 'guest',
349
- password: ''
350
+ password: password_object_1.PasswordManager.create('')
350
351
  });
351
352
  };
352
353
  Device.prototype.findPortByService = function (serviceType) {
@@ -396,7 +397,7 @@ var Device = /** @class */ (function () {
396
397
  name: 'Bank.txt',
397
398
  permissions: 'rw-r--r--',
398
399
  owner: user.username,
399
- content: "".concat(user.bankAccount.id, ":").concat(user.bankAccount.passwordHashed),
400
+ content: "".concat(user.bankAccount.id, ":").concat(user.bankAccount.password.hashed),
400
401
  type: file_system_1.FileType.Source
401
402
  });
402
403
  configFolder.putEntity(bankFile);
@@ -415,7 +416,7 @@ var Device = /** @class */ (function () {
415
416
  name: 'Mail.txt',
416
417
  permissions: 'rw-r--r--',
417
418
  owner: user.username,
418
- content: "".concat(user.email.email, ":").concat(user.email.passwordHashed),
419
+ content: "".concat(user.email.email, ":").concat(user.email.password.hashed),
419
420
  type: file_system_1.FileType.Source
420
421
  });
421
422
  configFolder.putEntity(emailFile);
@@ -1,3 +1,4 @@
1
+ import { PasswordObject } from './password-object';
1
2
  export declare class EMailMessage {
2
3
  from: string;
3
4
  subject: string;
@@ -6,13 +7,12 @@ export declare class EMailMessage {
6
7
  }
7
8
  export interface EMailOptions {
8
9
  email: string;
9
- password: string;
10
+ password: PasswordObject;
10
11
  messages?: Map<string, EMailMessage>;
11
12
  }
12
13
  export declare class EMail {
13
14
  email: string;
14
- password: string;
15
- passwordHashed: string;
15
+ password: PasswordObject;
16
16
  messages: Map<string, EMailMessage>;
17
17
  constructor(options: EMailOptions);
18
18
  }
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.EMail = exports.EMailMessage = void 0;
7
- var blueimp_md5_1 = __importDefault(require("blueimp-md5"));
8
4
  var EMailMessage = /** @class */ (function () {
9
5
  function EMailMessage(from, subject, messages) {
10
6
  this.from = from;
@@ -18,7 +14,6 @@ var EMail = /** @class */ (function () {
18
14
  function EMail(options) {
19
15
  this.email = options.email;
20
16
  this.password = options.password;
21
- this.passwordHashed = (0, blueimp_md5_1.default)(options.password);
22
17
  this.messages = options.messages || new Map();
23
18
  }
24
19
  return EMail;
@@ -0,0 +1,13 @@
1
+ export interface PasswordObject {
2
+ value: string;
3
+ hashed: string;
4
+ }
5
+ export declare class PasswordManager {
6
+ private passwordsByValue;
7
+ private passwordsByHash;
8
+ static singleton: PasswordManager;
9
+ static create(password: string): PasswordObject;
10
+ create(password: string): PasswordObject;
11
+ getByValue(password: string): PasswordObject;
12
+ getByHashed(hashed: string): PasswordObject;
13
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PasswordManager = void 0;
7
+ var blueimp_md5_1 = __importDefault(require("blueimp-md5"));
8
+ var PasswordManager = /** @class */ (function () {
9
+ function PasswordManager() {
10
+ this.passwordsByValue = {};
11
+ this.passwordsByHash = {};
12
+ }
13
+ PasswordManager.create = function (password) {
14
+ return PasswordManager.singleton.create(password);
15
+ };
16
+ PasswordManager.prototype.create = function (password) {
17
+ var existingPasswordObj = this.passwordsByValue[password];
18
+ if (existingPasswordObj) {
19
+ return existingPasswordObj;
20
+ }
21
+ var obj = {
22
+ value: password,
23
+ hashed: (0, blueimp_md5_1.default)(password)
24
+ };
25
+ this.passwordsByValue[password] = obj;
26
+ this.passwordsByHash[obj.hashed] = obj;
27
+ return obj;
28
+ };
29
+ PasswordManager.prototype.getByValue = function (password) {
30
+ return this.passwordsByValue[password];
31
+ };
32
+ PasswordManager.prototype.getByHashed = function (hashed) {
33
+ return this.passwordsByHash[hashed];
34
+ };
35
+ PasswordManager.singleton = new PasswordManager();
36
+ return PasswordManager;
37
+ }());
38
+ exports.PasswordManager = PasswordManager;
@@ -1,15 +1,15 @@
1
1
  import { BankAccount } from './bank';
2
2
  import { EMail } from './email';
3
+ import { PasswordObject } from './password-object';
3
4
  export interface UserOptions {
4
5
  username: string;
5
- password: string;
6
+ password: PasswordObject;
6
7
  email?: EMail;
7
8
  bankAccount?: BankAccount;
8
9
  }
9
10
  export declare class User {
10
11
  username: string;
11
- password: string;
12
- passwordHashed: string;
12
+ password: PasswordObject;
13
13
  email: EMail;
14
14
  bankAccount: BankAccount;
15
15
  constructor(options: UserOptions);
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.User = void 0;
7
- var blueimp_md5_1 = __importDefault(require("blueimp-md5"));
4
+ var password_object_1 = require("./password-object");
8
5
  var User = /** @class */ (function () {
9
6
  function User(options) {
10
7
  this.username = options.username;
11
8
  this.password = options.password;
12
- this.passwordHashed = (0, blueimp_md5_1.default)(options.password);
13
9
  this.email = options.email;
14
10
  this.bankAccount = options.bankAccount;
15
11
  }
16
12
  User.prototype.changePassword = function (password) {
17
- this.password = password;
18
- this.passwordHashed = (0, blueimp_md5_1.default)(password);
13
+ this.password = password_object_1.PasswordManager.create(password);
19
14
  };
20
15
  return User;
21
16
  }());
@@ -35,9 +35,7 @@ exports.VersionOptions = VersionOptions;
35
35
  var Version = /** @class */ (function () {
36
36
  function Version(options) {
37
37
  if (options === void 0) { options = {}; }
38
- this.version = options.version
39
- ? Version.parse(options.version)
40
- : [1, 0, 0];
38
+ this.version = options.version ? Version.parse(options.version) : [1, 0, 0];
41
39
  }
42
40
  Version.parse = function (version) {
43
41
  if (/^([0-9]+\.){2}[0-9]+$/.test(version)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-mock-environment",
3
- "version": "2.4.32",
3
+ "version": "2.4.34",
4
4
  "description": "Mock environment",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -49,7 +49,7 @@
49
49
  "dependencies": {
50
50
  "@types/random-seed": "^0.3.3",
51
51
  "blueimp-md5": "^2.19.0",
52
- "greyscript-core": "~2.5.1",
52
+ "greyscript-core": "~2.5.2",
53
53
  "random-seed": "^0.3.0",
54
54
  "random-username-generator": "^1.0.4"
55
55
  }