Skip to content

Commit

Permalink
Updated regex and test cases with negative cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh Gupta committed Nov 1, 2022
1 parent 5a780f0 commit 8908375
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -208,7 +208,7 @@ public class DockerLinuxContainerRuntime extends OCIContainerRuntime {
private static final Pattern dockerImagePattern =
Pattern.compile(DOCKER_IMAGE_PATTERN);

private static final Pattern DOCKER_DIGEST_PATTERN = Pattern.compile("^sha256:[a-z0-9]{32,}$");
private static final Pattern DOCKER_DIGEST_PATTERN = Pattern.compile("^sha256:[a-z0-9]{12,64}$");

private static final String DEFAULT_PROCFS = "/proc";

Expand Down
Expand Up @@ -2042,7 +2042,18 @@ public void testDockerImageNamePattern() throws Exception {
+ "@sha256:f1d4ae3f7261a72e98c6ebefe9985cf10a0ea5bd762585a43e0700ed99863807"};

String[] invalidNames = {"Ubuntu", "ubuntu || fedora", "ubuntu#", "myregistryhost:50AB0/ubuntu",
"myregistry#host:50AB0/ubuntu", ":8080/ubuntu"};
"myregistry#host:50AB0/ubuntu", ":8080/ubuntu",

// Invalid: contains "@sha256" but doesn't really contain a digest.
"123456789123.dkr.ecr.us-east-1.amazonaws.com/emr-docker-examples:pyspark-example@sha256",

// Invalid: digest is too short.
"123456789123.dkr.ecr.us-east-1.amazonaws.com/emr-docker-examples:pyspark-example"
+ "@sha256:f1d4",

// Invalid: digest is too long
"123456789123.dkr.ecr.us-east-1.amazonaws.com/emr-docker-examples:pyspark-example"
+ "@sha256:f1d4ae3f7261a72e98c6ebefe9985cf10a0ea5bd762585a43e0700ed99863807f"};

for (String name : validNames) {
DockerLinuxContainerRuntime.validateImageName(name);
Expand Down

0 comments on commit 8908375

Please sign in to comment.