Skip to content
Permalink
Browse files

Merge pull request #56 from liebowitz/master

[JENKINS-39181] Invalid fully qualified image name when registry URL specified
  • Loading branch information
oleg-nenashev committed Jan 11, 2017
2 parents 9d298f8 + acd1a92 commit 8edbc8ed06d2f9164fd00fe9be9cf39fa4dd78f8
@@ -228,14 +228,22 @@ public KeyMaterialFactory newKeyMaterialFactory(@CheckForNull Item context, @Non
* @return the full registry:port/namespace/name string
* @throws IOException
*/
public String imageName(String userAndRepo) throws IOException {
if (url==null) return userAndRepo;
public String imageName(@Nonnull String userAndRepo) throws IOException {
if (userAndRepo == null) {
throw new IllegalArgumentException("Image name cannot be null.");
}
if (url == null) {
return userAndRepo;
}
URL effectiveUrl = getEffectiveUrl();

StringBuilder s = new StringBuilder(effectiveUrl.getHost());
if (effectiveUrl.getPort() > 0 && effectiveUrl.getDefaultPort() != effectiveUrl.getPort()) {
s.append(':').append(effectiveUrl.getPort());
}
if (userAndRepo.startsWith(String.valueOf(s))) {
return userAndRepo;
}
return s.append('/').append(userAndRepo).toString();
}

@@ -28,6 +28,7 @@
import java.io.IOException;

import org.junit.Test;
import org.jvnet.hudson.test.Issue;

/**
* @author Carlos Sanchez <carlos@apache.org>
@@ -52,6 +53,25 @@ public void testParseWithTags() throws Exception {
assertRegistry("https://docker.acme.com", "docker.acme.com/busybox:tag");
}

@Issue("JENKINS-39181")
@Test
public void testParseFullyQualifiedImageName() throws Exception {
assertEquals("private-repo:5000/test-image", new DockerRegistryEndpoint("http://private-repo:5000/", null).imageName("private-repo:5000/test-image"));
assertEquals("private-repo:5000/test-image", new DockerRegistryEndpoint("http://private-repo:5000/", null).imageName("test-image"));
}

@Issue("JENKINS-39181")
@Test(expected = IllegalArgumentException.class)
public void testParseNullImageName() throws Exception {
new DockerRegistryEndpoint("http://private-repo:5000/", null).imageName(null);
}

@Issue("JENKINS-39181")
@Test(expected = IllegalArgumentException.class)
public void testParseNullUrlAndImageName() throws Exception {
new DockerRegistryEndpoint(null, null).imageName(null);
}

private void assertRegistry(String url, String repo) throws IOException {
assertEquals(url, DockerRegistryEndpoint.fromImageName(repo, null).getEffectiveUrl().toString());
}

0 comments on commit 8edbc8e

Please sign in to comment.
You can’t perform that action at this time.