Skip to content

Commit

Permalink
fix typo and include tests
Browse files Browse the repository at this point in the history
  • Loading branch information
h-sifat committed Nov 8, 2021
1 parent 7f93d0c commit 73f131c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/
coverage/
trash/
tests/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ analyze("drwxr---wx")
group: { read: true, write: false, execute: false },
other: { read: false, write: true, execute: true }
suid: false,
sgid: false,
guid: false,
sticky_bit: false
}
*/
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "permcon",
"version": "1.0.2",
"version": "1.0.3",
"description": "A simple utility tool to convert file-system permission from symbolic to octal notation and vice versa. ",
"keywords": [
"file-permission",
Expand All @@ -14,7 +14,7 @@
"octal",
"symbolic",
"SUID",
"SGID",
"GUID",
"STICKY_BIT"
],
"author": {
Expand Down
75 changes: 75 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const { isOctal, isSymbolic, analyze, convert } = require("../src");

describe("isOctal", () => {
it("should return true for valid octal permission strings", () => {
["123", "0764"].forEach((val) => {
expect(isOctal(val)).toBeTruthy();
});
});

it("should return false for invalid octal permission strings", () => {
["23242", "8349", "23434"].forEach((val) => {
expect(isOctal(val)).toBeFalsy();
});
});
});

describe("isSymbolic", () => {
it("should return true for valid symbolic permission strings", () => {
["drw-rw-r--", "rwxr---wx", "rwxr-xr--"].forEach((val) => {
expect(isSymbolic(val)).toBeTruthy();
});
});

it("should return false for invalid symbolic permission strings", () => {
["rdrw-rw-r--", "frxr---wx", "rwar-xr--"].forEach((val) => {
expect(isSymbolic(val)).toBeFalsy();
});
});
});

describe("convert", () => {
it("should conver sym to octal and vice versa", () => {
[
["rw-rw-r--", "0664"],
["rwxr---wx", "0743"],
["rwxr-xr--", "0754"],
].forEach(([s, o]) => {
expect(convert(s)).toEqual(o);
expect(convert(o)).toEqual(s);
});
});

it("should ignore the 1st the character of a 10 char long string", () => {
expect(convert("drw-rw-r--")).toEqual("0664");
});

it("should ignore the first 0 of a 4 char octal string", () => {
expect(convert("0664")).toEqual("rw-rw-r--");
});

it("should throw an error if invalid string is passed", () => {
expect(() => {
convert("a;sdlfjasdf");
}).toThrowError();
});
});

describe("analyze", () => {
const symbolicPermission = "drwsr---wT";
const expectedResult = {
fileType: "Directory",
symbolic: symbolicPermission,
octal: "5742",
owner: { read: true, write: true, execute: true },
group: { read: true, write: false, execute: false },
other: { read: false, write: true, execute: false },
suid: true,
guid: false,
sticky_bit: true,
};

it("should return the analyzed permission object", () => {
expect(analyze(symbolicPermission)).toEqual(expectedResult);
});
});

0 comments on commit 73f131c

Please sign in to comment.