-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test (jkube-kit) : Add ImageName upstream compatibility tests
Add tests for ImageName for ORAS reference and Docker Distribution reference. Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
275dc11
commit 19c97fc
Showing
2 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
.../src/test/java/org/eclipse/jkube/kit/config/image/ImageNameDistributionReferenceTest.java
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.config.image; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
/** | ||
* Tests ported from <a href="https://github.com/distribution/reference/blob/main/reference_test.go">Distribution Reference</a> | ||
*/ | ||
class ImageNameDistributionReferenceTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"test.com/foo", | ||
"test:8080/foo", | ||
"docker.io/library/foo", | ||
"test_com", | ||
"test.com:tag", | ||
"test.com:5000", | ||
"test.com/repo:tag", | ||
"test:5000/repo", | ||
"test:5000/repo:tag", | ||
"lowercase:Uppercase", | ||
"test:5000/repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"test:5000/repo:tag@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"sub-dom1.foo.com/bar/baz/quux", | ||
"sub-dom1.foo.com/bar/baz/quux:some-long-tag", | ||
"b.gcr.io/test.example.com/my-app:test.example.com", | ||
"xn--n3h.com/myimage:xn--n3h.com", | ||
//"xn--7o8h.com/myimage:xn--7o8h.com@sha512:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // Digest SHA 512 | ||
"foo_bar.com:8080", | ||
"foo/foo_bar.com:8080", | ||
"192.168.1.1", | ||
"192.168.1.1:tag", | ||
"192.168.1.1:5000", | ||
"192.168.1.1/repo", | ||
"192.168.1.1:5000/repo", | ||
"192.168.1.1:5000/repo:5050", | ||
"a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/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-puts-this-over-max", | ||
"docker/docker", | ||
"library/debian", | ||
"debian", | ||
"localhost/library/debian", | ||
"localhost/debian", | ||
"docker.io/docker/docker", | ||
"docker.io/library/debian", | ||
"docker.io/debian", | ||
"index.docker.io/docker/docker", | ||
"index.docker.io/library/debian", | ||
"index.docker.io/debian", | ||
"127.0.0.1:5000/docker/docker", | ||
"127.0.0.1:5000/library/debian", | ||
"127.0.0.1:5000/debian", | ||
"192.168.0.1", | ||
"192.168.0.1:80", | ||
"192.168.0.1:8/debian", | ||
"192.168.0.2:25000/debian", | ||
"docker.io/1a3f5e7d9c1b3a5f7e9d1c3b5a7f9e1d3c5b7a9f1e3d5d7c9b1a3f5e7d9c1b3a", | ||
//"[2001:db8::1]/repo", // Ipv6 | ||
//"[2001:db8:1:2:3:4:5:6]/repo:tag", // Ipv6 | ||
//"[2001:db8::1]:5000/repo", // Ipv6 | ||
//"[2001:db8::1]:5000/repo:tag", // Ipv6 | ||
//"[2001:db8::1]:5000/repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // Ipv6 | ||
//"[2001:db8::1]:5000/repo:tag@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // Ipv6 | ||
//"[2001:db8::]:5000/repo", // Ipv6 | ||
//"[::1]:5000/repo", // Ipv6 | ||
}) | ||
void validNames(String name) { | ||
// Given | ||
ImageName imageName = new ImageName(name); | ||
|
||
// When + Then | ||
assertThat(imageName).isNotNull(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"", | ||
":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", // Image Name length exceeding 255 | ||
//"repo@sha256:ffffffffffffffffffffffffffffffffff", // Invalid digest length | ||
"validname@invaliddigest:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
"Uppercase:tag", | ||
"test:5000/Uppercase/lowercase:tag", | ||
"aa/asdf$$^/aa", | ||
"[fe80::1%eth0]:5000/repo", // Invalid Ipv6 addresses - these are failing because we only support IPv4 at the moment | ||
"[fe80::1%@invalidzone]:5000/repo", // Invalid Ipv6 addresses - these are failing because we only support IPv4 at the moment | ||
}) | ||
void invalidNames(String name) { | ||
assertThatIllegalArgumentException().isThrownBy(() -> new ImageName(name)); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ig/image/src/test/java/org/eclipse/jkube/kit/config/image/ImageNameORASReferenceTest.java
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.config.image; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
/** | ||
* Tests ported from <a href="https://github.com/oras-project/oras-go/blob/main/registry/reference_test.go">ORAS Reference</a> | ||
*/ | ||
class ImageNameORASReferenceTest { | ||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"localhost/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"localhost/hello-world:v1", | ||
"localhost/hello-world", | ||
"registry.example.com/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"registry.example.com/hello-world:v1", | ||
"registry.example.com/hello-world", | ||
"localhost:5000/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"localhost:5000/hello-world:v1", | ||
"localhost:5000/hello-world", | ||
"127.0.0.1:5000/hello-world@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"127.0.0.1:5000/hello-world:v1", | ||
"127.0.0.1:5000/hello-world", | ||
"localhost/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"registry.example.com/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"localhost:5000/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
"127.0.0.1:5000/hello-world:v2@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", | ||
//"[::1]:5000/hello-world:v1", // IPv6 IP address in registry (works with ORAS) | ||
//"registry.example.com/hello-world:@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // both tag and digest (works with ORAS, tag is dropped) | ||
}) | ||
void validImageNamesCompatibleWithAll(String name) { | ||
// Given + When | ||
ImageName imageName = new ImageName(name); | ||
|
||
// Then | ||
assertThat(imageName).isNotNull(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"localhost/UPPERCASE/test", // Invalid repo name | ||
"localhost:v1/hello-world", // Invalid port | ||
"registry.example.com/hello-world:foobar:sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // Invalid Digest prefix: colon instead of the at sign | ||
"registry.example.com/hello-world@@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // Invalid Digest prefix: double at sign | ||
"registry.example.com/hello-world @sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9", // Invalid Digest prefix: space | ||
//"registry.example.com/foobar@sha256:b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde" // Invalid Digest (Should fail, but we don't check digest) | ||
}) | ||
void invalidImageNames(String name) { | ||
assertThatIllegalArgumentException().isThrownBy(() -> new ImageName(name)); | ||
} | ||
} |