Skip to content

Commit aab3156

Browse files
authored
Ensure to URI escape service name (#623)
Signed-off-by: Valentin Delaye <jonesbusy@users.noreply.github.com>
1 parent cd32199 commit aab3156

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/main/java/land/oras/auth/HttpClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ public <T> TokenResponse refreshToken(
411411

412412
LOG.debug("WWW-Authenticate header: realm={}, service={}, scope={}, error={}", realm, service, scope, error);
413413

414-
URI uri = URI.create(realm + "?scope=" + scope + "&service=" + service);
414+
String query = "scope=%s&service=%s".formatted(scope, URLEncoder.encode(service, StandardCharsets.UTF_8));
415+
416+
URI uri = URI.create(realm + "?" + query);
415417

416418
// Perform the request to get the token
417419
Map<String, String> headers = new HashMap<>();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*-
2+
* =LICENSE=
3+
* ORAS Java SDK
4+
* ===
5+
* Copyright (C) 2024 - 2026 ORAS
6+
* ===
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* =LICENSEEND=
19+
*/
20+
21+
package land.oras;
22+
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
25+
import java.nio.file.Path;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.io.TempDir;
28+
29+
class OracleContainerRegistryITCase {
30+
31+
@TempDir
32+
private Path tempDir;
33+
34+
@Test
35+
void shouldPullManifest() {
36+
Registry registry = Registry.builder().build();
37+
ContainerRef containerRef1 = ContainerRef.parse("container-registry.oracle.com/os/oraclelinux:latest");
38+
Manifest manifest = registry.getManifest(containerRef1);
39+
assertNotNull(manifest);
40+
}
41+
42+
@Test
43+
void shouldPullOneBlob() {
44+
Registry registry = Registry.builder().build();
45+
ContainerRef containerRef1 = ContainerRef.parse(
46+
"container-registry.oracle.com/os/oraclelinux@sha256:50ab38810635947eebaa66f1d3b551fcb5a28cc372dd3022805d83618fb59c02");
47+
registry.fetchBlob(containerRef1, tempDir.resolve("my-blob"));
48+
assertNotNull(tempDir.resolve("my-blob"));
49+
}
50+
}

0 commit comments

Comments
 (0)