|
| 1 | +import type { Destination } from "@dokploy/server/services/destination"; |
1 | 2 | import { redactRcloneCredentials } from "@dokploy/server/utils/backups/redact"; |
| 3 | +import { getS3Credentials } from "@dokploy/server/utils/backups/utils"; |
2 | 4 | import { describe, expect, it } from "vitest"; |
3 | 5 |
|
4 | 6 | describe("redactRcloneCredentials (#4621)", () => { |
@@ -48,3 +50,48 @@ describe("redactRcloneCredentials (#4621)", () => { |
48 | 50 | expect(redacted).toContain("[REDACTED]"); |
49 | 51 | }); |
50 | 52 | }); |
| 53 | + |
| 54 | +describe("redactRcloneCredentials with getS3Credentials output (#5519)", () => { |
| 55 | + const buildCommand = (accessKey: string, secretAccessKey: string) => |
| 56 | + `rclone rcat ${getS3Credentials({ |
| 57 | + accessKey, |
| 58 | + secretAccessKey, |
| 59 | + region: "us-west-001", |
| 60 | + endpoint: "https://s3.us-west-001.backblazeb2.com", |
| 61 | + provider: "Other", |
| 62 | + } as Destination).join(" ")} :s3:bucket/file.gz`; |
| 63 | + |
| 64 | + it.each([ |
| 65 | + [ |
| 66 | + "plain alphanumeric", |
| 67 | + "001aaaabbbbccccdd0000000001", |
| 68 | + "K001FAKEfakeFAKEfake", |
| 69 | + ], |
| 70 | + [ |
| 71 | + "containing slashes", |
| 72 | + "AKIAIOSFODNN7EXAMPLE", |
| 73 | + "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", |
| 74 | + ], |
| 75 | + ["containing spaces", "key with space", "secret with space"], |
| 76 | + ["containing quotes", "it's-a-key", `say "hi" it's`], |
| 77 | + ["containing shell metacharacters", "key$HOME", "sec;ret`id`&|\\x"], |
| 78 | + ])("redacts credentials %s", (_, accessKey, secretAccessKey) => { |
| 79 | + const redacted = redactRcloneCredentials( |
| 80 | + buildCommand(accessKey, secretAccessKey), |
| 81 | + ); |
| 82 | + expect(redacted).toContain( |
| 83 | + '--s3-access-key-id="[REDACTED]" --s3-secret-access-key="[REDACTED]" --s3-region=us-west-001', |
| 84 | + ); |
| 85 | + expect(redacted).not.toContain(accessKey); |
| 86 | + expect(redacted).not.toContain(secretAccessKey); |
| 87 | + expect(redacted).toContain(":s3:bucket/file.gz"); |
| 88 | + }); |
| 89 | + |
| 90 | + it("redacts credentials embedded in an error string", () => { |
| 91 | + const errorStr = `Error: Command failed: ${buildCommand("MYKEY", "MY/SECRET")}`; |
| 92 | + const redacted = redactRcloneCredentials(errorStr); |
| 93 | + expect(redacted).not.toContain("MYKEY"); |
| 94 | + expect(redacted).not.toContain("MY/SECRET"); |
| 95 | + expect(redacted).toContain("[REDACTED]"); |
| 96 | + }); |
| 97 | +}); |
0 commit comments