greybel-mock-environment 1.4.1 → 1.4.3

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.
@@ -10,6 +10,15 @@ export interface RouterLocation {
10
10
  percentage: number;
11
11
  router: Router;
12
12
  }
13
+ export declare type InitalUserCredentials = {
14
+ username: string;
15
+ password: string;
16
+ };
17
+ export interface MockEnvironmentOptions {
18
+ seed?: string;
19
+ localUser?: InitalUserCredentials;
20
+ myProgramContent?: string;
21
+ }
13
22
  export default class MockEnvironment {
14
23
  readonly WIFI_MAX_DISTANCE: number;
15
24
  seed: string;
@@ -22,10 +31,7 @@ export default class MockEnvironment {
22
31
  sessions: Session[];
23
32
  localSession: Session;
24
33
  libraryManager: LibraryManager;
25
- constructor(seed: string, localUser: {
26
- username: string;
27
- password: string;
28
- });
34
+ constructor(options: MockEnvironmentOptions);
29
35
  getComputerInLan(ipAddress: string, router: Router): Computer | null;
30
36
  getComputersOfRouter(router: Router): Computer[];
31
37
  getPortsOfRouter(router: Router): Port[];
@@ -33,7 +39,7 @@ export default class MockEnvironment {
33
39
  port: Port;
34
40
  computer: Computer;
35
41
  } | null;
36
- setupLocalSession(username: string, password: string): void;
42
+ setupLocalSession({ username, password }: InitalUserCredentials, myProgramContent?: string): void;
37
43
  getLatestSession(): Session;
38
44
  getLocal(): Session;
39
45
  connect(router: Router, device: Device): void;
@@ -39,10 +39,14 @@ var vulnerability_1 = __importDefault(require("./generators/vulnerability"));
39
39
  var types_1 = require("./types");
40
40
  var utils_1 = require("./utils");
41
41
  var MockEnvironment = /** @class */ (function () {
42
- function MockEnvironment(seed, localUser) {
43
- if (seed === void 0) { seed = 'test'; }
42
+ function MockEnvironment(options) {
44
43
  this.WIFI_MAX_DISTANCE = 10;
45
44
  var me = this;
45
+ var seed = options.seed || 'test';
46
+ var initalUser = options.localUser || {
47
+ username: 'test',
48
+ password: 'test'
49
+ };
46
50
  me.libraryManager = new types_1.LibraryManager();
47
51
  me.seed = seed;
48
52
  me.basicGenerator = new basic_1.default({ seed: seed });
@@ -73,7 +77,7 @@ var MockEnvironment = /** @class */ (function () {
73
77
  libraryManager: me.libraryManager
74
78
  });
75
79
  me.sessions = [];
76
- me.setupLocalSession(localUser.username, localUser.password);
80
+ me.setupLocalSession(initalUser, options.myProgramContent);
77
81
  }
78
82
  MockEnvironment.prototype.getComputerInLan = function (ipAddress, router) {
79
83
  var me = this;
@@ -99,17 +103,19 @@ var MockEnvironment = /** @class */ (function () {
99
103
  port: computer.ports.get(port)
100
104
  };
101
105
  };
102
- MockEnvironment.prototype.setupLocalSession = function (username, password) {
106
+ MockEnvironment.prototype.setupLocalSession = function (_a, myProgramContent) {
107
+ var username = _a.username, password = _a.password;
103
108
  var me = this;
104
109
  var user = me.userGenerator.generate(username, password);
105
110
  var computer = me.networkGenerator.generateLocalComputer([user], 'test');
106
111
  var currentPath = computer.getHome(user);
107
112
  var programPath = new types_1.File({
108
- name: 'myprogramm',
109
- permissions: '----------',
113
+ name: 'myprogram',
114
+ permissions: '---------',
110
115
  owner: 'root',
111
116
  isProtected: true,
112
- type: types_1.FileType.Binary
117
+ type: types_1.FileType.Binary,
118
+ content: myProgramContent
113
119
  });
114
120
  currentPath.putEntity(programPath);
115
121
  me.localSession = new types_1.Session({
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { default as MockEnvironment, RouterLocation } from './environment';
1
+ export { default as MockEnvironment, RouterLocation, InitalUserCredentials, MockEnvironmentOptions } from './environment';
2
2
  export * as FS from './fs';
3
3
  export * as Generators from './generators';
4
4
  export { default as MockTranspiler } from './mock-transpiler';
@@ -179,7 +179,7 @@ var Device = /** @class */ (function () {
179
179
  if (etcFolder instanceof file_system_1.Folder) {
180
180
  var file = new file_system_1.File({
181
181
  name: 'passwd',
182
- permissions: '-rw-r-----',
182
+ permissions: 'rw-r-----',
183
183
  owner: 'root',
184
184
  content: Array.from(this.users.values())
185
185
  .map(function (v) { return "".concat(v.username, ":").concat(v.passwordHashed); })
@@ -388,7 +388,7 @@ var Device = /** @class */ (function () {
388
388
  var configFolder = homeFolder.folders.get('Config');
389
389
  var bankFile = new file_system_1.File({
390
390
  name: 'Bank.txt',
391
- permissions: '-rw-r--r--',
391
+ permissions: 'rw-r--r--',
392
392
  owner: user.username,
393
393
  content: "".concat(user.bankAccount.id, ":").concat(user.bankAccount.passwordHashed),
394
394
  type: file_system_1.FileType.Source
@@ -407,7 +407,7 @@ var Device = /** @class */ (function () {
407
407
  var configFolder = homeFolder.folders.get('Config');
408
408
  var emailFile = new file_system_1.File({
409
409
  name: 'Mail.txt',
410
- permissions: '-rw-r--r--',
410
+ permissions: 'rw-r--r--',
411
411
  owner: user.username,
412
412
  content: "".concat(user.email.email, ":").concat(user.email.passwordHashed),
413
413
  type: file_system_1.FileType.Source
@@ -484,7 +484,7 @@ var Device = /** @class */ (function () {
484
484
  if (libFolder instanceof file_system_1.Folder) {
485
485
  libFile = new file_system_1.File({
486
486
  name: 'libssh.so',
487
- permissions: '-rw-r--r--',
487
+ permissions: 'rw-r--r--',
488
488
  owner: 'root',
489
489
  type: file_system_1.FileType.SSH,
490
490
  version: libManager.getLatestVersion(library_1.Library.SSH).toString()
@@ -497,7 +497,7 @@ var Device = /** @class */ (function () {
497
497
  if (configFolder instanceof file_system_1.Folder) {
498
498
  configFile = new file_system_1.File({
499
499
  name: 'sshd.conf',
500
- permissions: '-rw-r--r--',
500
+ permissions: 'rw-r--r--',
501
501
  owner: 'root',
502
502
  content: JSON.stringify({
503
503
  encryption_enabled: false,
@@ -525,7 +525,7 @@ var Device = /** @class */ (function () {
525
525
  if (libFolder instanceof file_system_1.Folder) {
526
526
  libFile = new file_system_1.File({
527
527
  name: 'libftp.so',
528
- permissions: '-rw-r--r--',
528
+ permissions: 'rw-r--r--',
529
529
  owner: 'root',
530
530
  type: file_system_1.FileType.FTP,
531
531
  version: libManager.getLatestVersion(library_1.Library.FTP).toString()
@@ -538,7 +538,7 @@ var Device = /** @class */ (function () {
538
538
  if (configFolder instanceof file_system_1.Folder) {
539
539
  configFile = new file_system_1.File({
540
540
  name: 'ftpd.conf',
541
- permissions: '-rw-r--r--',
541
+ permissions: 'rw-r--r--',
542
542
  owner: 'root',
543
543
  type: file_system_1.FileType.Source
544
544
  });
@@ -561,7 +561,7 @@ var Device = /** @class */ (function () {
561
561
  if (libFolder instanceof file_system_1.Folder) {
562
562
  libFile = new file_system_1.File({
563
563
  name: 'libhttp.so',
564
- permissions: '-rw-r--r--',
564
+ permissions: 'rw-r--r--',
565
565
  owner: 'root',
566
566
  type: file_system_1.FileType.HTTP,
567
567
  version: libManager.getLatestVersion(library_1.Library.HTTP).toString()
@@ -574,7 +574,7 @@ var Device = /** @class */ (function () {
574
574
  if (configFolder instanceof file_system_1.Folder) {
575
575
  configFile = new file_system_1.File({
576
576
  name: 'httpd.conf',
577
- permissions: '-rw-r--r--',
577
+ permissions: 'rw-r--r--',
578
578
  owner: 'root',
579
579
  type: file_system_1.FileType.Source
580
580
  });
@@ -585,7 +585,7 @@ var Device = /** @class */ (function () {
585
585
  if (!publicFolder) {
586
586
  publicFolder = new file_system_1.Folder({
587
587
  name: 'Public',
588
- permissions: '-rw-r--r--',
588
+ permissions: 'rw-r--r--',
589
589
  owner: 'root'
590
590
  });
591
591
  }
@@ -594,7 +594,7 @@ var Device = /** @class */ (function () {
594
594
  if (!dlFolder) {
595
595
  dlFolder = new file_system_1.Folder({
596
596
  name: 'Downloads',
597
- permissions: '-rw-r--r--',
597
+ permissions: 'rw-r--r--',
598
598
  owner: 'root'
599
599
  });
600
600
  publicFolder.putEntity(dlFolder);
@@ -604,7 +604,7 @@ var Device = /** @class */ (function () {
604
604
  if (!htDocsFolder) {
605
605
  htDocsFolder = new file_system_1.Folder({
606
606
  name: 'htdocs',
607
- permissions: '-rw-r--r--',
607
+ permissions: 'rw-r--r--',
608
608
  owner: 'root'
609
609
  });
610
610
  publicFolder.putEntity(htDocsFolder);
@@ -614,7 +614,7 @@ var Device = /** @class */ (function () {
614
614
  if (!htDocsDownloadFolder) {
615
615
  htDocsDownloadFolder = new file_system_1.Folder({
616
616
  name: 'downloads',
617
- permissions: '-rw-r--r--',
617
+ permissions: 'rw-r--r--',
618
618
  owner: 'root'
619
619
  });
620
620
  htDocsFolder.putEntity(htDocsDownloadFolder);
@@ -628,7 +628,7 @@ var Device = /** @class */ (function () {
628
628
  if (!htDocsWebsiteFile) {
629
629
  htDocsWebsiteFile = new file_system_1.File({
630
630
  name: 'website.html',
631
- permissions: '-rw-r--r--',
631
+ permissions: 'rw-r--r--',
632
632
  owner: 'root',
633
633
  content: "<!doctype html>\n <title>Site Maintenance</title>\n <style>\n body { text-align: center; padding: 25px; }\n h1 { font-size: 50px; }\n body { font: 20px Helvetica, sans-serif; color: #333; }\n article { display: block; text-align: left; width: 650px; margin: 0 auto; }\n html{\n background-color: whitesmoke;\n height:100%;\n }\n </style>\n <article>\n <h1>We will be back soon!</h1>\n <div>\n <p>Sorry for the inconvenience but we are performing some maintenance at the moment. We will be back online shortly!</p>\n <p>The Team</p>\n </div>\n </article>",
634
634
  type: file_system_1.FileType.Source
@@ -652,7 +652,7 @@ var Device = /** @class */ (function () {
652
652
  if (libFolder instanceof file_system_1.Folder) {
653
653
  libFile = new file_system_1.File({
654
654
  name: 'librshell.so',
655
- permissions: '-rw-r--r--',
655
+ permissions: 'rw-r--r--',
656
656
  owner: 'root',
657
657
  type: file_system_1.FileType.RShell,
658
658
  version: libManager.getLatestVersion(library_1.Library.RSHELL).toString()
@@ -665,7 +665,7 @@ var Device = /** @class */ (function () {
665
665
  if (configFolder instanceof file_system_1.Folder) {
666
666
  configFile = new file_system_1.File({
667
667
  name: 'rshelld.conf',
668
- permissions: '-rw-r--r--',
668
+ permissions: 'rw-r--r--',
669
669
  owner: 'root',
670
670
  type: file_system_1.FileType.Source
671
671
  });
@@ -687,7 +687,7 @@ var Device = /** @class */ (function () {
687
687
  if (libFolder instanceof file_system_1.Folder) {
688
688
  libFile = new file_system_1.File({
689
689
  name: 'libchat.so',
690
- permissions: '-rw-r--r--',
690
+ permissions: 'rw-r--r--',
691
691
  owner: 'root',
692
692
  type: file_system_1.FileType.Chat,
693
693
  version: libManager.getLatestVersion(library_1.Library.CHAT).toString()
@@ -700,7 +700,7 @@ var Device = /** @class */ (function () {
700
700
  if (configFolder instanceof file_system_1.Folder) {
701
701
  configFile = new file_system_1.File({
702
702
  name: 'chatd.conf',
703
- permissions: '-rw-r--r--',
703
+ permissions: 'rw-r--r--',
704
704
  owner: 'root',
705
705
  type: file_system_1.FileType.Source
706
706
  });
@@ -722,7 +722,7 @@ var Device = /** @class */ (function () {
722
722
  if (libFolder instanceof file_system_1.Folder) {
723
723
  libFile = new file_system_1.File({
724
724
  name: 'librepository.so',
725
- permissions: '-rw-r--r--',
725
+ permissions: 'rw-r--r--',
726
726
  owner: 'root',
727
727
  type: file_system_1.FileType.Repository,
728
728
  version: libManager.getLatestVersion(library_1.Library.REPOSITORY).toString()
@@ -735,7 +735,7 @@ var Device = /** @class */ (function () {
735
735
  if (configFolder instanceof file_system_1.Folder) {
736
736
  configFile = new file_system_1.File({
737
737
  name: 'repod.conf',
738
- permissions: '-rw-r--r--',
738
+ permissions: 'rw-r--r--',
739
739
  owner: 'root',
740
740
  type: file_system_1.FileType.Source,
741
741
  content: JSON.stringify({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-mock-environment",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Mock environment",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",