|
| 1 | +import { redactRcloneCredentials } from "@dokploy/server/utils/backups/redact"; |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | + |
| 4 | +describe("redactRcloneCredentials (#4621)", () => { |
| 5 | + it("should redact access key in rclone command", () => { |
| 6 | + const cmd = |
| 7 | + 'rclone rcat --s3-access-key-id="AKIAIOSFODNN7EXAMPLE" --s3-secret-access-key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" :s3:bucket/file.gz'; |
| 8 | + const redacted = redactRcloneCredentials(cmd); |
| 9 | + expect(redacted).not.toContain("AKIAIOSFODNN7EXAMPLE"); |
| 10 | + expect(redacted).toContain('--s3-access-key-id="[REDACTED]"'); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should redact secret access key in rclone command", () => { |
| 14 | + const cmd = |
| 15 | + 'rclone rcat --s3-access-key-id="key" --s3-secret-access-key="supersecret" :s3:bucket/file.gz'; |
| 16 | + const redacted = redactRcloneCredentials(cmd); |
| 17 | + expect(redacted).not.toContain("supersecret"); |
| 18 | + expect(redacted).toContain('--s3-secret-access-key="[REDACTED]"'); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should redact both credentials simultaneously", () => { |
| 22 | + const cmd = |
| 23 | + 'rclone lsf --s3-access-key-id="AKIA123" --s3-secret-access-key="secret456" --s3-region="us-east-1" :s3:bucket/'; |
| 24 | + const redacted = redactRcloneCredentials(cmd); |
| 25 | + expect(redacted).not.toContain("AKIA123"); |
| 26 | + expect(redacted).not.toContain("secret456"); |
| 27 | + expect(redacted).toContain('--s3-region="us-east-1"'); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should not modify non-credential flags", () => { |
| 31 | + const cmd = |
| 32 | + 'rclone rcat --s3-region="eu-west-1" --s3-endpoint="https://s3.example.com" --s3-no-check-bucket :s3:bucket/file.gz'; |
| 33 | + const redacted = redactRcloneCredentials(cmd); |
| 34 | + expect(redacted).toBe(cmd); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should handle commands with no credentials", () => { |
| 38 | + const cmd = "rclone lsf :s3:bucket/"; |
| 39 | + expect(redactRcloneCredentials(cmd)).toBe(cmd); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should handle error strings containing credentials", () => { |
| 43 | + const errorStr = |
| 44 | + 'Error: Command failed: rclone lsf --s3-access-key-id="MYKEY" --s3-secret-access-key="MYSECRET" :s3:bucket/'; |
| 45 | + const redacted = redactRcloneCredentials(errorStr); |
| 46 | + expect(redacted).not.toContain("MYKEY"); |
| 47 | + expect(redacted).not.toContain("MYSECRET"); |
| 48 | + expect(redacted).toContain("[REDACTED]"); |
| 49 | + }); |
| 50 | +}); |
0 commit comments