Skip to content

Commit 5af81f3

Browse files
authored
Merge pull request #687 from sigstore/staging-flaky
reduce impact of staging flakiness
2 parents 1316fe3 + 5ec77a4 commit 5af81f3

File tree

5 files changed

+60
-38
lines changed

5 files changed

+60
-38
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ jobs:
5454
- name: Setup Gradle
5555
uses: gradle/actions/setup-gradle@6cec5d49d4d6d4bb982fbed7047db31ea6d38f11 # v3.3.0
5656

57+
# tests that hit staging are current disabled due to flakiness (-PskipStaging)
5758
- name: Test sigstore-java
58-
run: ./gradlew build
59+
run: ./gradlew build -PskipStaging
5960

6061
- name: Ensure sigstore-java self signing still works
6162
run: ./gradlew sigstore-java:publishToMavenLocal -Prelease -PskipPgpSigning

build-logic/jvm/src/main/kotlin/build-logic.testing.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ tasks.withType<Test>().configureEach {
55
if (project.hasProperty("org.gradle.jvmargs")) {
66
systemProperty("sigstore-java.test.org.gradle.jvmargs", project.findProperty("org.gradle.jvmargs")!!)
77
}
8+
if (project.hasProperty("skipStaging")) {
9+
systemProperty("sigstore-java.test.skipStaging", project.findProperty("skipStaging")!!)
10+
}
811
}

sigstore-java/src/test/java/dev/sigstore/KeylessTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import dev.sigstore.encryption.certificates.Certificates;
2121
import dev.sigstore.rekor.client.RekorTypeException;
2222
import dev.sigstore.rekor.client.RekorTypes;
23+
import dev.sigstore.testkit.annotations.DisabledIfSkipStaging;
2324
import dev.sigstore.testkit.annotations.EnabledIfOidcExists;
2425
import dev.sigstore.testkit.annotations.OidcProviderType;
2526
import java.io.IOException;
@@ -77,6 +78,7 @@ public void sign_production() throws Exception {
7778

7879
@Test
7980
@EnabledIfOidcExists(provider = OidcProviderType.ANY)
81+
@DisabledIfSkipStaging
8082
public void sign_staging() throws Exception {
8183
var signer = KeylessSigner.builder().sigstoreStagingDefaults().build();
8284
var results = signer.sign(artifactDigests);
@@ -114,6 +116,8 @@ private void verifySigningResult(List<KeylessSignature> results)
114116
Assertions.assertArrayEquals(
115117
Base64.getDecoder().decode(hr.getSignature().getPublicKey().getContent()),
116118
Certificates.toPemBytes(result.getCertPath().getCertificates().get(0)));
119+
// check if required inclusion proof exists
120+
Assertions.assertNotNull(result.getEntry().get().getVerification().getInclusionProof());
117121
}
118122
}
119123

sigstore-java/src/test/java/dev/sigstore/rekor/client/RekorClientTest.java

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import dev.sigstore.encryption.signers.Signers;
2525
import dev.sigstore.testing.CertGenerator;
2626
import java.io.IOException;
27-
import java.net.URI;
28-
import java.net.URISyntaxException;
2927
import java.nio.charset.StandardCharsets;
3028
import java.security.InvalidKeyException;
3129
import java.security.MessageDigest;
@@ -39,30 +37,31 @@
3937
import org.hamcrest.MatcherAssert;
4038
import org.jetbrains.annotations.NotNull;
4139
import org.junit.jupiter.api.Assertions;
42-
import org.junit.jupiter.api.BeforeEach;
40+
import org.junit.jupiter.api.BeforeAll;
4341
import org.junit.jupiter.api.Test;
4442

