-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
prevent slashes in object names #1847
Merged
openshift-bot
merged 2 commits into
openshift:master
from
deads2k:deads-prevent-slashes
Apr 23, 2015
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import ( | |
|
||
func TestValidateImageOK(t *testing.T) { | ||
errs := ValidateImage(&api.Image{ | ||
ObjectMeta: kapi.ObjectMeta{Name: "foo", Namespace: "default"}, | ||
ObjectMeta: kapi.ObjectMeta{Name: "foo"}, | ||
DockerImageReference: "openshift/ruby-19-centos", | ||
}) | ||
if len(errs) > 0 { | ||
|
@@ -29,7 +29,17 @@ func TestValidateImageMissingFields(t *testing.T) { | |
"missing Name": { | ||
api.Image{DockerImageReference: "ref"}, | ||
fielderrors.ValidationErrorTypeRequired, | ||
"name", | ||
"metadata.name", | ||
}, | ||
"no slash in Name": { | ||
api.Image{ObjectMeta: kapi.ObjectMeta{Name: "foo/bar"}}, | ||
fielderrors.ValidationErrorTypeInvalid, | ||
"metadata.name", | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test % too? |
||
"no percent in Name": { | ||
api.Image{ObjectMeta: kapi.ObjectMeta{Name: "foo%%bar"}}, | ||
fielderrors.ValidationErrorTypeInvalid, | ||
"metadata.name", | ||
}, | ||
"missing DockerImageReference": { | ||
api.Image{ObjectMeta: kapi.ObjectMeta{Name: "foo"}}, | ||
|
@@ -122,14 +132,11 @@ func TestValidateImageStreamMappingNotOK(t *testing.T) { | |
DockerImageRepository: "openshift/ruby-19-centos", | ||
Tag: "latest", | ||
Image: api.Image{ | ||
ObjectMeta: kapi.ObjectMeta{ | ||
Namespace: "default", | ||
}, | ||
DockerImageReference: "openshift/ruby-19-centos", | ||
}, | ||
}, | ||
fielderrors.ValidationErrorTypeRequired, | ||
"image.name", | ||
"image.metadata.name", | ||
}, | ||
"invalid repository pull spec": { | ||
api.ImageStreamMapping{ | ||
|
@@ -183,21 +190,35 @@ func TestValidateImageStream(t *testing.T) { | |
namespace: "foo", | ||
name: "", | ||
expected: fielderrors.ValidationErrorList{ | ||
fielderrors.NewFieldRequired("name"), | ||
fielderrors.NewFieldRequired("metadata.name"), | ||
}, | ||
}, | ||
"no slash in Name": { | ||
namespace: "foo", | ||
name: "foo/bar", | ||
expected: fielderrors.ValidationErrorList{ | ||
fielderrors.NewFieldInvalid("metadata.name", "foo/bar", `may not contain "/"`), | ||
}, | ||
}, | ||
"no percent in Name": { | ||
namespace: "foo", | ||
name: "foo%%bar", | ||
expected: fielderrors.ValidationErrorList{ | ||
fielderrors.NewFieldInvalid("metadata.name", "foo%%bar", `may not contain "%"`), | ||
}, | ||
}, | ||
"missing namespace": { | ||
namespace: "", | ||
name: "foo", | ||
expected: fielderrors.ValidationErrorList{ | ||
fielderrors.NewFieldInvalid("namespace", "", ""), | ||
fielderrors.NewFieldRequired("metadata.namespace"), | ||
}, | ||
}, | ||
"invalid namespace": { | ||
namespace: "!$", | ||
name: "foo", | ||
expected: fielderrors.ValidationErrorList{ | ||
fielderrors.NewFieldInvalid("namespace", "!$", ""), | ||
fielderrors.NewFieldInvalid("metadata.namespace", "!$", `must have at most 253 characters and match regex [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`), | ||
}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding tests for names with % and / in them? |
||
"invalid dockerImageRepository": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need this for every other resource type as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of. All the name validators need to at least limit those characters. The others I know about are more restrictive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a lot are using ValidatePodName and others are using custom funcs that handle % and / and other characters. It'd be nice to have a single common func that all validations could use to check the bare minimum, and then custom logic could be added after that. But I don't think it's required for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first attempt as rejected because it was too broad. My second attempt failed because our main validation package would become cyclic. I decided I'd rather get enough in to stop us from failing before attempting a more consistent change again.