-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
1316fe3
commit 5ec77a4
Showing
5 changed files
with
60 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,6 @@ | |
import dev.sigstore.encryption.signers.Signers; | ||
import dev.sigstore.testing.CertGenerator; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.InvalidKeyException; | ||
import java.security.MessageDigest; | ||
|
@@ -39,30 +37,31 @@ | |
import org.hamcrest.MatcherAssert; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RekorClientTest { | ||
|
||
private static final String REKOR_URL = "https://rekor.sigstage.dev"; | ||
private RekorClient client; | ||
private static RekorClient client; | ||
private static HashedRekordRequest req; | ||
private static RekorResponse resp; | ||
|
||
@BeforeEach | ||
public void setupClient() throws URISyntaxException { | ||
// this tests directly against rekor in staging, it's a bit hard to bring up a rekor instance | ||
// without docker compose. | ||
client = RekorClient.builder().setUri(URI.create(REKOR_URL)).build(); | ||
@BeforeAll | ||
public static void setupClient() throws Exception { | ||
// this tests directly against rekor in prod, it's a bit hard to bring up a rekor instance | ||
client = RekorClient.builder().build(); | ||
req = createdRekorRequest(); | ||
resp = client.putEntry(req); | ||
} | ||
|
||
@Test | ||
public void putEntry_toStaging() throws Exception { | ||
public void putEntry() throws Exception { | ||
HashedRekordRequest req = createdRekorRequest(); | ||
var resp = client.putEntry(req); | ||
|
||
// pretty basic testing | ||
MatcherAssert.assertThat( | ||
resp.getEntryLocation().toString(), | ||
CoreMatchers.startsWith(REKOR_URL + "/api/v1/log/entries/")); | ||
CoreMatchers.startsWith(RekorClient.PUBLIC_GOOD_URI + "/api/v1/log/entries/")); | ||
|
||
assertNotNull(resp.getUuid()); | ||
assertNotNull(resp.getRaw()); | ||
|
@@ -72,32 +71,25 @@ public void putEntry_toStaging() throws Exception { | |
assertNotNull(entry.getLogID()); | ||
Assertions.assertTrue(entry.getLogIndex() > 0); | ||
assertNotNull(entry.getVerification().getSignedEntryTimestamp()); | ||
// Assertions.assertNotNull(entry.getVerification().getInclusionProof()); | ||
Assertions.assertNotNull(entry.getVerification().getInclusionProof()); | ||
} | ||
|
||
// TODO([email protected]): don't use data from prod, create the data as part of the test | ||
// setup in staging. | ||
@Test | ||
public void searchEntries_nullParams() throws IOException { | ||
assertEquals(ImmutableList.of(), client.searchEntry(null, null, null, null)); | ||
} | ||
|
||
@Test | ||
public void searchEntries_oneResult_hash() throws Exception { | ||
var newRekordRequest = createdRekorRequest(); | ||
client.putEntry(newRekordRequest); | ||
assertEquals( | ||
1, | ||
client | ||
.searchEntry( | ||
null, newRekordRequest.getHashedRekord().getData().getHash().getValue(), null, null) | ||
.searchEntry(null, req.getHashedRekord().getData().getHash().getValue(), null, null) | ||
.size()); | ||
} | ||
|
||
@Test | ||
public void searchEntries_oneResult_publicKey() throws Exception { | ||
var newRekordRequest = createdRekorRequest(); | ||
var resp = client.putEntry(newRekordRequest); | ||
assertEquals( | ||
1, | ||
client | ||
|
@@ -138,29 +130,24 @@ public void searchEntries_zeroResults() throws IOException { | |
|
||
@Test | ||
public void getEntry_entryExists() throws Exception { | ||
var newRekordRequest = createdRekorRequest(); | ||
var resp = client.putEntry(newRekordRequest); | ||
var entry = client.getEntry(resp.getUuid()); | ||
assertEntry(resp, entry); | ||
assertEntry(resp, entry.get()); | ||
} | ||
|
||
@Test | ||
public void getEntry_hashedRekordRequest_byCalculatedUuid() throws Exception { | ||
var hashedRekordRequest = createdRekorRequest(); | ||
var resp = client.putEntry(hashedRekordRequest); | ||
// getting an entry by hashedrekordrequest should implicitly calculate uuid | ||
// from the contents of the hashedrekord | ||
var entry = client.getEntry(hashedRekordRequest); | ||
assertEntry(resp, entry); | ||
var entry = client.getEntry(req); | ||
assertEntry(resp, entry.get()); | ||
} | ||
|
||
private void assertEntry(RekorResponse resp, Optional<RekorEntry> entry) { | ||
assertTrue(entry.isPresent()); | ||
assertEquals(resp.getEntry().getLogID(), entry.get().getLogID()); | ||
assertNotNull(entry.get().getVerification().getInclusionProof().getTreeSize()); | ||
assertNotNull(entry.get().getVerification().getInclusionProof().getRootHash()); | ||
assertNotNull(entry.get().getVerification().getInclusionProof().getLogIndex()); | ||
assertTrue(entry.get().getVerification().getInclusionProof().getHashes().size() > 0); | ||
private void assertEntry(RekorResponse resp, RekorEntry entry) { | ||
assertEquals(resp.getEntry().getLogID(), entry.getLogID()); | ||
assertNotNull(entry.getVerification().getInclusionProof().getTreeSize()); | ||
assertNotNull(entry.getVerification().getInclusionProof().getRootHash()); | ||
assertNotNull(entry.getVerification().getInclusionProof().getLogIndex()); | ||
assertTrue(entry.getVerification().getInclusionProof().getHashes().size() > 0); | ||
} | ||
|
||
@Test | ||
|
@@ -172,7 +159,7 @@ public void getEntry_entryDoesntExist() throws Exception { | |
} | ||
|
||
@NotNull | ||
private HashedRekordRequest createdRekorRequest() | ||
private static HashedRekordRequest createdRekorRequest() | ||
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, | ||
OperatorCreationException, CertificateException, IOException { | ||
// the data we want to sign | ||
|
27 changes: 27 additions & 0 deletions
27
sigstore-testkit/src/main/kotlin/dev/sigstore/testkit/annotations/DisabledIfSkipStaging.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2022 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package dev.sigstore.testkit.annotations | ||
|
||
import org.junit.jupiter.api.condition.DisabledIfSystemProperty | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
@DisabledIfSystemProperty( | ||
named = "sigstore-java.test.skipStaging", | ||
matches = "^\\s*+(true|y|on|)\\s*+$", | ||
disabledReason = "sigstore-java.test.skipStaging system property is present", | ||
) | ||
annotation class DisabledIfSkipStaging {} |