Skip to content

Commit f9dc47e

Browse files
authored
Fix: validate app name (#5155)
1 parent 8b4109b commit f9dc47e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pkg/transportrequest/cts/upload.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const (
6262
abapUserKey = "ABAP_USER"
6363
abapPasswordKey = "ABAP_PASSWORD"
6464
defaultConfigFileName = "ui5-deploy.yaml"
65-
pattern = "^[a-zA-Z0-9_]+$"
65+
pattern = "^(/[A-Za-z0-9_]{3,8}/)?[A-Za-z0-9_]+$"
6666
)
6767

6868
// WithConnection ...
@@ -194,7 +194,7 @@ func getFioriDeployStatement(
194194
if len(app.Name) > 0 {
195195
re := regexp.MustCompile(pattern)
196196
if !re.MatchString(app.Name) {
197-
return "", fmt.Errorf("application name '%s' contains spaces or special characters and is not according to the regex '%s'.", app.Name, pattern)
197+
return "", fmt.Errorf("application name '%s' contains spaces or special characters or invalid namespace prefix and is not according to the regex '%s'.", app.Name, pattern)
198198
}
199199
log.Entry().Debugf("application name '%s' used from piper config", app.Name)
200200
cmd = append(cmd, "--name", app.Name)

pkg/transportrequest/cts/upload_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestUploadCTS(t *testing.T) {
5252
cmd := mock.ShellMockRunner{}
5353
action := UploadAction{
5454
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
55-
Application: Application{Pack: "abapPackage", Name: "appName", Desc: "the Desc"},
55+
Application: Application{Pack: "abapPackage", Name: "/0ABCD/appName", Desc: "the Desc"},
5656
Node: Node{
5757
DeployDependencies: []string{},
5858
InstallOpts: []string{},
@@ -66,7 +66,7 @@ func TestUploadCTS(t *testing.T) {
6666
if assert.NoError(t, err) {
6767
assert.Regexp(
6868
t,
69-
"(?m)^fiori deploy --failfast --yes --username ABAP_USER --password ABAP_PASSWORD --description \"the Desc\" --noConfig --url https://example.org:8080/cts --client 001 --transport 12345678 --package abapPackage --name appName$",
69+
"(?m)^fiori deploy --failfast --yes --username ABAP_USER --password ABAP_PASSWORD --description \"the Desc\" --noConfig --url https://example.org:8080/cts --client 001 --transport 12345678 --package abapPackage --name /0ABCD/appName",
7070
cmd.Calls[0],
7171
"Expected fiori deploy command not found",
7272
)
@@ -101,11 +101,11 @@ func TestUploadCTS(t *testing.T) {
101101
}
102102
})
103103

104-
t.Run("fail in case of invalid app name", func(t *testing.T) {
104+
t.Run("fail in case of invalid app name", func(t *testing.T) {
105105
cmd := mock.ShellMockRunner{}
106106
action := UploadAction{
107107
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
108-
Application: Application{Pack: "abapPackage", Name: "app Name", Desc: "the Desc"},
108+
Application: Application{Pack: "abapPackage", Name: "/AB/app1", Desc: "the Desc"},
109109
Node: Node{
110110
DeployDependencies: []string{},
111111
InstallOpts: []string{},
@@ -116,7 +116,7 @@ func TestUploadCTS(t *testing.T) {
116116
}
117117

118118
err := action.Perform(&cmd)
119-
expectedErrorMessge := "application name 'app Name' contains spaces or special characters and is not according to the regex '^[a-zA-Z0-9_]+$'."
119+
expectedErrorMessge := "application name '/AB/app1' contains spaces or special characters or invalid namespace prefix and is not according to the regex '^(/[A-Za-z0-9_]{3,8}/)?[A-Za-z0-9_]+$'."
120120

121121
assert.EqualErrorf(t, err, expectedErrorMessge, "invalid app name")
122122
})

0 commit comments

Comments
 (0)