| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a1243d6 commit dd0de7c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ private NameParser() { | |||
| 22 | 22 | private static final int RepositoryNameTotalLengthMax = 255; | |
| 23 | 23 | ||
| 24 | 24 | private static final String SHA256_SEPARATOR = "@sha256:"; | |
| 25 | + private static final String COLON_SEPARATOR = ":"; | ||
| 25 | 26 | ||
| 26 | 27 | private static final Pattern RepositoryNameComponentRegexp = Pattern.compile("[a-z0-9]+(?:[._-][a-z0-9]+)*"); | |
| 27 | 28 | ||
@@ -106,6 +107,13 @@ public static HostnameReposName resolveRepositoryName(String reposName) { | |||
| 106 | 107 | String[] nameParts = reposName.split("/", 2); | |
| 107 | 108 | if (nameParts.length == 1 | |
| 108 | 109 | || (!nameParts[0].contains(".") && !nameParts[0].contains(":") && !nameParts[0].equals("localhost"))) { | |
| 110 | + if (StringUtils.containsIgnoreCase(reposName, SHA256_SEPARATOR)) { | ||
| 111 | + reposName = StringUtils.substringBeforeLast(reposName, SHA256_SEPARATOR); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + if (StringUtils.contains(reposName, COLON_SEPARATOR)) { | ||
| 115 | + reposName = StringUtils.substringBeforeLast(reposName, COLON_SEPARATOR); | ||
| 116 | + } | ||
| 109 | 117 | return new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, reposName); | |
| 110 | 118 | } | |
| 111 | 119 | ||
@@ -119,6 +127,10 @@ public static HostnameReposName resolveRepositoryName(String reposName) { | |||
| 119 | 127 | reposName = StringUtils.substringBeforeLast(reposName, SHA256_SEPARATOR); | |
| 120 | 128 | } | |
| 121 | 129 | ||
| 130 | + if (StringUtils.contains(reposName, COLON_SEPARATOR)) { | ||
| 131 | + reposName = StringUtils.substringBeforeLast(reposName, COLON_SEPARATOR); | ||
| 132 | + } | ||
| 133 | + | ||
| 122 | 134 | validateRepoName(reposName); | |
| 123 | 135 | return new HostnameReposName(hostname, reposName); | |
| 124 | 136 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,6 +83,24 @@ public void testResolveSimpleRepositoryName() { | |||
| 83 | 83 | assertEquals(new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "repository"), resolved); | |
| 84 | 84 | } | |
| 85 | 85 | ||
| 86 | + @Test | ||
| 87 | + public void testResolveRepositoryNameWithTag() { | ||
| 88 | + HostnameReposName resolved = NameParser.resolveRepositoryName("repository:tag"); | ||
| 89 | + assertEquals(new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "repository"), resolved); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Test | ||
| 93 | + public void testResolveRepositoryNameWithSHA256() { | ||
| 94 | + HostnameReposName resolved = NameParser.resolveRepositoryName("repository@sha256:sha256"); | ||
| 95 | + assertEquals(new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "repository"), resolved); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + @Test | ||
| 99 | + public void testResolveRepositoryNameWithTagAndSHA256() { | ||
| 100 | + HostnameReposName resolved = NameParser.resolveRepositoryName("repository:tag@sha256:sha256"); | ||
| 101 | + assertEquals(new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "repository"), resolved); | ||
| 102 | + } | ||
| 103 | + | ||
| 86 | 104 | @Test | |
| 87 | 105 | public void testResolveRepositoryNameWithNamespace() { | |
| 88 | 106 | HostnameReposName resolved = NameParser.resolveRepositoryName("namespace/repository"); | |
@@ -92,7 +110,7 @@ public void testResolveRepositoryNameWithNamespace() { | |||
| 92 | 110 | @Test | |
| 93 | 111 | public void testResolveRepositoryNameWithNamespaceAndSHA256() { | |
| 94 | 112 | HostnameReposName resolved = NameParser.resolveRepositoryName("namespace/repository@sha256:sha256"); | |
| 95 | - assertEquals(new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "namespace/repository@sha256:sha256"), resolved); | ||
| 113 | + assertEquals(new HostnameReposName(AuthConfig.DEFAULT_SERVER_ADDRESS, "namespace/repository"), resolved); | ||
| 96 | 114 | } | |
| 97 | 115 | ||
| 98 | 116 | @Test | |
@@ -107,6 +125,17 @@ public void testResolveRepositoryNameWithNamespaceAndHostnameAndSHA256() { | |||
| 107 | 125 | assertEquals(new HostnameReposName("localhost:5000", "namespace/repository"), resolved); | |
| 108 | 126 | } | |
| 109 | 127 | ||
| 128 | + @Test | ||
| 129 | + public void testResolveRepositoryNameWithNamespaceAndHostnameAndTag() { | ||
| 130 | + HostnameReposName resolved = NameParser.resolveRepositoryName("localhost:5000/namespace/repository:tag"); | ||
| 131 | + assertEquals(new HostnameReposName("localhost:5000", "namespace/repository"), resolved); | ||
| 132 | + } | ||
| 133 | + @Test | ||
| 134 | + public void testResolveRepositoryNameWithNamespaceAndHostnameAndTagAndSHA256() { | ||
| 135 | + HostnameReposName resolved = NameParser.resolveRepositoryName("localhost:5000/namespace/repository:tag@sha256:sha256"); | ||
| 136 | + assertEquals(new HostnameReposName("localhost:5000", "namespace/repository"), resolved); | ||
| 137 | + } | ||
| 138 | + | ||
| 110 | 139 | @Test(expected = InvalidRepositoryNameException.class) | |
| 111 | 140 | public void testResolveRepositoryNameWithIndex() { | |
| 112 | 141 | NameParser.resolveRepositoryName("index.docker.io/repository"); | |
@@ -147,4 +176,16 @@ public void testResolveReposTagWithSHA256() { | |||
| 147 | 176 | resolved = NameParser.parseRepositoryTag("localhost:5000/namespace/repository@sha256:sha256"); | |
| 148 | 177 | assertEquals(new ReposTag("localhost:5000/namespace/repository@sha256:sha256", ""), resolved); | |
| 149 | 178 | } | |
| 179 | + | ||
| 180 | + @Test | ||
| 181 | + public void testResolveReposTagWithTagAndSHA256() { | ||
| 182 | + ReposTag resolved = NameParser.parseRepositoryTag("repository:tag@sha256:sha256"); | ||
| 183 | + assertEquals(new ReposTag("repository:tag@sha256:sha256", ""), resolved); | ||
| 184 | + | ||
| 185 | + resolved = NameParser.parseRepositoryTag("namespace/repository:tag@sha256:sha256"); | ||
| 186 | + assertEquals(new ReposTag("namespace/repository:tag@sha256:sha256", ""), resolved); | ||
| 187 | + | ||
| 188 | + resolved = NameParser.parseRepositoryTag("localhost:5000/namespace/repository:tag@sha256:sha256"); | ||
| 189 | + assertEquals(new ReposTag("localhost:5000/namespace/repository:tag@sha256:sha256", ""), resolved); | ||
| 190 | + } | ||
| 150 | 191 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments