You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-07-15 01:34:38 +02:00
Fix: validate app name (#5155)
This commit is contained in:
committed by
GitHub
parent
8b4109bf85
commit
f9dc47e47e
@ -62,7 +62,7 @@ const (
|
|||||||
abapUserKey = "ABAP_USER"
|
abapUserKey = "ABAP_USER"
|
||||||
abapPasswordKey = "ABAP_PASSWORD"
|
abapPasswordKey = "ABAP_PASSWORD"
|
||||||
defaultConfigFileName = "ui5-deploy.yaml"
|
defaultConfigFileName = "ui5-deploy.yaml"
|
||||||
pattern = "^[a-zA-Z0-9_]+$"
|
pattern = "^(/[A-Za-z0-9_]{3,8}/)?[A-Za-z0-9_]+$"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WithConnection ...
|
// WithConnection ...
|
||||||
@ -194,7 +194,7 @@ func getFioriDeployStatement(
|
|||||||
if len(app.Name) > 0 {
|
if len(app.Name) > 0 {
|
||||||
re := regexp.MustCompile(pattern)
|
re := regexp.MustCompile(pattern)
|
||||||
if !re.MatchString(app.Name) {
|
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)
|
log.Entry().Debugf("application name '%s' used from piper config", app.Name)
|
||||||
cmd = append(cmd, "--name", app.Name)
|
cmd = append(cmd, "--name", app.Name)
|
||||||
|
@ -52,7 +52,7 @@ func TestUploadCTS(t *testing.T) {
|
|||||||
cmd := mock.ShellMockRunner{}
|
cmd := mock.ShellMockRunner{}
|
||||||
action := UploadAction{
|
action := UploadAction{
|
||||||
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
|
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{
|
Node: Node{
|
||||||
DeployDependencies: []string{},
|
DeployDependencies: []string{},
|
||||||
InstallOpts: []string{},
|
InstallOpts: []string{},
|
||||||
@ -66,7 +66,7 @@ func TestUploadCTS(t *testing.T) {
|
|||||||
if assert.NoError(t, err) {
|
if assert.NoError(t, err) {
|
||||||
assert.Regexp(
|
assert.Regexp(
|
||||||
t,
|
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],
|
cmd.Calls[0],
|
||||||
"Expected fiori deploy command not found",
|
"Expected fiori deploy command not found",
|
||||||
)
|
)
|
||||||
@ -105,7 +105,7 @@ func TestUploadCTS(t *testing.T) {
|
|||||||
cmd := mock.ShellMockRunner{}
|
cmd := mock.ShellMockRunner{}
|
||||||
action := UploadAction{
|
action := UploadAction{
|
||||||
Connection: Connection{Endpoint: "https://example.org:8080/cts", Client: "001", User: "me", Password: "******"},
|
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{
|
Node: Node{
|
||||||
DeployDependencies: []string{},
|
DeployDependencies: []string{},
|
||||||
InstallOpts: []string{},
|
InstallOpts: []string{},
|
||||||
@ -116,7 +116,7 @@ func TestUploadCTS(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := action.Perform(&cmd)
|
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")
|
assert.EqualErrorf(t, err, expectedErrorMessge, "invalid app name")
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user