|
| 1 | +import { isValidDockerImageReference } from "../../lib/utils"; |
| 2 | + |
| 3 | +describe("isValidDockerImageReference", () => { |
| 4 | + describe("valid image references", () => { |
| 5 | + const validImages = [ |
| 6 | + "nginx", |
| 7 | + "ubuntu", |
| 8 | + "alpine", |
| 9 | + "nginx:latest", |
| 10 | + "ubuntu:20.04", |
| 11 | + "alpine:3.14", |
| 12 | + "library/nginx", |
| 13 | + "library/ubuntu:20.04", |
| 14 | + "docker.io/nginx", |
| 15 | + "docker.io/library/nginx:latest", |
| 16 | + "gcr.io/project-id/image-name", |
| 17 | + "gcr.io/project-id/image-name:tag", |
| 18 | + "registry.hub.docker.com/library/nginx", |
| 19 | + "localhost:5000/myimage", |
| 20 | + "localhost:5000/myimage:latest", |
| 21 | + "registry.example.com/path/to/image", |
| 22 | + "registry.example.com:8080/path/to/image:v1.0", |
| 23 | + "my-registry.com/my-namespace/my-image", |
| 24 | + "my-registry.com/my-namespace/my-image:v2.1.0", |
| 25 | + "nginx@sha256:abcd1234567890abcd1234567890abcd1234567890abcd1234567890abcd1234", |
| 26 | + "ubuntu:20.04@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef12", |
| 27 | + "image_name", |
| 28 | + "image.name", |
| 29 | + "image-name", |
| 30 | + "namespace/image_name.with-dots", |
| 31 | + "registry.com/namespace/image__double_underscore", |
| 32 | + "127.0.0.1:5000/test", |
| 33 | + "[::1]:5000/test", |
| 34 | + "registry.com/a/b/c/d/e/f/image", |
| 35 | + "a.b.c/namespace/image:tag", |
| 36 | + ]; |
| 37 | + |
| 38 | + it.each(validImages)( |
| 39 | + "should return true for valid image reference: %s", |
| 40 | + (imageName) => { |
| 41 | + expect(isValidDockerImageReference(imageName)).toBe(true); |
| 42 | + }, |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + describe("invalid image references", () => { |
| 47 | + const invalidImages = [ |
| 48 | + "/test:unknown", |
| 49 | + "//invalid", |
| 50 | + "invalid//path", |
| 51 | + "UPPERCASE", |
| 52 | + "Invalid:Tag", |
| 53 | + "registry.com/UPPERCASE/image", |
| 54 | + "registry.com/namespace/UPPERCASE", |
| 55 | + "", |
| 56 | + "image:", |
| 57 | + ":tag", |
| 58 | + "image::", |
| 59 | + "registry.com:", |
| 60 | + "registry.com:/image", |
| 61 | + "image@", |
| 62 | + "image@sha256:", |
| 63 | + "image@invalid:digest", |
| 64 | + "registry.com//namespace/image", |
| 65 | + "registry.com/namespace//image", |
| 66 | + ".image", |
| 67 | + "image.", |
| 68 | + "-image", |
| 69 | + "image-", |
| 70 | + "_image", |
| 71 | + "image_", |
| 72 | + "registry-.com/image", |
| 73 | + "registry.com-/image", |
| 74 | + "image:tag@", |
| 75 | + "image:tag@sha256", |
| 76 | + "registry.com:abc/image", |
| 77 | + "registry.com:-1/image", |
| 78 | + ]; |
| 79 | + |
| 80 | + it.each(invalidImages)( |
| 81 | + "should return false for invalid image reference: %s", |
| 82 | + (imageName) => { |
| 83 | + expect(isValidDockerImageReference(imageName)).toBe(false); |
| 84 | + }, |
| 85 | + ); |
| 86 | + }); |
| 87 | +}); |
0 commit comments