Skip to content

Commit 23765b0

Browse files
committed
chore: add size limit to preset icon and description
1 parent 2a17ccc commit 23765b0

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

provider/workspace_preset.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,22 @@ func workspacePresetDataSource() *schema.Resource {
9696
ValidateFunc: validation.StringIsNotEmpty,
9797
},
9898
"description": {
99-
Type: schema.TypeString,
100-
Optional: true,
101-
Description: "Describe what this preset does.",
99+
Type: schema.TypeString,
100+
Optional: true,
101+
Description: "Describe what this preset does.",
102+
ValidateFunc: validation.StringLenBetween(0, 128),
102103
},
103104
"icon": {
104105
Type: schema.TypeString,
105106
Description: "A URL to an icon that will display in the dashboard. View built-in " +
106107
"icons [here](https://github.com/coder/coder/tree/main/site/static/icon). Use a " +
107108
"built-in icon with `\"${data.coder_workspace.me.access_url}/icon/<path>\"`.",
108-
ForceNew: true,
109-
Optional: true,
110-
ValidateFunc: helpers.ValidateURL,
109+
ForceNew: true,
110+
Optional: true,
111+
ValidateFunc: validation.All(
112+
helpers.ValidateURL,
113+
validation.StringLenBetween(0, 256),
114+
),
111115
},
112116
"default": {
113117
Type: schema.TypeBool,

provider/workspace_preset_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ func TestWorkspacePreset(t *testing.T) {
9797
// So we test it here to make sure we don't regress.
9898
ExpectError: nil,
9999
},
100+
{
101+
Name: "Description field exceeds maximum supported length (128 characters)",
102+
Config: `
103+
data "coder_workspace_preset" "preset_1" {
104+
name = "preset_1"
105+
description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vehicula leo sit amet mi laoreet, sed ornare velit tincidunt. Proin gravida lacinia blandit."
106+
parameters = {
107+
"region" = "us-east1-a"
108+
}
109+
}`,
110+
// This validation is done by Terraform, but it could still break if we misconfigure the schema.
111+
// So we test it here to make sure we don't regress.
112+
ExpectError: regexp.MustCompile(`expected length of description to be in the range \(0 - 128\)`),
113+
},
100114
{
101115
Name: "Icon field is empty",
102116
Config: `
@@ -125,6 +139,20 @@ func TestWorkspacePreset(t *testing.T) {
125139
// So we test it here to make sure we don't regress.
126140
ExpectError: regexp.MustCompile("invalid URL escape"),
127141
},
142+
{
143+
Name: "Icon field exceeds maximum supported length (256 characters)",
144+
Config: `
145+
data "coder_workspace_preset" "preset_1" {
146+
name = "preset_1"
147+
icon = "https://example.com/path/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.svg"
148+
parameters = {
149+
"region" = "us-east1-a"
150+
}
151+
}`,
152+
// This validation is done by Terraform, but it could still break if we misconfigure the schema.
153+
// So we test it here to make sure we don't regress.
154+
ExpectError: regexp.MustCompile(`expected length of icon to be in the range \(0 - 256\)`),
155+
},
128156
{
129157
Name: "Parameters field is not provided",
130158
Config: `

0 commit comments

Comments
 (0)