mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-28 05:47:08 +02:00
Fix: validate app name (#5155)
This commit is contained in:
parent
8b4109bf85
commit
f9dc47e47e
@ -62,7 +62,7 @@ const (
|
||||
abapUserKey = "ABAP_USER"
|
||||
abapPasswordKey = "ABAP_PASSWORD"
|
||||
defaultConfigFileName = "ui5-deploy.yaml"
|
||||
pattern = "^[a-zA-Z0-9_]+$"
|
||||
pattern = "^(/[A-Za-z0-9_]{3,8}/)?[A-Za-z0-9_]+$"
|
||||
)
|
||||
|
||||
// WithConnection ...
|
||||
@ -194,7 +194,7 @@ func getFioriDeployStatement(
|
||||
if len(app.Name) > 0 {
|
||||
re := regexp.MustCompile(pattern)
|
||||
if !re.MatchString(app.Name) {
|
||||
return "", fmt.Errorf("application name '%s' contains spaces or special characters and is not according to the regex '%s'.", app.Name, pattern)
|
||||
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)
|
||||
}
|
||||
log.Entry().Debugf("application name '%s' used from piper config", app.Name)
|
||||
cmd = append(cmd, "--name", app.Name)
|
||||
|
@ -52,7 +52,7 @@ func TestUploadCTS(t *testing.T) {
|
||||
cmd := mock.ShellMockRunner{}
|
||||
action := UploadAction{
|
||||
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
|
||||
Application: Application{Pack: "abapPackage", Name: "appName", Desc: "the Desc"},
|
||||
Application: Application{Pack: "abapPackage", Name: "/0ABCD/appName", Desc: "the Desc"},
|
||||
Node: Node{
|
||||
DeployDependencies: []string{},
|
||||
InstallOpts: []string{},
|
||||
@ -66,7 +66,7 @@ func TestUploadCTS(t *testing.T) {
|
||||
if assert.NoError(t, err) {
|
||||
assert.Regexp(
|
||||
t,
|
||||
"(?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$",
|
||||
"(?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",
|
||||
cmd.Calls[0],
|
||||
"Expected fiori deploy command not found",
|
||||
)
|
||||
@ -101,11 +101,11 @@ func TestUploadCTS(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("fail in case of invalid app name", func(t *testing.T) {
|
||||
t.Run("fail in case of invalid app name", func(t *testing.T) {
|
||||
cmd := mock.ShellMockRunner{}
|
||||
action := UploadAction{
|
||||
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
|
||||
Application: Application{Pack: "abapPackage", Name: "app Name", Desc: "the Desc"},
|
||||
Application: Application{Pack: "abapPackage", Name: "/AB/app1", Desc: "the Desc"},
|
||||
Node: Node{
|
||||
DeployDependencies: []string{},
|
||||
InstallOpts: []string{},
|
||||
@ -116,7 +116,7 @@ func TestUploadCTS(t *testing.T) {
|
||||
}
|
||||
|
||||
err := action.Perform(&cmd)
|
||||
expectedErrorMessge := "application name 'app Name' contains spaces or special characters and is not according to the regex '^[a-zA-Z0-9_]+$'."
|
||||
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_]+$'."
|
||||
|
||||
assert.EqualErrorf(t, err, expectedErrorMessge, "invalid app name")
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user