4543
public class RekorClientTest {
4644

47-
private static final String REKOR_URL = "https://rekor.sigstage.dev";
48-
private RekorClient client;
45+
private static RekorClient client;
46+
private static HashedRekordRequest req;
47+
private static RekorResponse resp;
4948

50-
@BeforeEach
51-
public void setupClient() throws URISyntaxException {
52-
// this tests directly against rekor in staging, it's a bit hard to bring up a rekor instance
53-
// without docker compose.
54-
client = RekorClient.builder().setUri(URI.create(REKOR_URL)).build();
49+
@BeforeAll
50+
public static void setupClient() throws Exception {
51+
// this tests directly against rekor in prod, it's a bit hard to bring up a rekor instance
52+
client = RekorClient.builder().build();
53+
req = createdRekorRequest();
54+
resp = client.putEntry(req);
5555
}
5656

5757
@Test
58-
public void putEntry_toStaging() throws Exception {
58+
public void putEntry() throws Exception {
5959
HashedRekordRequest req = createdRekorRequest();
6060
var resp = client.putEntry(req);
61-
6261
// pretty basic testing
6362
MatcherAssert.assertThat(
6463
resp.getEntryLocation().toString(),
65-
CoreMatchers.startsWith(REKOR_URL + "/api/v1/log/entries/"));
64+
CoreMatchers.startsWith(RekorClient.PUBLIC_GOOD_URI + "/api/v1/log/entries/"));
6665

6766
assertNotNull(resp.getUuid());
6867
assertNotNull(resp.getRaw());
@@ -72,32 +71,25 @@ public void putEntry_toStaging() throws Exception {
7271
assertNotNull(entry.getLogID());
7372
Assertions.assertTrue(entry.getLogIndex() > 0);
7473
assertNotNull(entry.getVerification().getSignedEntryTimestamp());
75-
// Assertions.assertNotNull(entry.getVerification().getInclusionProof());
74+
Assertions.assertNotNull(entry.getVerification().getInclusionProof());
7675
}
7776

78-
// TODO([email protected]): don't use data from prod, create the data as part of the test
79-
// setup in staging.
8077
@Test
8178
public void searchEntries_nullParams() throws IOException {
8279
assertEquals(ImmutableList.of(), client.searchEntry(null, null, null, null));
8380
}
8481

8582
@Test
8683
public void searchEntries_oneResult_hash() throws Exception {
87-
var newRekordRequest = createdRekorRequest();
88-
client.putEntry(newRekordRequest);
8984
assertEquals(
9085
1,
9186
client
92-
.searchEntry(
93-
null, newRekordRequest.getHashedRekord().getData().getHash().getValue(), null, null)
87+
.searchEntry(null, req.getHashedRekord().getData().getHash().getValue(), null, null)
9488
.size());
9589
}
9690

9791
@Test
9892
public void searchEntries_oneResult_publicKey() throws Exception {
99-
var newRekordRequest = createdRekorRequest();
100-
var resp = client.putEntry(newRekordRequest);
10193
assertEquals(
10294
1,
10395
client
@@ -138,29 +130,24 @@ public void searchEntries_zeroResults() throws IOException {
138130

139131
@Test
140132
public void getEntry_entryExists() throws Exception {
141-
var newRekordRequest = createdRekorRequest();
142-
var resp = client.putEntry(newRekordRequest);
143133
var entry = client.getEntry(resp.getUuid());
144-
assertEntry(resp, entry);
134+
assertEntry(resp, entry.get());
145135
}
146136

147137
@Test
148138
public void getEntry_hashedRekordRequest_byCalculatedUuid() throws Exception {
149-
var hashedRekordRequest = createdRekorRequest();
150-
var resp = client.putEntry(hashedRekordRequest);
151139
// getting an entry by hashedrekordrequest should implicitly calculate uuid
152140
// from the contents of the hashedrekord
153-
var entry = client.getEntry(hashedRekordRequest);
154-
assertEntry(resp, entry);
141+
var entry = client.getEntry(req);
142+
assertEntry(resp, entry.get());
155143
}
156144

157-
private void assertEntry(RekorResponse resp, Optional<RekorEntry> entry) {
158-
assertTrue(entry.isPresent());
159-
assertEquals(resp.getEntry().getLogID(), entry.get().getLogID());
160-
assertNotNull(entry.get().getVerification().getInclusionProof().getTreeSize());
161-
assertNotNull(entry.get().getVerification().getInclusionProof().getRootHash());
162-
assertNotNull(entry.get().getVerification().getInclusionProof().getLogIndex());
163-
assertTrue(entry.get().getVerification().getInclusionProof().getHashes().size() > 0);
145+
private void assertEntry(RekorResponse resp, RekorEntry entry) {
146+
assertEquals(resp.getEntry().getLogID(), entry.getLogID());
147+
assertNotNull(entry.getVerification().getInclusionProof().getTreeSize());
148+
assertNotNull(entry.getVerification().getInclusionProof().getRootHash());
149+
assertNotNull(entry.getVerification().getInclusionProof().getLogIndex());
150+
assertTrue(entry.getVerification().getInclusionProof().getHashes().size() > 0);
164151
}
165152

166153
@Test
@@ -172,7 +159,7 @@ public void getEntry_entryDoesntExist() throws Exception {
172159
}
173160

174161
@NotNull
175-
private HashedRekordRequest createdRekorRequest()
162+
private static HashedRekordRequest createdRekorRequest()
176163
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException,
177164
OperatorCreationException, CertificateException, IOException {
178165
// the data we want to sign
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2022 The Sigstore Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package dev.sigstore.testkit.annotations
18+
19+
import org.junit.jupiter.api.condition.DisabledIfSystemProperty
20+
21+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
22+
@DisabledIfSystemProperty(
23+
named = "sigstore-java.test.skipStaging",
24+
matches = "^\\s*+(true|y|on|)\\s*+$",
25+
disabledReason = "sigstore-java.test.skipStaging system property is present",
26+
)
27+
annotation class DisabledIfSkipStaging {}

0 commit comments

Comments
 (0)