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 check for image name length to not exceed 255 #2555

Closed
Show file tree
Hide file tree
Changes from 14 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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class ImageName {
// Digest
private String digest;

private static final int REPO_NAME_MAX_LENGTH = 255;


/**
* Create an image name
*
Expand Down Expand Up @@ -272,13 +275,16 @@ private void doValidate() {
// Strip off user from repository name
String user = inferUser();
String image = user != null ? repository.substring(user.length() + 1) : repository;

Object[] checks = new Object[] {
"registry", DOMAIN_REGEXP, registry,
"image", IMAGE_NAME_REGEXP, image,
"user", NAME_COMP_REGEXP, user,
"tag", TAG_REGEXP, tag,
"digest", DIGEST_REGEXP, digest

};

for (int i = 0; i < checks.length; i +=3) {
String value = (String) checks[i + 2];
Pattern checkPattern = (Pattern) checks[i + 1];
Expand All @@ -288,6 +294,11 @@ private void doValidate() {
checks[i], value, checkPattern.pattern()));
}
}

if (repository.length() > REPO_NAME_MAX_LENGTH) {
errors.add(String.format("Repository name must not be more than %d characters", REPO_NAME_MAX_LENGTH));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add one more test in ImageNameTest for verifying exception with this exact message is thrown when too long image name is provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add one more test in ImageNameTest for verifying exception with this exact message is thrown when too long image name is provided?

Ya sure

}

if (!errors.isEmpty()) {
StringBuilder buf = new StringBuilder();
buf.append(String.format("Given Docker name '%s' is invalid:%n", getFullName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void validNames(String name) {
"",
":justtag",
"@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
//"a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a:tag", // https://github.com/eclipse/jkube/issues/2542
"a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a:tag", // https://github.com/eclipse/jkube/issues/2542
//"repo@sha256:ffffffffffffffffffffffffffffffffff", // https://github.com/eclipse/jkube/issues/2543
"validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"Uppercase:tag",
Expand Down
Loading