diff --git a/pom.xml b/pom.xml index 46e4cbc7..2eda22a7 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,6 @@ 4.3.0 - 2.74.0 3.6.1 0.8.15 3.10.0 @@ -601,15 +600,14 @@ ${spotless-maven-plugin.version} + + true - - - ${palantir.java.format.version} - + diff --git a/src/main/java/land/oras/Registry.java b/src/main/java/land/oras/Registry.java index 376b617c..3b97c637 100644 --- a/src/main/java/land/oras/Registry.java +++ b/src/main/java/land/oras/Registry.java @@ -22,6 +22,7 @@ import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import java.io.ByteArrayInputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; @@ -1176,7 +1177,7 @@ private String uploadChunks(ContainerRef ref, InputStream stream, long totalSize Const.APPLICATION_OCTET_STREAM_HEADER_VALUE, Const.CONTENT_RANGE_HEADER, contentRange), - () -> new java.io.ByteArrayInputStream(chunk), + () -> new ByteArrayInputStream(chunk), Scopes.of(ref), authProvider); logResponse(patchResponse); diff --git a/src/main/java/land/oras/Tags.java b/src/main/java/land/oras/Tags.java index 588f24cc..e308e963 100644 --- a/src/main/java/land/oras/Tags.java +++ b/src/main/java/land/oras/Tags.java @@ -35,7 +35,11 @@ @NullMarked @OrasModel @JsonInclude(JsonInclude.Include.NON_NULL) -public record Tags(String name, List tags, @Nullable String last, @Nullable Integer n) { +public record Tags( + String name, + List tags, + @Nullable String last, + @Nullable Integer n) { /** * Constructor without last diff --git a/src/main/java/land/oras/auth/HttpClient.java b/src/main/java/land/oras/auth/HttpClient.java index b3f10cab..3c1e1a71 100644 --- a/src/main/java/land/oras/auth/HttpClient.java +++ b/src/main/java/land/oras/auth/HttpClient.java @@ -20,14 +20,22 @@ package land.oras.auth; +// spotless:off +// Until https://github.com/diffplug/spotless/issues/3033 import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Timer; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; -import java.net.*; +import java.net.CookieManager; +import java.net.CookiePolicy; +import java.net.HttpURLConnection; +import java.net.Socket; +import java.net.URI; +import java.net.URLEncoder; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpTimeoutException; @@ -66,6 +74,7 @@ import org.jspecify.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// spotless:on /** * HTTP client for ORAS @@ -87,12 +96,15 @@ public final class HttpClient { /** * The HTTP client builder */ + // spotless:off + // Until https://github.com/diffplug/spotless/issues/3033 private final java.net.http.HttpClient.Builder builder; /** * The HTTP client */ private java.net.http.HttpClient client; + // spotless:on /** * Skip TLS verification @@ -834,7 +846,7 @@ private static boolean isRetryableStatus(int statusCode) { } private static boolean isRetryableException(Exception e) { - return e instanceof HttpTimeoutException || e instanceof java.io.IOException; + return e instanceof HttpTimeoutException || e instanceof IOException; } private long computeRetryDelay(@Nullable HttpResponse response, int attempt) { @@ -989,7 +1001,10 @@ private void logRequest(HttpRequest request, byte[] body) { * @param service The service (not on response but on HTTP headers) */ public record ResponseWrapper( - T response, int statusCode, Map headers, @Nullable String service) {} + T response, + int statusCode, + Map headers, + @Nullable String service) {} /** * Insecure trust manager when skipping TLS verification diff --git a/src/main/java/land/oras/auth/RegistriesConf.java b/src/main/java/land/oras/auth/RegistriesConf.java index 2dcbf1e1..93273a7f 100644 --- a/src/main/java/land/oras/auth/RegistriesConf.java +++ b/src/main/java/land/oras/auth/RegistriesConf.java @@ -329,7 +329,9 @@ record ConfigFile( @JsonProperty("short-name-mode") @Nullable ShortNameMode shortNameMode, @JsonProperty("registry") @Nullable List registries, @JsonProperty("aliases") @Nullable Map aliases, - @JsonProperty("unqualified-search-registries") @Nullable List unqualifiedRegistries) {} + + @JsonProperty("unqualified-search-registries") @Nullable + List unqualifiedRegistries) {} /** * Get the list of unqualified registries. diff --git a/src/main/java/land/oras/policy/SigstoreVerifier.java b/src/main/java/land/oras/policy/SigstoreVerifier.java index a38b6017..adc6a8dd 100644 --- a/src/main/java/land/oras/policy/SigstoreVerifier.java +++ b/src/main/java/land/oras/policy/SigstoreVerifier.java @@ -30,6 +30,7 @@ import java.security.PublicKey; import java.security.Signature; import java.security.spec.X509EncodedKeySpec; +import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Map; @@ -287,7 +288,7 @@ static byte[] preAuthEncoding(String payloadType, byte[] payload) { * @return a non-null (possibly empty) list of successfully loaded public keys. */ static List loadKeys(PolicyRequirement.SigstoreSigned requirement) { - java.util.List keys = new java.util.ArrayList<>(); + List keys = new ArrayList<>(); // Single-key fields PublicKey single = loadKey(requirement); @@ -391,7 +392,8 @@ record DsseSignature(@JsonProperty("sig") @Nullable String sig) {} * @param subject The subject */ @OrasModel - record InTotoStatement(@JsonProperty("subject") @Nullable List subject) {} + record InTotoStatement( + @JsonProperty("subject") @Nullable List subject) {} /** * An in-toto subject: a map of digest algorithm to hex value diff --git a/src/test/java/land/oras/ContainerRefTest.java b/src/test/java/land/oras/ContainerRefTest.java index 559324f4..584bda86 100644 --- a/src/test/java/land/oras/ContainerRefTest.java +++ b/src/test/java/land/oras/ContainerRefTest.java @@ -40,8 +40,7 @@ class ContainerRefTest { @Execution(ExecutionMode.SAME_THREAD) void shouldReadRegistriesConfig(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] location = "public.ecr.aws" blocked = true @@ -82,8 +81,7 @@ void shouldReadRegistriesConfig(@TempDir Path homeDir) throws Exception { void shouldDetermineFromAlias(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [aliases] "my-library/my-namespace"="localhost:5000/test" "my-library"="localhost:5000/test2" @@ -105,8 +103,7 @@ void shouldDetermineFromAlias(@TempDir Path homeDir) throws Exception { void shouldRewriteAllSubdomainToLocalProxy(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] prefix = "*.example.com" location = "localhost:5000/example-com" diff --git a/src/test/java/land/oras/DockerIoITCase.java b/src/test/java/land/oras/DockerIoITCase.java index 2251da8c..d4a12040 100644 --- a/src/test/java/land/oras/DockerIoITCase.java +++ b/src/test/java/land/oras/DockerIoITCase.java @@ -149,8 +149,7 @@ void shouldContainsCommonLinuxPlatform() { void shouldCopyTagToInternalRegistryViaAlias(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [aliases] "dockerhub-alpine" = "docker.io/library/alpine" """; diff --git a/src/test/java/land/oras/GitHubContainerRegistryITCase.java b/src/test/java/land/oras/GitHubContainerRegistryITCase.java index da99aad3..a368e11d 100644 --- a/src/test/java/land/oras/GitHubContainerRegistryITCase.java +++ b/src/test/java/land/oras/GitHubContainerRegistryITCase.java @@ -85,17 +85,14 @@ void shouldPullSignedImage(@TempDir Path homeDir) throws Exception { Path publicKeyPath = Path.of("src/test/resources/keys/sigstore/alpine-signed.pub"); // language=toml - String config = - """ + String config = """ [[registry]] location = "ghcr.io" insecure = false """; // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -104,8 +101,7 @@ void shouldPullSignedImage(@TempDir Path homeDir) throws Exception { } } } - """ - .formatted(publicKeyPath.toAbsolutePath().toString())); + """.formatted(publicKeyPath.toAbsolutePath().toString())); ContainersPolicy policy = ContainersPolicy.newPolicy(path); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -120,8 +116,7 @@ void shouldPullSignedImage(@TempDir Path homeDir) throws Exception { @Execution(ExecutionMode.SAME_THREAD) void shouldPullIndexWithAlias(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [aliases] "oras"="ghcr.io/oras-project/oras" """; diff --git a/src/test/java/land/oras/HarborS3ITCase.java b/src/test/java/land/oras/HarborS3ITCase.java index a181e15f..3fe600e8 100644 --- a/src/test/java/land/oras/HarborS3ITCase.java +++ b/src/test/java/land/oras/HarborS3ITCase.java @@ -178,8 +178,7 @@ void shouldPushJenkinsLibArtifact() { void shouldPushJenkinsScriptArtifact() { // language=groovy - String jenkinsfile = - """ + String jenkinsfile = """ node { stage('Build') { echo 'Building...' diff --git a/src/test/java/land/oras/LayerTest.java b/src/test/java/land/oras/LayerTest.java index 76e33f83..8be4cbea 100644 --- a/src/test/java/land/oras/LayerTest.java +++ b/src/test/java/land/oras/LayerTest.java @@ -77,8 +77,7 @@ void shouldHaveEmptyLayer() { @Test void shouldReadNullAnnotations() { - String json = - """ + String json = """ { "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip", "digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", @@ -94,8 +93,7 @@ void shouldReadNullAnnotations() { @Test void shouldReadBlobData() { - String json = - """ + String json = """ { "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip", "digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", @@ -155,14 +153,12 @@ private String emptyLayer() { * @return The manifest */ private String sampleLayer() { - return Layer.fromJson( - """ + return Layer.fromJson(""" { "mediaType": "application/vnd.oci.image.layer.v1.tar+gzip", "digest": "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", "size": 32654 } - """) - .toJson(); + """).toJson(); } } diff --git a/src/test/java/land/oras/OCILayoutTest.java b/src/test/java/land/oras/OCILayoutTest.java index 849b0673..b2e39734 100644 --- a/src/test/java/land/oras/OCILayoutTest.java +++ b/src/test/java/land/oras/OCILayoutTest.java @@ -166,9 +166,7 @@ void shouldPushSignedLayoutAndPullItAndValidateSignature(@TempDir Path homeDir) Path policyPath = homeDir.resolve("policy.json"); // language=json - Files.writeString( - policyPath, - """ + Files.writeString(policyPath, """ { "default": [{"type": "reject"}], "transports": { @@ -177,8 +175,7 @@ void shouldPushSignedLayoutAndPullItAndValidateSignature(@TempDir Path homeDir) } } } - """ - .formatted(registry.getRegistry(), publicKeyPath.toAbsolutePath())); + """.formatted(registry.getRegistry(), publicKeyPath.toAbsolutePath())); ContainersPolicy policy = ContainersPolicy.newPolicy(policyPath); // Pull the manifest with the policy: the attached signature is fetched and verified. diff --git a/src/test/java/land/oras/PlatformTest.java b/src/test/java/land/oras/PlatformTest.java index 52455d5a..171b6c4a 100644 --- a/src/test/java/land/oras/PlatformTest.java +++ b/src/test/java/land/oras/PlatformTest.java @@ -112,8 +112,7 @@ void shouldTestUnknownPlatform() { @Test void shouldReadFromJson() { // language=json - String json = - """ + String json = """ { "architecture": "amd64", "os": "linux" @@ -125,8 +124,7 @@ void shouldReadFromJson() { assertNull(platform.variant()); assertEquals(Platform.linuxAmd64(), platform); - json = - """ + json = """ { "architecture": "unknown", "os": "unknown" @@ -139,8 +137,7 @@ void shouldReadFromJson() { @Test void shouldReadFromJsonWithOptionalValues() { // language=json - String json = - """ + String json = """ { "architecture": "amd64", "variant": "v8", @@ -164,8 +161,7 @@ void shouldReadFromJsonWithOptionalValues() { .withVariant("v8"), platform); - json = - """ + json = """ { "architecture": "unknown", "os": "unknown" diff --git a/src/test/java/land/oras/PublicECRITCase.java b/src/test/java/land/oras/PublicECRITCase.java index bbc29b6a..7e6094df 100644 --- a/src/test/java/land/oras/PublicECRITCase.java +++ b/src/test/java/land/oras/PublicECRITCase.java @@ -60,8 +60,7 @@ void shouldDetermineEffectiveRegistryWithUnqualifiedSettings() throws Exception void shouldRewriteDockerIOToPublicECR() throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] prefix = "docker.io/library" location = "public.ecr.aws/docker/library" diff --git a/src/test/java/land/oras/RegistryMirrorTest.java b/src/test/java/land/oras/RegistryMirrorTest.java index 2d1f8e55..9c9a5249 100644 --- a/src/test/java/land/oras/RegistryMirrorTest.java +++ b/src/test/java/land/oras/RegistryMirrorTest.java @@ -70,8 +70,7 @@ void shouldFetchManifestViaMirrorWhenOriginalIsDown(@TempDir Path blobDir) throw // mirror 1: localhost:59999 (down, connection refused) // mirror 2: the running mirrorUp container // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -83,8 +82,7 @@ void shouldFetchManifestViaMirrorWhenOriginalIsDown(@TempDir Path blobDir) throw [[registry.mirror]] location = "%s" insecure = true - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -107,8 +105,7 @@ void shouldPullArtifactViaMirrorWhenOriginalIsDown(@TempDir Path blobDir, @TempD setupRegistry.pushArtifact(mirrorArtifact, LocalPath.of(testFile)); // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -120,8 +117,7 @@ void shouldPullArtifactViaMirrorWhenOriginalIsDown(@TempDir Path blobDir, @TempD [[registry.mirror]] location = "%s" insecure = true - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -147,8 +143,7 @@ void shouldFetchManifestViaInsecurePathPrefixedMirror(@TempDir Path blobDir) thr // Mirror location includes a path prefix → covers mirrorLocation.contains("/") branch. // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -156,8 +151,7 @@ void shouldFetchManifestViaInsecurePathPrefixedMirror(@TempDir Path blobDir) thr [[registry.mirror]] location = "%s/prefix" insecure = true - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -182,8 +176,7 @@ void shouldFetchBlobViaMirrorWhenOriginalIsDown(@TempDir Path blobDir, @TempDir Layer layer = setupRegistry.pushBlob(mirrorRef, blobContent); // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -195,8 +188,7 @@ void shouldFetchBlobViaMirrorWhenOriginalIsDown(@TempDir Path blobDir, @TempDir [[registry.mirror]] location = "%s" insecure = true - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -241,8 +233,7 @@ void shouldFetchManifestViaUnqualifiedReference(@TempDir Path blobDir) throws Ex // Configure docker.io with a mirror — unqualified refs resolve to docker.io by default // language=toml - String registriesConf = - """ + String registriesConf = """ short-name-mode = "disabled" unqualified-search-registries = ["docker.io"] @@ -254,8 +245,7 @@ void shouldFetchManifestViaUnqualifiedReference(@TempDir Path blobDir) throws Ex [[registry.mirror]] location = "%s" insecure = true - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -286,8 +276,7 @@ void shouldResolveUnqualifiedRegistryViaFallbackWhenMirrorIsDown(@TempDir Path b // is actually configured as the search registry below. The mirror here is unreachable: resolution // must catch that failure and fall back to probing the search registry directly. // language=toml - String registriesConf = - """ + String registriesConf = """ short-name-mode = "disabled" unqualified-search-registries = ["%s"] @@ -298,8 +287,7 @@ void shouldResolveUnqualifiedRegistryViaFallbackWhenMirrorIsDown(@TempDir Path b [[registry.mirror]] location = "localhost:59999" insecure = true - """ - .formatted(searchRegistry); + """.formatted(searchRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -323,8 +311,7 @@ void shouldThrowWhenMirrorIsDownAndSearchRegistryLacksArtifact() throws Exceptio String searchRegistry = mirrorUp.getRegistry(); // language=toml - String registriesConf = - """ + String registriesConf = """ short-name-mode = "disabled" unqualified-search-registries = ["%s"] @@ -335,8 +322,7 @@ void shouldThrowWhenMirrorIsDownAndSearchRegistryLacksArtifact() throws Exceptio [[registry.mirror]] location = "localhost:59999" insecure = true - """ - .formatted(searchRegistry); + """.formatted(searchRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -365,8 +351,7 @@ void shouldSkipDigestOnlyMirrorWhenPullingByTag(@TempDir Path blobDir) throws Ex // Mirror configured as digest-only — a tag-based pull must NOT use it // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -375,8 +360,7 @@ void shouldSkipDigestOnlyMirrorWhenPullingByTag(@TempDir Path blobDir) throws Ex location = "%s" insecure = true pull-from-mirror = "digest-only" - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -385,7 +369,7 @@ void shouldSkipDigestOnlyMirrorWhenPullingByTag(@TempDir Path blobDir) throws Ex // Pull by tag: digest-only mirror is skipped; fallback to "original" (also down) → must fail ContainerRef ref = ContainerRef.parse("localhost:59998/test/digest-only-mirror:v1"); assertThrows( - land.oras.exception.OrasException.class, + OrasException.class, () -> registry.getManifest(ref), "digest-only mirror must be skipped for a tag-based pull"); }); @@ -407,8 +391,7 @@ void shouldUseDigestOnlyMirrorWhenPullingByDigest(@TempDir Path blobDir) throws String digest = pushed.getDescriptor().getDigest(); // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -417,8 +400,7 @@ void shouldUseDigestOnlyMirrorWhenPullingByDigest(@TempDir Path blobDir) throws location = "%s" insecure = true pull-from-mirror = "digest-only" - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -447,8 +429,7 @@ void shouldApplyMirrorByDigestOnly(@TempDir Path blobDir) throws Exception { String digest = pushed.getDescriptor().getDigest(); // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -457,8 +438,7 @@ void shouldApplyMirrorByDigestOnly(@TempDir Path blobDir) throws Exception { [[registry.mirror]] location = "%s" insecure = true - """ - .formatted(mirrorRegistry); + """.formatted(mirrorRegistry); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -468,7 +448,7 @@ void shouldApplyMirrorByDigestOnly(@TempDir Path blobDir) throws Exception { // Tag pull, mirror-by-digest-only skips all mirrors. Fail with original down ContainerRef tagRef = ContainerRef.parse("localhost:59998/test/mbd-mirror:v1"); assertThrows( - land.oras.exception.OrasException.class, + OrasException.class, () -> registry.getManifest(tagRef), "mirror-by-digest-only must skip mirrors for tag-based pulls"); diff --git a/src/test/java/land/oras/RegistryTest.java b/src/test/java/land/oras/RegistryTest.java index e180a5e2..792a2ac9 100644 --- a/src/test/java/land/oras/RegistryTest.java +++ b/src/test/java/land/oras/RegistryTest.java @@ -85,8 +85,7 @@ void shouldThrowIfUnableToFindOnAnyUnQualifiedSearchRegistry(@TempDir Path homeD // language=toml String config = """ unqualified-search-registries = ["%s"] - """ - .formatted(registry.getRegistry()); + """.formatted(registry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); @@ -105,8 +104,7 @@ void shouldEnforceMultipleRegistriesWithDefaultEnforcingMode(@TempDir Path homeD // language=toml String config = """ unqualified-search-registries = ["%s", "localhost:5000"] - """ - .formatted(registry.getRegistry()); + """.formatted(registry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); @@ -128,12 +126,10 @@ void shouldEnforceMultipleRegistriesWithDefaultEnforcingMode(@TempDir Path homeD void shouldAllowMultipleRegistriesWithDisabledEnforcingMode(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ short-name-mode = "disabled" unqualified-search-registries = ["%s", "localhost:5000"] - """ - .formatted(registry.getRegistry()); + """.formatted(registry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); @@ -151,12 +147,10 @@ void shouldAllowMultipleRegistriesWithDisabledEnforcingMode(@TempDir Path homeDi void shouldEnforceMultipleRegistriesWithPermissiveEnforcingMode(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ short-name-mode = "permissive" unqualified-search-registries = ["%s", "localhost:5000"] - """ - .formatted(registry.getRegistry()); + """.formatted(registry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); @@ -191,13 +185,11 @@ void shouldListRepositories() { void shouldListRepositoriesInsecure(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -290,13 +282,11 @@ void shouldCheckIfCanMount() throws IOException { void shouldMountWithInsecureRegistry(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -448,13 +438,11 @@ void shouldPushPullManifestsAndBlobsByUsingConfig(@TempDir Path homeDir) throws ExecutorService customExecutor = Executors.newSingleThreadExecutor(); // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -650,13 +638,11 @@ void shouldPushManifest() { void shouldPushManifestWithRegistryConfig(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -690,16 +676,14 @@ void shouldPushManifestWithRegistryConfig(@TempDir Path homeDir) throws Exceptio void shouldPushManifestWithAlias(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true [aliases] "my-library/my-namespace"="%s/test/bar" - """ - .formatted(this.unsecureRegistry.getRegistry(), this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry(), this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -735,8 +719,7 @@ void shouldDetermineRegistryFromAlias(@TempDir Path homeDir) throws Exception { String config = """ [aliases] "my-library/my-namespace"="localhost/test" - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -1025,13 +1008,11 @@ void shouldListReferrers(@TempDir Path homeDir) throws Exception { // Use config // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -1224,16 +1205,14 @@ void testShouldCopySingleFromDigest() throws IOException { void testShouldArtifactWithAlias(@TempDir Path homeDir) throws Exception { // language=toml - String config = - """ + String config = """ [aliases] "the-target" = "%s/test/artifact-target" [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry(), this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry(), this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); // Copy to same registry @@ -1268,8 +1247,7 @@ void testShouldCopyFromAliasToAlias(@TempDir Path homeDir) throws Exception { otherRegistryContainer.start(); // language=toml - String config = - """ + String config = """ [aliases] "the-source" = "%s/test/artifact-source" "the-target" = "%s/test/artifact-target" @@ -1281,12 +1259,11 @@ void testShouldCopyFromAliasToAlias(@TempDir Path homeDir) throws Exception { [[registry]] location = "%s" insecure = true - """ - .formatted( - this.unsecureRegistry.getRegistry(), - otherRegistryContainer.getRegistry(), - this.unsecureRegistry.getRegistry(), - otherRegistryContainer.getRegistry()); + """.formatted( + this.unsecureRegistry.getRegistry(), + otherRegistryContainer.getRegistry(), + this.unsecureRegistry.getRegistry(), + otherRegistryContainer.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); // Copy to same registry @@ -2207,13 +2184,11 @@ void shouldFailChunkedUploadWithInvalidChunkSize() throws IOException { void shouldPushBlobChunkedFromPathViaInsecureRegistryConfig(@TempDir Path homeDir) throws Exception { // Insecure config - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { @@ -2246,13 +2221,11 @@ void shouldPushBlobChunkedFromPathViaInsecureRegistryConfig(@TempDir Path homeDi void shouldPushBlobChunkedFromStreamViaInsecureRegistryConfig(@TempDir Path homeDir) throws Exception { // Insecure config - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(this.unsecureRegistry.getRegistry()); + """.formatted(this.unsecureRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, config); TestUtils.withHome(homeDir, () -> { diff --git a/src/test/java/land/oras/RegistryTlsTest.java b/src/test/java/land/oras/RegistryTlsTest.java index e67c6b43..74f5283a 100644 --- a/src/test/java/land/oras/RegistryTlsTest.java +++ b/src/test/java/land/oras/RegistryTlsTest.java @@ -144,13 +144,11 @@ void shouldDowngradeToSecureWhenConfigExplicitlyNotInsecure(@TempDir Path homeDi // Authoritative parent // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] location = "%s" insecure = false - """ - .formatted(tlsRegistry.getRegistry()); + """.formatted(tlsRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, registriesConf); @@ -176,8 +174,7 @@ void shouldUpgradeToSecureAllOperationsToSecureWhenConfigDefaultsToSecure( String registriesConf = """ [[registry]] location = "%s" - """ - .formatted(tlsRegistry.getRegistry()); + """.formatted(tlsRegistry.getRegistry()); TestUtils.createRegistriesConfFile(homeDir, registriesConf); Path testFile = blobDir.resolve("downgrade1.txt"); @@ -299,8 +296,7 @@ void shouldNotDowngradeSecureMirrorWhenRegistryLevelInsecureSetForMirrorHost( // connection to plaintext HTTP. The HTTPS-only container would refuse a plaintext request, so // a successful manifest fetch proves the connection stayed on HTTPS. // language=toml - String registriesConf = - """ + String registriesConf = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -312,8 +308,7 @@ void shouldNotDowngradeSecureMirrorWhenRegistryLevelInsecureSetForMirrorHost( prefix = "%s" location = "%s" insecure = true - """ - .formatted(mirror, mirror, mirror); + """.formatted(mirror, mirror, mirror); TestUtils.createRegistriesConfFile(homeDir, registriesConf); diff --git a/src/test/java/land/oras/RegistryWireMockTest.java b/src/test/java/land/oras/RegistryWireMockTest.java index f114a47d..76a4fffb 100644 --- a/src/test/java/land/oras/RegistryWireMockTest.java +++ b/src/test/java/land/oras/RegistryWireMockTest.java @@ -39,6 +39,7 @@ import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -283,8 +284,7 @@ void shouldNotForwardParentCredentialsToInsecureMirror(WireMockRuntimeInfo wmRun // WireMock server. The parent registry is configured with static basic-auth credentials — those // credentials must NOT be forwarded to the mirror over plaintext HTTP. // language=toml - String config = - """ + String config = """ [[registry]] prefix = "localhost:59998" location = "localhost:59998" @@ -292,13 +292,11 @@ void shouldNotForwardParentCredentialsToInsecureMirror(WireMockRuntimeInfo wmRun [[registry.mirror]] location = "%s" insecure = true - """ - .formatted(mirrorHost); + """.formatted(mirrorHost); TestUtils.createRegistriesConfFile(homeDir4, config); // language=json - String manifestJson = - """ + String manifestJson = """ {"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json",\ "config":{"mediaType":"application/vnd.oci.empty.v1+json",\ "digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","size":2},\ @@ -389,13 +387,11 @@ void shouldListTagsWithConfig(WireMockRuntimeInfo wmRuntimeInfo) throws Exceptio String registryAsString = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(registryAsString); + """.formatted(registryAsString); TestUtils.createRegistriesConfFile(homeDir1, config); // Return data from wiremock @@ -458,13 +454,11 @@ void shouldListRepositoryWithLocationConfig(WireMockRuntimeInfo wmRuntimeInfo) t String registryAsString = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); // language=toml - String config = - """ + String config = """ [[registry]] location = "%s" insecure = true - """ - .formatted(registryAsString); + """.formatted(registryAsString); TestUtils.createRegistriesConfFile(homeDir2, config); // Return data from wiremock @@ -493,13 +487,11 @@ void shouldListRepositoryWithPrefixConfig(WireMockRuntimeInfo wmRuntimeInfo) thr String registryAsString = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); // language=toml - String config = - """ + String config = """ [[registry]] prefix = "%s" insecure = true - """ - .formatted(registryAsString); + """.formatted(registryAsString); TestUtils.createRegistriesConfFile(homeDir3, config); // Return data from wiremock @@ -526,8 +518,7 @@ void shouldListRepositoryWithPrefixConfig(WireMockRuntimeInfo wmRuntimeInfo) thr void shouldListTagsWithFileStoreAuth(WireMockRuntimeInfo wmRuntimeInfo) throws IOException { // Auth file for current registry - String authFile = - """ + String authFile = """ { "auths": { "localhost:%d": { @@ -535,8 +526,7 @@ void shouldListTagsWithFileStoreAuth(WireMockRuntimeInfo wmRuntimeInfo) throws I } } } - """ - .formatted(wmRuntimeInfo.getHttpPort()); + """.formatted(wmRuntimeInfo.getHttpPort()); Files.writeString(configDir.resolve("config.json"), authFile, StandardCharsets.UTF_8); @@ -1517,8 +1507,7 @@ void shouldFailChunkedUploadWhenInitiationReturnsNon202(WireMockRuntimeInfo wmRu OrasException exStream = assertThrows( OrasException.class, - () -> registry.pushBlobChunked( - refStream, new java.io.ByteArrayInputStream(content), content.length, 4L)); + () -> registry.pushBlobChunked(refStream, new ByteArrayInputStream(content), content.length, 4L)); assertEquals( "Failed to initiate chunked blob upload: status 500", exStream.getMessage(), @@ -1579,14 +1568,12 @@ void shouldCopyWithoutLoopingOnCyclicIndexGraph(WireMockRuntimeInfo wmRuntimeInf .withHeader(Const.DOCKER_CONTENT_DIGEST_HEADER, digestA))); // Generic target: accept any manifest push and return an empty index on the follow-up read. - String emptyIndex = - """ + String emptyIndex = """ { "schemaVersion": 2, "mediaType": "%s", "manifests": [] - }""" - .formatted(Const.DEFAULT_INDEX_MEDIA_TYPE); + }""".formatted(Const.DEFAULT_INDEX_MEDIA_TYPE); wireMock.register(WireMock.put(WireMock.urlMatching("/v2/%s/manifests/.*".formatted(dstRepo))) .willReturn(WireMock.created().withHeader(Const.DOCKER_CONTENT_DIGEST_HEADER, digestA))); wireMock.register(WireMock.head(WireMock.urlMatching("/v2/%s/manifests/.*".formatted(dstRepo))) @@ -1634,8 +1621,7 @@ private static String nestedIndexJson(String childDigest) { "size": 100 } ] - }""" - .formatted(Const.DEFAULT_INDEX_MEDIA_TYPE, Const.DEFAULT_INDEX_MEDIA_TYPE, childDigest); + }""".formatted(Const.DEFAULT_INDEX_MEDIA_TYPE, Const.DEFAULT_INDEX_MEDIA_TYPE, childDigest); } /** @@ -1743,8 +1729,7 @@ void shouldRejectBlobStreamOnDigestMismatch(WireMockRuntimeInfo wmRuntimeInfo) { @Test void shouldRejectManifestWhoseContentDoesNotMatchPinnedDigest(WireMockRuntimeInfo wmRuntimeInfo) { - String realManifest = - """ + String realManifest = """ {"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json",\ "config":{"mediaType":"application/vnd.oci.empty.v1+json",\ "digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","size":2},\ @@ -1820,13 +1805,11 @@ void shouldFailOnReferrerListPaginationExceedingMaxPages(WireMockRuntimeInfo wmR String referrersPath = "/v2/library/artifact-text/referrers/" + digest; // Minimal referrers index JSON with one manifest entry per page - String page1 = - """ + String page1 = """ {"mediaType":"application/vnd.oci.image.index.v1+json","manifests":\ [{"mediaType":"application/vnd.oci.image.manifest.v1+json",\ "digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","size":1}]}"""; - String page2 = - """ + String page2 = """ {"mediaType":"application/vnd.oci.image.index.v1+json","manifests":\ [{"mediaType":"application/vnd.oci.image.manifest.v1+json",\ "digest":"sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","size":1}]}"""; @@ -1871,8 +1854,7 @@ void shouldFallbackToReferrersTagSchemaWhenReferrersApiUnavailable(WireMockRunti String fallbackTagPath = "/v2/library/artifact-text/manifests/" + "sha256-44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"; - String fallbackIndex = - """ + String fallbackIndex = """ {"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","manifests":\ [{"mediaType":"application/vnd.oci.image.manifest.v1+json",\ "digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","size":1,\ @@ -1912,8 +1894,7 @@ void shouldFilterFallbackReferrersByArtifactType(WireMockRuntimeInfo wmRuntimeIn String fallbackTagPath = "/v2/library/artifact-text/manifests/" + "sha256-44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"; - String fallbackIndex = - """ + String fallbackIndex = """ {"schemaVersion":2,"mediaType":"application/vnd.oci.image.index.v1+json","manifests":\ [{"mediaType":"application/vnd.oci.image.manifest.v1+json",\ "digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","size":1,\ diff --git a/src/test/java/land/oras/auth/AuthStoreTest.java b/src/test/java/land/oras/auth/AuthStoreTest.java index 4d8fa29f..c5ad8d0e 100644 --- a/src/test/java/land/oras/auth/AuthStoreTest.java +++ b/src/test/java/land/oras/auth/AuthStoreTest.java @@ -58,8 +58,7 @@ class AuthStoreTest { private static final String PASSWORD = "password"; // language=json - public static final String SAMPLE_DOCKER_CONFIG = - """ + public static final String SAMPLE_DOCKER_CONFIG = """ { "auths": { "registry.example.com": { @@ -82,8 +81,7 @@ class AuthStoreTest { """; // language=json - public static final String SAMPLE_PODMAN_CONFIG = - """ + public static final String SAMPLE_PODMAN_CONFIG = """ { "auths": { "registry.other.com": { @@ -293,8 +291,7 @@ void testShouldReadCredentialsFromPodManConfig() throws Exception { } // language=json - public static final String SAMPLE_HIERARCHICAL_CONFIG = - """ + public static final String SAMPLE_HIERARCHICAL_CONFIG = """ { "auths": { "my-registry.local/namespace/user/image": { @@ -412,8 +409,7 @@ void testRegistryAuthFileIsUsedWhenSet() throws Exception { @Test void testRegistryAuthFileTakesPrecedenceOverDefaults() throws Exception { // language=json - String customConfig = - """ + String customConfig = """ { "auths": { "custom.registry.com": { @@ -489,15 +485,13 @@ void testPasswordContainingColonIsPreserved() throws Exception { String auth = java.util.Base64.getEncoder() .encodeToString((user + ":" + password).getBytes(java.nio.charset.StandardCharsets.UTF_8)); // language=json - String config = - """ + String config = """ { "auths": { "colon.registry.com": { "auth": "%s" } } } - """ - .formatted(auth); + """.formatted(auth); Path configFile = tempDir.resolve("colon-config.json"); Files.writeString(configFile, config); @@ -516,16 +510,14 @@ void testMalformedEntryIsSkippedWithoutDroppingOtherCredentials() throws Excepti String valid = java.util.Base64.getEncoder() .encodeToString("user:password".getBytes(java.nio.charset.StandardCharsets.UTF_8)); // language=json - String config = - """ + String config = """ { "auths": { "bad.registry.com": { "auth": "%s" }, "good.registry.com": { "auth": "%s" } } } - """ - .formatted(malformed, valid); + """.formatted(malformed, valid); Path configFile = tempDir.resolve("malformed-config.json"); Files.writeString(configFile, config); @@ -542,15 +534,13 @@ void testEmptyPasswordIsPreserved() throws Exception { String auth = java.util.Base64.getEncoder().encodeToString("user:".getBytes(java.nio.charset.StandardCharsets.UTF_8)); // language=json - String config = - """ + String config = """ { "auths": { "empty.registry.com": { "auth": "%s" } } } - """ - .formatted(auth); + """.formatted(auth); Path configFile = tempDir.resolve("empty-pass-config.json"); Files.writeString(configFile, config); @@ -569,15 +559,13 @@ void testPasswordWithArbitraryCharactersIsPreserved() throws Exception { String auth = java.util.Base64.getEncoder() .encodeToString((user + ":" + password).getBytes(java.nio.charset.StandardCharsets.UTF_8)); // language=json - String config = - """ + String config = """ { "auths": { "any.registry.com": { "auth": "%s" } } } - """ - .formatted(auth); + """.formatted(auth); Path configFile = tempDir.resolve("any-char-config.json"); Files.writeString(configFile, config); @@ -593,14 +581,12 @@ void testPasswordWithArbitraryCharactersIsPreserved() throws Exception { void shouldRejectCredentialHelperThatEscapesPrefix() throws Exception { String maliciousSuffix = "../../../../../../tmp/pwn"; // language=json - String config = - """ + String config = """ { "auths": {}, "credHelpers": { "evil.registry.com": "%s" } } - """ - .formatted(maliciousSuffix); + """.formatted(maliciousSuffix); Path configFile = tempDir.resolve("evil-helper-config.json"); Files.writeString(configFile, config); @@ -614,8 +600,7 @@ void shouldRejectCredentialHelperThatEscapesPrefix() throws Exception { @Test void shouldReturnValidCredentialHelperBinary() throws Exception { // language=json - String config = - """ + String config = """ { "auths": {}, "credHelpers": { "good.registry.com": "ecr-login" } diff --git a/src/test/java/land/oras/auth/RegistriesConfTest.java b/src/test/java/land/oras/auth/RegistriesConfTest.java index e84cb996..94de29ea 100644 --- a/src/test/java/land/oras/auth/RegistriesConfTest.java +++ b/src/test/java/land/oras/auth/RegistriesConfTest.java @@ -41,8 +41,7 @@ class RegistriesConfTest { private static Path homeDir; // language=toml - public static final String HOME_REGISTRIES_CONF = - """ + public static final String HOME_REGISTRIES_CONF = """ unqualified-search-registries = ["docker.io"] [aliases] @@ -80,10 +79,7 @@ void shouldLoadDropInConfFiles(@TempDir Path dropInHomeDir) throws Exception { // language=toml TestUtils.createRegistriesConfFile(dropInHomeDir, "unqualified-search-registries = [\"docker.io\"]"); // language=toml - TestUtils.createDropInConfFile( - dropInHomeDir, - "10-extra.conf", - """ + TestUtils.createDropInConfFile(dropInHomeDir, "10-extra.conf", """ [aliases] "myapp"="registry.example.com/myapp" """); @@ -102,18 +98,12 @@ void shouldLoadDropInConfFiles(@TempDir Path dropInHomeDir) throws Exception { void shouldLoadDropInConfFilesInAlphaNumericalOrder(@TempDir Path dropInHomeDir) throws Exception { TestUtils.createRegistriesConfFile(dropInHomeDir, ""); // language=toml - TestUtils.createDropInConfFile( - dropInHomeDir, - "01-first.conf", - """ + TestUtils.createDropInConfFile(dropInHomeDir, "01-first.conf", """ [aliases] "foo"="registry.first.com/foo" """); // language=toml - TestUtils.createDropInConfFile( - dropInHomeDir, - "02-second.conf", - """ + TestUtils.createDropInConfFile(dropInHomeDir, "02-second.conf", """ [aliases] "foo"="registry.second.com/foo" """); diff --git a/src/test/java/land/oras/auth/RegistryConfTest.java b/src/test/java/land/oras/auth/RegistryConfTest.java index 12997250..e87409d1 100644 --- a/src/test/java/land/oras/auth/RegistryConfTest.java +++ b/src/test/java/land/oras/auth/RegistryConfTest.java @@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -222,8 +223,7 @@ void shouldRewriteUnqualifiedContainerRef() { @Test void shouldParseMirrorsFromToml() { // language=toml - String toml = - """ + String toml = """ [[registry]] prefix = "docker.io" location = "docker.io" @@ -362,8 +362,7 @@ void shouldRewriteForMirrorWithTrailingSlash() { @Test void shouldParsePullFromMirrorFromToml() { // language=toml - String toml = - """ + String toml = """ [[registry]] prefix = "docker.io" location = "docker.io" @@ -398,8 +397,7 @@ void shouldParsePullFromMirrorFromToml() { @Test void shouldFilterMirrorsByPullFromMirrorForTagRef() { // language=toml - String toml = - """ + String toml = """ [[registry]] prefix = "docker.io" location = "docker.io" @@ -430,8 +428,7 @@ void shouldFilterMirrorsByPullFromMirrorForTagRef() { @Test void shouldFilterMirrorsByPullFromMirrorForDigestRef() { // language=toml - String toml = - """ + String toml = """ [[registry]] prefix = "docker.io" location = "docker.io" @@ -463,8 +460,7 @@ void shouldFilterMirrorsByPullFromMirrorForDigestRef() { @Test void shouldApplyMirrorByDigestOnly() { // language=toml - String toml = - """ + String toml = """ [[registry]] prefix = "docker.io" location = "docker.io" @@ -496,8 +492,7 @@ void shouldApplyMirrorByDigestOnly() { @Test void shouldReturnAllMirrorsWhenNoFilterConfigured() { // language=toml - String toml = - """ + String toml = """ [[registry]] prefix = "docker.io" location = "docker.io" @@ -520,7 +515,7 @@ private Path writeTempToml(String content) { temp.toFile().deleteOnExit(); Files.writeString(temp, content); return temp; - } catch (java.io.IOException e) { + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/test/java/land/oras/policy/ContainersPolicyTest.java b/src/test/java/land/oras/policy/ContainersPolicyTest.java index eca0ab4e..e7a91daa 100644 --- a/src/test/java/land/oras/policy/ContainersPolicyTest.java +++ b/src/test/java/land/oras/policy/ContainersPolicyTest.java @@ -276,12 +276,9 @@ void sigstoreSignedGlobalDefaultApplies(@TempDir Path dir) throws IOException { KeyPair kp = SigstoreTestSupport.generateKeyPair(); Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ {"default": [{"type": "sigstoreSigned", "keyData": "%s"}]} - """ - .formatted(SigstoreTestSupport.keyData(kp.getPublic()))); + """.formatted(SigstoreTestSupport.keyData(kp.getPublic()))); ContainersPolicy policy = ContainersPolicy.newPolicy(path); assertDoesNotThrow(() -> policy.verify(context( @@ -358,9 +355,7 @@ void sigstoreSignedWithKeyPathsList(@TempDir Path dir) throws IOException { Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -372,10 +367,8 @@ void sigstoreSignedWithKeyPathsList(@TempDir Path dir) throws IOException { } } } - """ - .formatted( - keyFile1.toString().replace("\\", "\\\\"), - keyFile2.toString().replace("\\", "\\\\"))); + """.formatted( + keyFile1.toString().replace("\\", "\\\\"), keyFile2.toString().replace("\\", "\\\\"))); ContainersPolicy policy = ContainersPolicy.newPolicy(path); // Accepted when signed by kp1 @@ -407,9 +400,7 @@ void sigstoreSignedWithKeyDatasList(@TempDir Path dir) throws IOException { Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -421,10 +412,8 @@ void sigstoreSignedWithKeyDatasList(@TempDir Path dir) throws IOException { } } } - """ - .formatted( - SigstoreTestSupport.keyData(kp1.getPublic()), - SigstoreTestSupport.keyData(kp2.getPublic()))); + """.formatted( + SigstoreTestSupport.keyData(kp1.getPublic()), SigstoreTestSupport.keyData(kp2.getPublic()))); ContainersPolicy policy = ContainersPolicy.newPolicy(path); // Accepted when signed by kp1 @@ -453,9 +442,7 @@ void sigstoreSignedWithKeyDatasList(@TempDir Path dir) throws IOException { void sigstoreSignedKeyPathsDeserializesCorrectly(@TempDir Path dir) throws IOException { Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -483,9 +470,7 @@ void sigstoreSignedKeyPathsDeserializesCorrectly(@TempDir Path dir) throws IOExc void signedByGpgIsDeniedBecauseNotImplemented(@TempDir Path dir) throws IOException { Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -508,9 +493,7 @@ void mixedScopesResolveAndVerifyIndependently(@TempDir Path dir) throws IOExcept KeyPair kp = SigstoreTestSupport.generateKeyPair(); Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -521,8 +504,7 @@ void mixedScopesResolveAndVerifyIndependently(@TempDir Path dir) throws IOExcept } } } - """ - .formatted(SigstoreTestSupport.keyData(kp.getPublic()))); + """.formatted(SigstoreTestSupport.keyData(kp.getPublic()))); ContainersPolicy policy = ContainersPolicy.newPolicy(path); // Open scope: accepted without signatures. @@ -563,9 +545,7 @@ private static ContainersPolicy sigstorePolicy(Path dir, String scopeKey, String throws IOException { Path path = dir.resolve("policy.json"); // language=json - Files.writeString( - path, - """ + Files.writeString(path, """ { "default": [{"type": "reject"}], "transports": { @@ -574,8 +554,7 @@ private static ContainersPolicy sigstorePolicy(Path dir, String scopeKey, String } } } - """ - .formatted(scopeKey, keyField, keyValue)); + """.formatted(scopeKey, keyField, keyValue)); return ContainersPolicy.newPolicy(path); } diff --git a/src/test/java/land/oras/policy/SigstoreTestSupport.java b/src/test/java/land/oras/policy/SigstoreTestSupport.java index cbf613ac..58f8ca0f 100644 --- a/src/test/java/land/oras/policy/SigstoreTestSupport.java +++ b/src/test/java/land/oras/policy/SigstoreTestSupport.java @@ -72,8 +72,7 @@ static String publicKeyPem(PublicKey key) { -----BEGIN PUBLIC KEY----- %s -----END PUBLIC KEY----- - """ - .formatted(b64); + """.formatted(b64); } /** @@ -122,8 +121,7 @@ private static String inTotoPayload(String imageHex) { "subject": [{"digest": {"sha256": "%s"}, "annotations": {}}], "predicateType": "https://sigstore.dev/cosign/sign/v1", "predicate": {} - }""" - .formatted(imageHex); + }""".formatted(imageHex); } private static String bundleJson(byte[] payload, byte[] signature) { @@ -137,8 +135,7 @@ private static String bundleJson(byte[] payload, byte[] signature) { "payloadType": "%s", "signatures": [{"sig": "%s"}] } - }""" - .formatted( + }""".formatted( Const.SIGSTORE_BUNDLE_MEDIA_TYPE, b64.encodeToString(payload), Const.IN_TOTO_PAYLOAD_TYPE, diff --git a/src/test/java/land/oras/policy/SigstoreVerifierTest.java b/src/test/java/land/oras/policy/SigstoreVerifierTest.java index 21cb200b..a2b6ed50 100644 --- a/src/test/java/land/oras/policy/SigstoreVerifierTest.java +++ b/src/test/java/land/oras/policy/SigstoreVerifierTest.java @@ -142,13 +142,13 @@ void loadsKeysFromKeyPathsAndKeyDatas(@TempDir Path dir) throws Exception { // keyPaths list PolicyRequirement.SigstoreSigned fromPaths = new PolicyRequirement.SigstoreSigned( null, null, List.of(keyFile1.toString(), keyFile2.toString()), null); - List loadedFromPaths = SigstoreVerifier.loadKeys(fromPaths); + List loadedFromPaths = SigstoreVerifier.loadKeys(fromPaths); assertEquals(2, loadedFromPaths.size()); // keyDatas list PolicyRequirement.SigstoreSigned fromDatas = new PolicyRequirement.SigstoreSigned(null, null, null, List.of(keyData1, keyData2)); - List loadedFromDatas = SigstoreVerifier.loadKeys(fromDatas); + List loadedFromDatas = SigstoreVerifier.loadKeys(fromDatas); assertEquals(2, loadedFromDatas.size()); } @@ -180,9 +180,7 @@ void policyVerificationPassesForSignedImageAndFailsWhenTampered(@TempDir Path di Path policyPath = dir.resolve("policy.json"); // language=json - Files.writeString( - policyPath, - """ + Files.writeString(policyPath, """ { "default": [{"type": "reject"}], "transports": { @@ -193,8 +191,7 @@ void policyVerificationPassesForSignedImageAndFailsWhenTampered(@TempDir Path di } } } - """ - .formatted(keyFile.toString().replace("\\", "\\\\"))); + """.formatted(keyFile.toString().replace("\\", "\\\\"))); ContainersPolicy policy = ContainersPolicy.newPolicy(policyPath); @@ -224,9 +221,7 @@ void policyVerificationFailsWhenKeyIsMissing(@TempDir Path dir) throws Exception Path policyPath = dir.resolve("policy.json"); // language=json - Files.writeString( - policyPath, - """ + Files.writeString(policyPath, """ { "default": [{"type": "reject"}], "transports": { @@ -277,8 +272,7 @@ private static String inTotoPayload(String imageHex) { "subject": [{"digest": {"sha256": "%s"}, "annotations": {}}], "predicateType": "https://sigstore.dev/cosign/sign/v1", "predicate": {} - }""" - .formatted(imageHex); + }""".formatted(imageHex); } private static String bundleJson(byte[] payload, byte[] signature) { @@ -292,8 +286,7 @@ private static String bundleJson(byte[] payload, byte[] signature) { "payloadType": "%s", "signatures": [{"sig": "%s"}] } - }""" - .formatted( + }""".formatted( Const.SIGSTORE_BUNDLE_MEDIA_TYPE, b64.encodeToString(payload), Const.IN_TOTO_PAYLOAD_TYPE, @@ -307,7 +300,6 @@ private static String toPem(PublicKey key) { -----BEGIN PUBLIC KEY----- %s -----END PUBLIC KEY----- - """ - .formatted(b64); + """.formatted(b64); } } diff --git a/src/test/java/land/oras/utils/ArchiveUtilsTest.java b/src/test/java/land/oras/utils/ArchiveUtilsTest.java index d128a524..ed08b718 100644 --- a/src/test/java/land/oras/utils/ArchiveUtilsTest.java +++ b/src/test/java/land/oras/utils/ArchiveUtilsTest.java @@ -30,6 +30,8 @@ import java.nio.file.Paths; import java.nio.file.attribute.PosixFilePermission; import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import land.oras.LocalPath; import land.oras.exception.OrasException; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -410,8 +412,8 @@ void shouldUnzipOverwriteExistingFiles(@TempDir Path tmp) throws IOException { byte[] secondContent = "second-overwritten".getBytes(); Path zip1 = tmp.resolve("first.zip"); - try (java.util.zip.ZipOutputStream zout = new java.util.zip.ZipOutputStream(Files.newOutputStream(zip1))) { - zout.putNextEntry(new java.util.zip.ZipEntry("file.txt")); + try (ZipOutputStream zout = new ZipOutputStream(Files.newOutputStream(zip1))) { + zout.putNextEntry(new ZipEntry("file.txt")); zout.write(firstContent); zout.closeEntry(); } @@ -419,8 +421,8 @@ void shouldUnzipOverwriteExistingFiles(@TempDir Path tmp) throws IOException { assertEquals("first", Files.readString(target.resolve("file.txt"))); Path zip2 = tmp.resolve("second.zip"); - try (java.util.zip.ZipOutputStream zout = new java.util.zip.ZipOutputStream(Files.newOutputStream(zip2))) { - zout.putNextEntry(new java.util.zip.ZipEntry("file.txt")); + try (ZipOutputStream zout = new ZipOutputStream(Files.newOutputStream(zip2))) { + zout.putNextEntry(new ZipEntry("file.txt")); zout.write(secondContent); zout.closeEntry(); } diff --git a/src/test/java/land/oras/utils/YamlUtilsTest.java b/src/test/java/land/oras/utils/YamlUtilsTest.java index 571eb6bd..494f5cac 100644 --- a/src/test/java/land/oras/utils/YamlUtilsTest.java +++ b/src/test/java/land/oras/utils/YamlUtilsTest.java @@ -53,8 +53,7 @@ void failToParseYamlString() { @Test @SuppressWarnings("unchecked") void shouldParseYaml() { - String yamlMap = - """ + String yamlMap = """ --- key1: "value1" key2: "value2" @@ -69,8 +68,7 @@ void shouldParseYaml() { @Test @SuppressWarnings("unchecked") void shouldParseYamlFile() throws IOException { - String yamlMap = - """ + String yamlMap = """ --- key1: "value1" key2: "value2" diff --git a/src/test/java/land/oras/utils/ZotContainer.java b/src/test/java/land/oras/utils/ZotContainer.java index a63d1c1a..cff5fe2c 100644 --- a/src/test/java/land/oras/utils/ZotContainer.java +++ b/src/test/java/land/oras/utils/ZotContainer.java @@ -44,8 +44,7 @@ public ZotContainer() { copyFileToContainer(authFile, "/etc/zot/auth.htpasswd"); // language=JSON - String configJson = - """ + String configJson = """ { "storage": { "rootDirectory": "/var/lib/registry" }, "http": { @@ -59,8 +58,7 @@ public ZotContainer() { "search": { "enable": true } } } - """ - .formatted(ZOT_PORT); + """.formatted(ZOT_PORT); writeConfig(configJson); } catch (Exception e) { diff --git a/src/test/java/land/oras/utils/ZotTlsContainer.java b/src/test/java/land/oras/utils/ZotTlsContainer.java index 2c3328ae..1e1a24f2 100644 --- a/src/test/java/land/oras/utils/ZotTlsContainer.java +++ b/src/test/java/land/oras/utils/ZotTlsContainer.java @@ -66,8 +66,7 @@ public ZotTlsContainer() { copyFileToContainer(serverKeyPath, "/etc/zot/server-key.pem"); // language=JSON - String configJson = - """ + String configJson = """ { "storage": { "rootDirectory": "/var/lib/registry" }, "http": { @@ -82,8 +81,7 @@ public ZotTlsContainer() { "search": { "enable": true } } } - """ - .formatted(ZOT_PORT); + """.formatted(ZOT_PORT); writeConfig(configJson); } catch (Exception e) { diff --git a/src/test/java/land/oras/utils/ZotUnsecureContainer.java b/src/test/java/land/oras/utils/ZotUnsecureContainer.java index ea7a136a..63092235 100644 --- a/src/test/java/land/oras/utils/ZotUnsecureContainer.java +++ b/src/test/java/land/oras/utils/ZotUnsecureContainer.java @@ -33,8 +33,7 @@ public ZotUnsecureContainer() { setWaitStrategy(Wait.forHttp("/v2/_catalog").forPort(ZOT_PORT).forStatusCode(200)); // language=JSON - String configJson = - """ + String configJson = """ { "storage": { "rootDirectory": "/var/lib/registry" }, "http": { @@ -45,8 +44,7 @@ public ZotUnsecureContainer() { "search": { "enable": true } } } - """ - .formatted(ZOT_PORT); + """.formatted(ZOT_PORT); writeConfig(configJson); } }