Skip to content

Commit 4e5186f

Browse files
committed
Enable tests to query fulcio cert chain
Signed-off-by: Appu Goundan <[email protected]>
1 parent 5d82c81 commit 4e5186f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

sigstore-java/src/test/java/dev/sigstore/testing/FulcioWrapper.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515
*/
1616
package dev.sigstore.testing;
1717

18+
import com.google.gson.Gson;
19+
import dev.sigstore.encryption.certificates.Certificates;
1820
import java.io.IOException;
1921
import java.net.URI;
22+
import java.net.http.HttpClient;
23+
import java.net.http.HttpRequest;
24+
import java.net.http.HttpResponse;
25+
import java.net.http.HttpResponse.BodyHandlers;
2026
import java.nio.file.Files;
2127
import java.nio.file.Path;
28+
import java.security.cert.CertPath;
29+
import java.security.cert.CertificateException;
30+
import java.util.List;
2231
import java.util.Locale;
2332
import org.junit.jupiter.api.extension.*;
2433

@@ -40,14 +49,19 @@ public URI getURI() {
4049
return URI.create("http://localhost:5555");
4150
}
4251

43-
public URI getGrpcURI() {
44-
return URI.create("localhost:5554");
45-
}
46-
4752
public URI getGrpcURI2() {
4853
return URI.create("http://localhost:5554");
4954
}
5055

56+
public CertPath getTrustBundle() throws CertificateException, IOException, InterruptedException {
57+
HttpRequest req =
58+
HttpRequest.newBuilder().uri(getURI().resolve("/api/v2/trustBundle")).GET().build();
59+
HttpResponse<String> response = HttpClient.newHttpClient().send(req, BodyHandlers.ofString());
60+
61+
TrustBundle tb = new Gson().fromJson(response.body(), TrustBundle.class);
62+
return Certificates.fromPemChain(tb.chains.get(0).certificates.get(0));
63+
}
64+
5165
private Path createConfig(String issuer) throws IOException {
5266
fulcioConfig = Files.createTempFile("fulcio-config", ".json");
5367
Files.writeString(
@@ -99,6 +113,14 @@ public void beforeEach(ExtensionContext context) throws Exception {
99113
Thread.sleep(1000); // wait for the server to come up
100114
}
101115

116+
public static class TrustBundle {
117+
private List<Chain> chains;
118+
}
119+
120+
public static class Chain {
121+
private List<String> certificates;
122+
}
123+
102124
@Override
103125
public boolean supportsParameter(
104126
ParameterContext parameterContext, ExtensionContext extensionContext)

0 commit comments

Comments
 (0)