Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add validation for environment variables #140

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pkg/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,31 @@ func validateName(name string) error {
return nil
}

func (e *EnvVariable) validate() error {
// TODO: add more validation tests besides checking for '='
if strings.Contains(e.Key, "=") {
return fmt.Errorf("Illegal character '=' in environment variable key: %v", e.Key)
}

if strings.Contains(e.Value, "=") {
return fmt.Errorf("Illegal character '=' in environment variable value: %v", e.Value)
}
return nil
}

func (c *Container) validate() error {

// validate image name
// TODO: implement me
// validate Environment
// TODO: implement me
// validate Ports
// TODO: implement me

for _, env := range c.Environment {
if err := env.validate(); err != nil {
return fmt.Errorf("failed to validate environment variable: %v", err)
}
}

allMounts := make(map[string]string)
// validate Mounts
for _, mount := range c.Mounts {
Expand Down
36 changes: 36 additions & 0 deletions pkg/object/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,42 @@ func TestContainer_Validate(t *testing.T) {
},
},
},
{
"passing '=' in environment variable key",
false,
&Container{
Environment: []EnvVariable{
{
Key: "ke=y",
Value: "value",
},
},
},
},
{
"passing '=' in environment variable value",
false,
&Container{
Environment: []EnvVariable{
{
Key: "key",
Value: "va=lue",
},
},
},
},
{
"passing a valid environment variable",
true,
&Container{
Environment: []EnvVariable{
{
Key: "key",
Value: "value",
},
},
},
},
}

for _, test := range tests {
Expand Down