24
24
import dev .sigstore .encryption .signers .Signers ;
25
25
import dev .sigstore .testing .CertGenerator ;
26
26
import java .io .IOException ;
27
- import java .net .URI ;
28
- import java .net .URISyntaxException ;
29
27
import java .nio .charset .StandardCharsets ;
30
28
import java .security .InvalidKeyException ;
31
29
import java .security .MessageDigest ;
39
37
import org .hamcrest .MatcherAssert ;
40
38
import org .jetbrains .annotations .NotNull ;
41
39
import org .junit .jupiter .api .Assertions ;
42
- import org .junit .jupiter .api .BeforeEach ;
40
+ import org .junit .jupiter .api .BeforeAll ;
43
41
import org .junit .jupiter .api .Test ;
44
42
45
43
public class RekorClientTest {
46
44
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 ;
49
48
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 );
55
55
}
56
56
57
57
@ Test
58
- public void putEntry_toStaging () throws Exception {
58
+ public void putEntry () throws Exception {
59
59
HashedRekordRequest req = createdRekorRequest ();
60
60
var resp = client .putEntry (req );
61
-
62
61
// pretty basic testing
63
62
MatcherAssert .assertThat (
64
63
resp .getEntryLocation ().toString (),
65
- CoreMatchers .startsWith (REKOR_URL + "/api/v1/log/entries/" ));
64
+ CoreMatchers .startsWith (RekorClient . PUBLIC_GOOD_URI + "/api/v1/log/entries/" ));
66
65
67
66
assertNotNull (resp .getUuid ());
68
67
assertNotNull (resp .getRaw ());
@@ -72,32 +71,25 @@ public void putEntry_toStaging() throws Exception {
72
71
assertNotNull (entry .getLogID ());
73
72
Assertions .assertTrue (entry .getLogIndex () > 0 );
74
73
assertNotNull (entry .getVerification ().getSignedEntryTimestamp ());
75
- // Assertions.assertNotNull(entry.getVerification().getInclusionProof());
74
+ Assertions .assertNotNull (entry .getVerification ().getInclusionProof ());
76
75
}
77
76
78
- // TODO([email protected] ): don't use data from prod, create the data as part of the test
79
- // setup in staging.
80
77
@ Test
81
78
public void searchEntries_nullParams () throws IOException {
82
79
assertEquals (ImmutableList .of (), client .searchEntry (null , null , null , null ));
83
80
}
84
81
85
82
@ Test
86
83
public void searchEntries_oneResult_hash () throws Exception {
87
- var newRekordRequest = createdRekorRequest ();
88
- client .putEntry (newRekordRequest );
89
84
assertEquals (
90
85
1 ,
91
86
client
92
- .searchEntry (
93
- null , newRekordRequest .getHashedRekord ().getData ().getHash ().getValue (), null , null )
87
+ .searchEntry (null , req .getHashedRekord ().getData ().getHash ().getValue (), null , null )
94
88
.size ());
95
89
}
96
90
97
91
@ Test
98
92
public void searchEntries_oneResult_publicKey () throws Exception {
99
- var newRekordRequest = createdRekorRequest ();
100
- var resp = client .putEntry (newRekordRequest );
101
93
assertEquals (
102
94
1 ,
103
95
client
@@ -138,29 +130,24 @@ public void searchEntries_zeroResults() throws IOException {
138
130
139
131
@ Test
140
132
public void getEntry_entryExists () throws Exception {
141
- var newRekordRequest = createdRekorRequest ();
142
- var resp = client .putEntry (newRekordRequest );
143
133
var entry = client .getEntry (resp .getUuid ());
144
- assertEntry (resp , entry );
134
+ assertEntry (resp , entry . get () );
145
135
}
146
136
147
137
@ Test
148
138
public void getEntry_hashedRekordRequest_byCalculatedUuid () throws Exception {
149
- var hashedRekordRequest = createdRekorRequest ();
150
- var resp = client .putEntry (hashedRekordRequest );
151
139
// getting an entry by hashedrekordrequest should implicitly calculate uuid
152
140
// 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 () );
155
143
}
156
144
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 );
164
151
}
165
152
166
153
@ Test
@@ -172,7 +159,7 @@ public void getEntry_entryDoesntExist() throws Exception {
172
159
}
173
160
174
161
@ NotNull
175
- private HashedRekordRequest createdRekorRequest ()
162
+ private static HashedRekordRequest createdRekorRequest ()
176
163
throws NoSuchAlgorithmException , InvalidKeyException , SignatureException ,
177
164
OperatorCreationException , CertificateException , IOException {
178
165
// the data we want to sign
0 commit comments