Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b3fc65

Browse files
authored
fix: app display name validation (#344)
1 parentaef6220 commit4b3fc65

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

‎provider/app.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var (
2323
appSlugRegex=regexp.MustCompile(`^[a-z0-9](-?[a-z0-9])*$`)
2424
)
2525

26+
constappDisplayNameMaxLength=64// database column limit
27+
2628
funcappResource()*schema.Resource {
2729
return&schema.Resource{
2830
SchemaVersion:1,
@@ -124,6 +126,17 @@ func appResource() *schema.Resource {
124126
Description:"A display name to identify the app. Defaults to the slug.",
125127
ForceNew:true,
126128
Optional:true,
129+
ValidateDiagFunc:func(valinterface{},c cty.Path) diag.Diagnostics {
130+
valStr,ok:=val.(string)
131+
if!ok {
132+
returndiag.Errorf("expected string, got %T",val)
133+
}
134+
135+
iflen(valStr)>appDisplayNameMaxLength {
136+
returndiag.Errorf("display name is too long (max %d characters)",appDisplayNameMaxLength)
137+
}
138+
returnnil
139+
},
127140
},
128141
"subdomain": {
129142
Type:schema.TypeBool,

‎provider/app_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,66 @@ func TestApp(t *testing.T) {
415415
}
416416
})
417417

418+
t.Run("DisplayName",func(t*testing.T) {
419+
t.Parallel()
420+
421+
cases:= []struct {
422+
namestring
423+
displayNamestring
424+
expectValuestring
425+
expectError*regexp.Regexp
426+
}{
427+
{
428+
name:"Empty",
429+
displayName:"",
430+
},
431+
{
432+
name:"Regular",
433+
displayName:"Regular Application",
434+
},
435+
{
436+
name:"DisplayNameStillOK",
437+
displayName:"0123456789012345678901234567890123456789012345678901234567890123",
438+
},
439+
{
440+
name:"DisplayNameTooLong",
441+
displayName:"01234567890123456789012345678901234567890123456789012345678901234",
442+
expectError:regexp.MustCompile("display name is too long"),
443+
},
444+
}
445+
446+
for_,c:=rangecases {
447+
c:=c
448+
449+
t.Run(c.name,func(t*testing.T) {
450+
t.Parallel()
451+
452+
config:=fmt.Sprintf(`
453+
provider "coder" {
454+
}
455+
resource "coder_agent" "dev" {
456+
os = "linux"
457+
arch = "amd64"
458+
}
459+
resource "coder_app" "code-server" {
460+
agent_id = coder_agent.dev.id
461+
slug = "code-server"
462+
display_name = "%s"
463+
url = "http://localhost:13337"
464+
open_in = "slim-window"
465+
}
466+
`,c.displayName)
467+
468+
resource.Test(t, resource.TestCase{
469+
ProviderFactories:coderFactory(),
470+
IsUnitTest:true,
471+
Steps: []resource.TestStep{{
472+
Config:config,
473+
ExpectError:c.expectError,
474+
}},
475+
})
476+
})
477+
}
478+
})
479+
418480
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp