mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
feat(Chmod Calculator): octal input and special flags
Handle input of octal rights values and special flags Fix #670 and #527
This commit is contained in:
parent
d3b32cc14e
commit
3ead4d37ad
4 changed files with 314 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation } from './chmod-calculator.service';
|
||||
|
||||
describe('chmod-calculator', () => {
|
||||
describe('computeChmodOctalRepresentation', () => {
|
||||
|
@ -10,6 +10,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('777');
|
||||
|
@ -20,6 +21,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('000');
|
||||
|
@ -30,6 +32,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('235');
|
||||
|
@ -40,6 +43,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('421');
|
||||
|
@ -50,6 +54,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('124');
|
||||
|
@ -60,11 +65,57 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('222');
|
||||
});
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('7222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('4222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('2222');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('1222');
|
||||
});
|
||||
});
|
||||
describe('computeChmodSymbolicRepresentation', () => {
|
||||
it('get the symbolic representation from permissions', () => {
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
|
@ -72,6 +123,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('rwxrwxrwx');
|
||||
|
@ -82,6 +134,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('---------');
|
||||
|
@ -92,6 +145,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('-w--wxr-x');
|
||||
|
@ -102,6 +156,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('r---w---x');
|
||||
|
@ -112,6 +167,7 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-w-r--');
|
||||
|
@ -122,9 +178,165 @@ describe('chmod-calculator', () => {
|
|||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('-w--w--w-');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-w-r-t');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-wsr-t');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('--s-wsr-t');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: false, execute: true },
|
||||
group: { read: true, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('r-xrw-r--');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('rwsrwsrwt');
|
||||
});
|
||||
});
|
||||
describe('computePermissionsFromChmodOctalRepresentation', () => {
|
||||
it('throws on invalid octal values', () => {
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('12')).to.throw();
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('12345')).to.throw();
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('999')).to.throw();
|
||||
expect(() => computePermissionsFromChmodOctalRepresentation('9999')).to.throw();
|
||||
});
|
||||
|
||||
it('get permissions from octal representation', () => {
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('777'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('000'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('235'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('421'),
|
||||
).to.eql({
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('124'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('7222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: true, stickybit: true },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('4222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: true, setgid: false, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('2222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: true, stickybit: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
computePermissionsFromChmodOctalRepresentation('1222'),
|
||||
).to.eql({
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
flags: { setuid: false, setgid: false, stickybit: true },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue