|
1 | 1 | import { describe, expect, it } from 'vitest';
|
2 |
| -import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation } from './chmod-calculator.service'; |
| 2 | +import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation, computePermissionsFromChmodOctalRepresentation, computePermissionsFromChmodSymbolicRepresentation } from './chmod-calculator.service'; |
3 | 3 |
|
4 | 4 | describe('chmod-calculator', () => {
|
5 | 5 | describe('computeChmodOctalRepresentation', () => {
|
@@ -339,4 +339,119 @@ describe('chmod-calculator', () => {
|
339 | 339 | });
|
340 | 340 | });
|
341 | 341 | });
|
| 342 | + describe('computePermissionsFromChmodSymbolicRepresentation', () => { |
| 343 | + it('throws on invalid symbolic values', () => { |
| 344 | + expect(() => computePermissionsFromChmodSymbolicRepresentation('rr---')).to.throw(); |
| 345 | + expect(() => computePermissionsFromChmodSymbolicRepresentation('rwxrwx--w')).to.throw(); |
| 346 | + }); |
| 347 | + |
| 348 | + it('get permissions from symbolic representation', () => { |
| 349 | + expect( |
| 350 | + computePermissionsFromChmodSymbolicRepresentation('dr-xr-xr-x'), |
| 351 | + ).to.eql({ |
| 352 | + owner: { read: true, write: false, execute: true }, |
| 353 | + group: { read: true, write: false, execute: true }, |
| 354 | + public: { read: true, write: false, execute: true }, |
| 355 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 356 | + }); |
| 357 | + expect( |
| 358 | + computePermissionsFromChmodSymbolicRepresentation('-rw-r--r--'), |
| 359 | + ).to.eql({ |
| 360 | + owner: { read: true, write: true, execute: false }, |
| 361 | + group: { read: true, write: false, execute: false }, |
| 362 | + public: { read: true, write: false, execute: false }, |
| 363 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 364 | + }); |
| 365 | + |
| 366 | + expect( |
| 367 | + computePermissionsFromChmodSymbolicRepresentation('rwxrwxrwx'), |
| 368 | + ).to.eql({ |
| 369 | + owner: { read: true, write: true, execute: true }, |
| 370 | + group: { read: true, write: true, execute: true }, |
| 371 | + public: { read: true, write: true, execute: true }, |
| 372 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 373 | + }); |
| 374 | + |
| 375 | + expect( |
| 376 | + computePermissionsFromChmodSymbolicRepresentation('---------'), |
| 377 | + ).to.eql({ |
| 378 | + owner: { read: false, write: false, execute: false }, |
| 379 | + group: { read: false, write: false, execute: false }, |
| 380 | + public: { read: false, write: false, execute: false }, |
| 381 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 382 | + }); |
| 383 | + |
| 384 | + expect( |
| 385 | + computePermissionsFromChmodSymbolicRepresentation('r---wxr-x'), |
| 386 | + ).to.eql({ |
| 387 | + owner: { read: true, write: false, execute: false }, |
| 388 | + group: { read: false, write: true, execute: true }, |
| 389 | + public: { read: true, write: false, execute: true }, |
| 390 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 391 | + }); |
| 392 | + |
| 393 | + expect( |
| 394 | + computePermissionsFromChmodSymbolicRepresentation('r---w---x'), |
| 395 | + ).to.eql({ |
| 396 | + owner: { read: true, write: false, execute: false }, |
| 397 | + group: { read: false, write: true, execute: false }, |
| 398 | + public: { read: false, write: false, execute: true }, |
| 399 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 400 | + }); |
| 401 | + |
| 402 | + expect( |
| 403 | + computePermissionsFromChmodSymbolicRepresentation('--x-w-r--'), |
| 404 | + ).to.eql({ |
| 405 | + owner: { read: false, write: false, execute: true }, |
| 406 | + group: { read: false, write: true, execute: false }, |
| 407 | + public: { read: true, write: false, execute: false }, |
| 408 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 409 | + }); |
| 410 | + |
| 411 | + expect( |
| 412 | + computePermissionsFromChmodSymbolicRepresentation('-w--w--w-'), |
| 413 | + ).to.eql({ |
| 414 | + owner: { read: false, write: true, execute: false }, |
| 415 | + group: { read: false, write: true, execute: false }, |
| 416 | + public: { read: false, write: true, execute: false }, |
| 417 | + flags: { setuid: false, setgid: false, stickybit: false }, |
| 418 | + }); |
| 419 | + |
| 420 | + expect( |
| 421 | + computePermissionsFromChmodSymbolicRepresentation('-ws-ws-wt'), |
| 422 | + ).to.eql({ |
| 423 | + owner: { read: false, write: true, execute: true }, |
| 424 | + group: { read: false, write: true, execute: true }, |
| 425 | + public: { read: false, write: true, execute: true }, |
| 426 | + flags: { setuid: true, setgid: true, stickybit: true }, |
| 427 | + }); |
| 428 | + |
| 429 | + expect( |
| 430 | + computePermissionsFromChmodSymbolicRepresentation('-ws-w--w-'), |
| 431 | + ).to.eql({ |
| 432 | + owner: { read: false, write: true, execute: true }, |
| 433 | + group: { read: false, write: true, execute: false }, |
| 434 | + public: { read: false, write: true, execute: false }, |
| 435 | + flags: { setuid: true, setgid: false, stickybit: false }, |
| 436 | + }); |
| 437 | + |
| 438 | + expect( |
| 439 | + computePermissionsFromChmodSymbolicRepresentation('-w--ws-w-'), |
| 440 | + ).to.eql({ |
| 441 | + owner: { read: false, write: true, execute: false }, |
| 442 | + group: { read: false, write: true, execute: true }, |
| 443 | + public: { read: false, write: true, execute: false }, |
| 444 | + flags: { setuid: false, setgid: true, stickybit: false }, |
| 445 | + }); |
| 446 | + |
| 447 | + expect( |
| 448 | + computePermissionsFromChmodSymbolicRepresentation('-w--w--wt'), |
| 449 | + ).to.eql({ |
| 450 | + owner: { read: false, write: true, execute: false }, |
| 451 | + group: { read: false, write: true, execute: false }, |
| 452 | + public: { read: false, write: true, execute: true }, |
| 453 | + flags: { setuid: false, setgid: false, stickybit: true }, |
| 454 | + }); |
| 455 | + }); |
| 456 | + }); |
342 | 457 | });
|
0 commit comments