Skip to content

Commit

Permalink
adding . and - to the regular expression to validate and cnn exec env
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Bustamante <bustamantejj@gmail.com>
  • Loading branch information
jjbustamante committed Jan 28, 2025
1 parent f4bbe82 commit f0a88d8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
3 changes: 1 addition & 2 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ func validateBuildFlags(flags *BuildFlags, cfg config.Config, inputImageRef clie
}

if flags.ExecutionEnv != "" && flags.ExecutionEnv != "production" && flags.ExecutionEnv != "test" {
// TODO: add . or - as valid values
var executionEnvRegex = regexp.MustCompile(`^[a-zA-Z0-9]+$`)
var executionEnvRegex = regexp.MustCompile(`^[a-zA-Z0-9.-]+$`)
if ok := executionEnvRegex.MatchString(flags.ExecutionEnv); !ok {
return errors.New("exec-env MUST only contain numbers, letters, and the characters: . or -")
}
Expand Down
47 changes: 46 additions & 1 deletion internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,59 @@ builder = "my-builder"

when("is provided", func() {
when("contains valid characters", func() {
it("forwards the exec-value into the client", func() {
it("forwards the exec-value (only letters) into the client", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithExecEnv("something")).
Return(nil)

command.SetArgs([]string{"image", "--builder", "my-builder", "--exec-env", "something"})
h.AssertNil(t, command.Execute())
})

it("forwards the exec-value (only numbers) into the client", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithExecEnv("1234")).
Return(nil)

command.SetArgs([]string{"image", "--builder", "my-builder", "--exec-env", "1234"})
h.AssertNil(t, command.Execute())
})

it("forwards the exec-value (mix letters and numbers) into the client", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithExecEnv("env1")).
Return(nil)

command.SetArgs([]string{"image", "--builder", "my-builder", "--exec-env", "env1"})
h.AssertNil(t, command.Execute())
})

it("forwards the exec-value (mix letters, numbers and .) into the client", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithExecEnv("env1.1")).
Return(nil)

command.SetArgs([]string{"image", "--builder", "my-builder", "--exec-env", "env1.1"})
h.AssertNil(t, command.Execute())
})

it("forwards the exec-value (mix letters, numbers and -) into the client", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithExecEnv("env-1")).
Return(nil)

command.SetArgs([]string{"image", "--builder", "my-builder", "--exec-env", "env-1"})
h.AssertNil(t, command.Execute())
})

it("forwards the exec-value (mix letters, numbers, . and -) into the client", func() {
mockClient.EXPECT().
Build(gomock.Any(), EqBuildOptionsWithExecEnv("env-1.1")).
Return(nil)

command.SetArgs([]string{"image", "--builder", "my-builder", "--exec-env", "env-1.1"})
h.AssertNil(t, command.Execute())
})
})

when("contains invalid characters", func() {
Expand Down

0 comments on commit f0a88d8

Please sign in to comment.