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 #2585

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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class ImageName {
// Digest
private String digest;

private static final int REPO_NAME_MAX_LENGTH = 255;

/**
* Create an image name
*
Expand Down Expand Up @@ -279,6 +281,11 @@ private void doValidate() {
"tag", TAG_REGEXP, tag,
"digest", DIGEST_REGEXP, digest
};

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

for (int i = 0; i < checks.length; i +=3) {
String value = (String) checks[i + 2];
Pattern checkPattern = (Pattern) checks[i + 1];
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",
//"repo@sha256:ffffffffffffffffffffffffffffffffff", // https://github.com/eclipse/jkube/issues/2543
"validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"Uppercase:tag",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.image;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -125,6 +125,17 @@ void testIllegalFormat() {
assertThrows(IllegalArgumentException.class, () -> new ImageName(""));
}


@Test
@DisplayName("too long repository name, should throw exception")
void shouldThrowExceptionOnTooLongImageName() {
String tooLongName = StringUtils.repeat("a", 256);
assertThatIllegalArgumentException()
.as("Too long image name should fail")
.isThrownBy(() -> new ImageName(tooLongName))
.withMessageContaining("Repository name must not be more than 255 characters");
}

@Test
void namesUsedByDockerTests() {
StringBuilder longTag = new StringBuilder();
Expand Down
Loading