|
1 | 1 | import { describe, expect, it } from 'vitest';
|
2 |
| -import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation } from './chmod-calculator.service'; |
| 2 | +import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation, computeUmaskRepresentation } from './chmod-calculator.service'; |
3 | 3 |
|
4 | 4 | describe('chmod-calculator', () => {
|
5 | 5 | describe('computeChmodOctalRepresentation', () => {
|
@@ -454,4 +454,106 @@ describe('chmod-calculator', () => {
|
454 | 454 | });
|
455 | 455 | });
|
456 | 456 | });
|
| 457 | + |
| 458 | + describe('computeUmaskRepresentation', () => { |
| 459 | + it('get the umask from permissions', () => { |
| 460 | + expect( |
| 461 | + computeUmaskRepresentation({ |
| 462 | + permissions: { |
| 463 | + owner: { read: true, write: true, execute: true }, |
| 464 | + group: { read: true, write: true, execute: true }, |
| 465 | + public: { read: true, write: true, execute: true }, |
| 466 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 467 | + }, |
| 468 | + }), |
| 469 | + ).to.deep.eq({ |
| 470 | + octal: '000', |
| 471 | + symbolic: 'umask u=rwx,g=rwx,o=rwx', |
| 472 | + }); |
| 473 | + |
| 474 | + expect( |
| 475 | + computeUmaskRepresentation({ |
| 476 | + permissions: { |
| 477 | + owner: { read: false, write: false, execute: false }, |
| 478 | + group: { read: false, write: false, execute: false }, |
| 479 | + public: { read: false, write: false, execute: false }, |
| 480 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 481 | + }, |
| 482 | + }), |
| 483 | + ).to.deep.eq({ |
| 484 | + octal: '777', |
| 485 | + symbolic: 'umask u=,g=,o=', |
| 486 | + }); |
| 487 | + |
| 488 | + expect( |
| 489 | + computeUmaskRepresentation({ |
| 490 | + permissions: { |
| 491 | + owner: { read: false, write: true, execute: false }, |
| 492 | + group: { read: false, write: true, execute: true }, |
| 493 | + public: { read: true, write: false, execute: true }, |
| 494 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 495 | + }, |
| 496 | + }), |
| 497 | + ).to.deep.eq({ |
| 498 | + octal: '542', |
| 499 | + symbolic: 'umask u=w,g=wx,o=rx', |
| 500 | + }); |
| 501 | + |
| 502 | + expect( |
| 503 | + computeUmaskRepresentation({ |
| 504 | + permissions: { |
| 505 | + owner: { read: true, write: false, execute: false }, |
| 506 | + group: { read: false, write: true, execute: false }, |
| 507 | + public: { read: false, write: false, execute: true }, |
| 508 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 509 | + }, |
| 510 | + }), |
| 511 | + ).to.deep.eq({ |
| 512 | + octal: '356', |
| 513 | + symbolic: 'umask u=r,g=w,o=x', |
| 514 | + }); |
| 515 | + |
| 516 | + expect( |
| 517 | + computeUmaskRepresentation({ |
| 518 | + permissions: { |
| 519 | + owner: { read: false, write: false, execute: true }, |
| 520 | + group: { read: false, write: true, execute: false }, |
| 521 | + public: { read: true, write: false, execute: false }, |
| 522 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 523 | + }, |
| 524 | + }), |
| 525 | + ).to.deep.eq({ |
| 526 | + octal: '653', |
| 527 | + symbolic: 'umask u=x,g=w,o=r', |
| 528 | + }); |
| 529 | + |
| 530 | + expect( |
| 531 | + computeUmaskRepresentation({ |
| 532 | + permissions: { |
| 533 | + owner: { read: false, write: true, execute: false }, |
| 534 | + group: { read: false, write: true, execute: false }, |
| 535 | + public: { read: false, write: true, execute: false }, |
| 536 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 537 | + }, |
| 538 | + }), |
| 539 | + ).to.deep.eq({ |
| 540 | + octal: '555', |
| 541 | + symbolic: 'umask u=w,g=w,o=w', |
| 542 | + }); |
| 543 | + |
| 544 | + expect( |
| 545 | + computeUmaskRepresentation({ |
| 546 | + permissions: { |
| 547 | + owner: { read: false, write: false, execute: true }, |
| 548 | + group: { read: false, write: true, execute: false }, |
| 549 | + public: { read: true, write: false, execute: false }, |
| 550 | + flags: { setuid: true, setgid: true, stickybit: true }, |
| 551 | + }, |
| 552 | + }), |
| 553 | + ).to.deep.eq({ |
| 554 | + octal: '653', |
| 555 | + symbolic: 'umask u=x,g=w,o=r', |
| 556 | + }); |
| 557 | + }); |
| 558 | + }); |
457 | 559 | });
|
0 commit comments