92 lines
5.7 KiB
TypeScript
92 lines
5.7 KiB
TypeScript
import { FileSystem } from "@core/filesystem/filesystem";
|
|
import type { TreeNode } from "@core/filesystem/node";
|
|
import type { GroupInfo, UserInfo } from "@core/session_manager";
|
|
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
|
import { deserializeFileSystem } from "@shell/serializer";
|
|
import { buildTestFS } from "./filesystems_fixture";
|
|
import { depth7Tree } from "./tree_fixture";
|
|
|
|
export class Fixture {
|
|
/*
|
|
root (0)
|
|
├── folder1 (1)
|
|
│ └── subdir1 (2)
|
|
├── folder2 (3)
|
|
│ ├── subdir2 (4)
|
|
│ └── subdir3 (5)
|
|
│ └── empty-foo (6)
|
|
└── some-file (7)
|
|
*/
|
|
|
|
static rawJson = `{"atime": 1786341244,"children": [{"atime": 1786341264,"children": [{"atime": 1786341330,"children": [],"content": null,"ctime": 1786341330,"group": 1000,"inode": 2,"mode": 493,"mtime": 1786341330,"name": "subdir1","owner": 1000,"parent": 1,"type": "directory"}],"content": null,"ctime": 1786341330,"group": 1000,"inode": 1,"mode": 493,"mtime": 1786341330,"name": "folder1","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341269,"children": [{"atime": 1786341344,"children": [],"content": null,"ctime": 1786341344,"group": 1000,"inode": 4,"mode": 493,"mtime": 1786341344,"name": "subdir2","owner": 1000,"parent": 3,"type": "directory"},{"atime": 1786341345,"children": [{"atime": 1786341356,"children": [],"content": [],"ctime": 1786341356,"group": 1000,"inode": 6,"mode": 420,"mtime": 1786341356,"name": "empty-foo","owner": 1000,"parent": 5,"type": "regular"}],"content": null,"ctime": 1786341356,"group": 1000,"inode": 5,"mode": 493,"mtime": 1786341356,"name": "subdir3","owner": 1000,"parent": 3,"type": "directory"}],"content": null,"ctime": 1786341345,"group": 1000,"inode": 3,"mode": 493,"mtime": 1786341345,"name": "folder2","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341312,"children": [],"content": [72,101,108,108,111,44,32,87,111,114,108,100,33,10],"ctime": 1786341312,"group": 1000,"inode": 7,"mode": 420,"mtime": 1786341312,"name": "some-file","owner": 1000,"parent": 0,"type": "regular"}],"content": null,"ctime": 1786341312,"group": 1000,"inode": 0,"mode": 493,"mtime": 1786341312,"name": "root","owner": 1000,"parent": 0,"type": "directory"}`;
|
|
static user: UserInfo = {
|
|
username: "root",
|
|
uid: 0,
|
|
gid: 0, // <- PRIMARY GID
|
|
group: [0], // <- GROUPS ARRAY
|
|
home: 0,
|
|
};
|
|
static user2: UserInfo = {
|
|
username: "user",
|
|
uid: 1000,
|
|
gid: 1000,
|
|
group: [1000],
|
|
home: 1,
|
|
};
|
|
|
|
static nopass: UserInfo = {
|
|
username: "no pass",
|
|
uid: 1001,
|
|
gid: 1000,
|
|
group: [1000],
|
|
home: 2,
|
|
};
|
|
|
|
static group: GroupInfo = {
|
|
groupname: "root",
|
|
gid: 0,
|
|
members: [0], // <- UID
|
|
};
|
|
static group2: GroupInfo = {
|
|
groupname: "user",
|
|
gid: 1000,
|
|
members: [1000, 1001], // <- UID
|
|
};
|
|
|
|
public static get State(): ShellState {
|
|
const rawJson = `{"atime": 1786341244,"children": [{"atime": 1786341264,"children": [{"atime": 1786341330,"children": [],"content": null,"ctime": 1786341330,"group": 1000,"inode": 2,"mode": 493,"mtime": 1786341330,"name": "subdir1","owner": 1000,"parent": 1,"type": "directory"}],"content": null,"ctime": 1786341330,"group": 1000,"inode": 1,"mode": 493,"mtime": 1786341330,"name": "folder1","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341269,"children": [{"atime": 1786341344,"children": [],"content": null,"ctime": 1786341344,"group": 1000,"inode": 4,"mode": 493,"mtime": 1786341344,"name": "subdir2","owner": 1000,"parent": 3,"type": "directory"},{"atime": 1786341345,"children": [{"atime": 1786341356,"children": [],"content": [],"ctime": 1786341356,"group": 1000,"inode": 6,"mode": 420,"mtime": 1786341356,"name": "empty-foo","owner": 1000,"parent": 5,"type": "regular"}],"content": null,"ctime": 1786341356,"group": 1000,"inode": 5,"mode": 493,"mtime": 1786341356,"name": "subdir3","owner": 1000,"parent": 3,"type": "directory"}],"content": null,"ctime": 1786341345,"group": 1000,"inode": 3,"mode": 493,"mtime": 1786341345,"name": "folder2","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341312,"children": [],"content": [72,101,108,108,111,44,32,87,111,114,108,100,33,10],"ctime": 1786341312,"group": 1000,"inode": 7,"mode": 420,"mtime": 1786341312,"name": "some-file","owner": 1000,"parent": 0,"type": "regular"}],"content": null,"ctime": 1786341312,"group": 1000,"inode": 0,"mode": 493,"mtime": 1786341312,"name": "root","owner": 1000,"parent": 0,"type": "directory"}`;
|
|
const base = deserializeFileSystem(rawJson);
|
|
|
|
const overlay: ReadonlyMap<number, TreeNode | null> = new Map();
|
|
|
|
const fs = FileSystem.init(base, overlay, base.size - 1);
|
|
|
|
const users: Map<number, UserInfo> = new Map();
|
|
const groups: Map<number, GroupInfo> = new Map();
|
|
|
|
users.set(0, Fixture.user);
|
|
users.set(1000, Fixture.user2);
|
|
users.set(1001, Fixture.nopass);
|
|
groups.set(0, Fixture.group);
|
|
groups.set(1000, Fixture.group2);
|
|
|
|
return createInitialShellState(fs, users, groups, Fixture.user);
|
|
}
|
|
}
|
|
|
|
export class Fixture7Depth extends Fixture {
|
|
public static get State(): ShellState {
|
|
const fs = buildTestFS(depth7Tree);
|
|
|
|
const users: Map<number, UserInfo> = new Map();
|
|
const groups: Map<number, GroupInfo> = new Map();
|
|
|
|
users.set(0, Fixture7Depth.user);
|
|
users.set(1000, Fixture7Depth.user2);
|
|
groups.set(0, Fixture7Depth.group);
|
|
groups.set(1000, Fixture7Depth.group2);
|
|
|
|
return createInitialShellState(fs, users, groups, Fixture7Depth.user);
|
|
}
|
|
}
|