Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.api.client.http.HttpRequestFactory;
import dev.sigstore.http.HttpClients;
import dev.sigstore.http.HttpParams;
import dev.sigstore.http.ImmutableHttpParams;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import okhttp3.mockwebserver.MockResponse;
Expand All @@ -36,19 +31,12 @@
import org.junit.jupiter.api.Test;

public class TimestampClientHttpTest {
private static HttpRequestFactory requestFactory;
private static HttpParams httpParams;
private static TimestampRequest tsReq;

private static final byte[] INVALID_TS_RESP_BYTES = new byte[14];
private static final URI SIGSTORE_TSA_URI =
URI.create("https://timestamp.sigstage.dev/api/v1/timestamp");

@BeforeAll
public static void setup() throws Exception {
httpParams = ImmutableHttpParams.builder().build();
requestFactory = HttpClients.newRequestFactory(httpParams);

var digest = MessageDigest.getInstance("SHA-256");
var artifactHashBytes = digest.digest("test".getBytes(StandardCharsets.UTF_8));
tsReq =
Expand All @@ -60,7 +48,7 @@ public static void setup() throws Exception {

@Test
public void timestamp_success() throws Exception {
var client = new TimestampClientHttp(requestFactory, SIGSTORE_TSA_URI);
var client = TimestampClientHttp.builder().build();

var tsResp = client.timestamp(tsReq);

Expand Down Expand Up @@ -92,7 +80,7 @@ public void timestamp_failure_badResponse_incorrectDigestLength() throws Excepti
.nonce(tsReq.getNonce())
.build();

var client = new TimestampClientHttp(requestFactory, SIGSTORE_TSA_URI);
var client = TimestampClientHttp.builder().build();

var tse =
assertThrows(
Expand All @@ -112,7 +100,7 @@ public void timestamp_failure_badResponse_nonRetryableError() throws Exception {
server.start();

var tsaUri = server.url("/v1/timestamp/").uri();
var client = new TimestampClientHttp(requestFactory, tsaUri);
var client = TimestampClientHttp.builder().setUri(tsaUri).build();

var tse =
assertThrows(
Expand All @@ -134,7 +122,7 @@ public void timestamp_failure_badResponse_RetryableError() throws Exception {
server.start();

var tsaUri = server.url("/v1/timestamp/").uri();
var client = new TimestampClientHttp(requestFactory, tsaUri);
var client = TimestampClientHttp.builder().setUri(tsaUri).build();

var tse =
assertThrows(
Expand All @@ -156,7 +144,7 @@ public void timestamp_failure_invalidResponseFormat() throws Exception {
server.start();

var tsaUri = server.url("/v1/timestamp/").uri();
var client = new TimestampClientHttp(requestFactory, tsaUri);
var client = TimestampClientHttp.builder().setUri(tsaUri).build();

var tse =
assertThrows(
Expand All @@ -180,7 +168,7 @@ public void timestamp_failure_responseBodyReadError() throws Exception {
server.start();

var tsaUri = server.url("/v1/timestamp/").uri();
var client = new TimestampClientHttp(requestFactory, tsaUri);
var client = TimestampClientHttp.builder().setUri(tsaUri).build();

var tse =
assertThrows(
Expand Down
Loading