Skip to content

Commit

Permalink
Merge pull request #525 from sigstore/fulciowrappertrustbundle
Browse files Browse the repository at this point in the history
Enable tests to query fulcio cert chain
  • Loading branch information
loosebazooka authored Sep 19, 2023
2 parents 13890d4 + 4e5186f commit fcd554b
Showing 1 changed file with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
*/
package dev.sigstore.testing;

import com.google.gson.Gson;
import dev.sigstore.encryption.certificates.Certificates;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.cert.CertPath;
import java.security.cert.CertificateException;
import java.util.List;
import java.util.Locale;
import org.junit.jupiter.api.extension.*;

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

public URI getGrpcURI() {
return URI.create("localhost:5554");
}

public URI getGrpcURI2() {
return URI.create("http://localhost:5554");
}

public CertPath getTrustBundle() throws CertificateException, IOException, InterruptedException {
HttpRequest req =
HttpRequest.newBuilder().uri(getURI().resolve("/api/v2/trustBundle")).GET().build();
HttpResponse<String> response = HttpClient.newHttpClient().send(req, BodyHandlers.ofString());

TrustBundle tb = new Gson().fromJson(response.body(), TrustBundle.class);
return Certificates.fromPemChain(tb.chains.get(0).certificates.get(0));
}

private Path createConfig(String issuer) throws IOException {
fulcioConfig = Files.createTempFile("fulcio-config", ".json");
Files.writeString(
Expand Down Expand Up @@ -99,6 +113,14 @@ public void beforeEach(ExtensionContext context) throws Exception {
Thread.sleep(1000); // wait for the server to come up
}

public static class TrustBundle {
private List<Chain> chains;
}

public static class Chain {
private List<String> certificates;
}

@Override
public boolean supportsParameter(
ParameterContext parameterContext, ExtensionContext extensionContext)
Expand Down

0 comments on commit fcd554b

Please sign in to comment.