Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion apps/dokploy/__test__/utils/backups.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import { normalizeS3Path } from "@dokploy/server/utils/backups/utils";
import type { Destination } from "@dokploy/server/services/destination";
import {
getRcloneBucketPath,
getS3Credentials,
normalizeS3Path,
} from "@dokploy/server/utils/backups/utils";
import { describe, expect, test } from "vitest";

const baseDestination = {
destinationId: "dest-1",
name: "test",
provider: "AWS",
accessKey: "AKIA",
secretAccessKey: "secret",
bucket: "my-bucket",
region: "us-east-1",
endpoint: "https://s3.example.com",
additionalFlags: null,
organizationId: "org-1",
createdAt: new Date(),
} satisfies Destination;

describe("normalizeS3Path", () => {
test("should handle empty and whitespace-only prefix", () => {
expect(normalizeS3Path("")).toBe("");
Expand Down Expand Up @@ -59,3 +78,72 @@ describe("normalizeS3Path", () => {
expect(normalizeS3Path("instance-backups")).toBe("instance-backups/");
});
});

describe("getRcloneBucketPath", () => {
test("returns S3-style remote for S3 providers", () => {
expect(getRcloneBucketPath(baseDestination)).toBe(":s3:my-bucket");
});

test("uses the user-supplied connection string for Custom provider", () => {
const destination: Destination = {
...baseDestination,
provider: "Custom",
endpoint: ":sftp,host=example.com,user=foo,pass=bar:",
bucket: "",
accessKey: "",
secretAccessKey: "",
region: "",
};
expect(getRcloneBucketPath(destination)).toBe(
":sftp,host=example.com,user=foo,pass=bar:",
);
});

test("appends the optional path/folder for Custom provider", () => {
const destination: Destination = {
...baseDestination,
provider: "Custom",
endpoint: ":drive,token=xyz:",
bucket: "/backups",
accessKey: "",
secretAccessKey: "",
region: "",
};
expect(getRcloneBucketPath(destination)).toBe(":drive,token=xyz:backups");
});
});

describe("getS3Credentials", () => {
test("emits --s3-* flags for S3 providers", () => {
const flags = getS3Credentials(baseDestination);
expect(flags).toContain('--s3-access-key-id="AKIA"');
expect(flags).toContain('--s3-secret-access-key="secret"');
expect(flags).toContain('--s3-region="us-east-1"');
expect(flags).toContain('--s3-endpoint="https://s3.example.com"');
expect(flags).toContain('--s3-provider="AWS"');
});

test("does NOT emit --s3-* flags for Custom provider", () => {
const destination: Destination = {
...baseDestination,
provider: "Custom",
endpoint: ":sftp,host=example.com,user=foo,pass=bar:",
additionalFlags: ["--sftp-disable-hashcheck"],
};
const flags = getS3Credentials(destination);
for (const flag of flags) {
expect(flag).not.toMatch(/^--s3-/);
}
expect(flags).toEqual(["--sftp-disable-hashcheck"]);
});

test("returns an empty array for Custom provider with no additional flags", () => {
const destination: Destination = {
...baseDestination,
provider: "Custom",
endpoint: ":sftp,host=example.com,user=foo,pass=bar:",
additionalFlags: null,
};
expect(getS3Credentials(destination)).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export const CUSTOM_PROVIDER_KEY = "Custom";

export const S3_PROVIDERS: Array<{
key: string;
name: string;
}> = [
{
key: CUSTOM_PROVIDER_KEY,
name: "Custom (rclone connection string — FTP/SFTP/Google Drive/etc.)",
},
{
key: "AWS",
name: "Amazon Web Services (AWS) S3",
Expand Down
Loading
Loading