1
- import type { TransparencyLogEntry } from '@sigstore/bundle' ;
1
+ import type { TLogEntryWithInclusionProof } from '@sigstore/bundle' ;
2
2
import { fromPartial } from '@total-typescript/shoehorn' ;
3
3
import { VerificationError } from '../../../error' ;
4
4
import { verifyCheckpoint } from '../../../tlog/verify/checkpoint' ;
@@ -43,55 +43,34 @@ describe('verifyCheckpoint', () => {
43
43
const checkpoint =
44
44
'rekor.sigstore.dev - 2605736670972794746\n21428036\nrxnoKyFZlJ7/R6bMh/d3lcqwKqAy5CL1LcNBJP17kgQ=\nTimestamp: 1688058656037355364\n\n— rekor.sigstore.dev wNI9ajBFAiEAuDk7uu5Ae8Own/MjhSZNuVzbLuYH2jBMxbSA0WaNDNACIDV4reKpYiOpkwtvazCClnpUuduF2o/th2xR3gRZAUU4\n' ;
45
45
46
- const inclusionProof : TransparencyLogEntry [ 'inclusionProof' ] = fromPartial ( {
47
- checkpoint : { envelope : checkpoint } ,
48
- rootHash : Buffer . from (
49
- 'rxnoKyFZlJ7/R6bMh/d3lcqwKqAy5CL1LcNBJP17kgQ=' ,
50
- 'base64'
51
- ) ,
52
- } ) ;
46
+ const inclusionProof : TLogEntryWithInclusionProof [ 'inclusionProof' ] =
47
+ fromPartial ( {
48
+ checkpoint : { envelope : checkpoint } ,
49
+ rootHash : Buffer . from (
50
+ 'rxnoKyFZlJ7/R6bMh/d3lcqwKqAy5CL1LcNBJP17kgQ=' ,
51
+ 'base64'
52
+ ) ,
53
+ } ) ;
53
54
54
- const entry : TransparencyLogEntry = fromPartial ( {
55
+ const entry : TLogEntryWithInclusionProof = fromPartial ( {
55
56
inclusionProof : inclusionProof ,
56
57
integratedTime : '1688058655' ,
57
58
} ) ;
58
59
59
60
describe ( 'when the entry has a valid checkpoint' , ( ) => {
60
- it ( 'does NOT throw an error' , ( ) => {
61
- expect ( ( ) => verifyCheckpoint ( entry , tlogs ) ) . not . toThrow ( ) ;
62
- } ) ;
63
- } ) ;
64
-
65
- describe ( 'when the entry has no inclusion proof' , ( ) => {
66
- const entryWithoutProof : TransparencyLogEntry = fromPartial ( {
67
- logId : { keyId : keyID } ,
68
- } ) ;
69
-
70
- it ( 'throws a VerificationError' , ( ) => {
71
- expect ( ( ) => verifyCheckpoint ( entryWithoutProof , tlogs ) ) . toThrow (
72
- VerificationError
73
- ) ;
74
- } ) ;
75
- } ) ;
76
-
77
- describe ( 'when the entry has no checkpoint' , ( ) => {
78
- const entryWithoutCheckpoint : TransparencyLogEntry = fromPartial ( {
79
- inclusionProof : { } ,
80
- } ) ;
81
-
82
- it ( 'throws a VerificationError' , ( ) => {
83
- expect ( ( ) => verifyCheckpoint ( entryWithoutCheckpoint , tlogs ) ) . toThrow (
84
- VerificationError
85
- ) ;
61
+ it ( 'returns true' , ( ) => {
62
+ expect ( verifyCheckpoint ( entry , tlogs ) ) . toBe ( true ) ;
86
63
} ) ;
87
64
} ) ;
88
65
89
66
describe ( 'when the checkpoint has no separator' , ( ) => {
90
- const entryWithInvalidCheckpoint : TransparencyLogEntry = fromPartial ( {
91
- inclusionProof : {
92
- checkpoint : { envelope : 'rekor.sigstore.dev - 2605736670972794746' } ,
93
- } ,
94
- } ) ;
67
+ const entryWithInvalidCheckpoint : TLogEntryWithInclusionProof = fromPartial (
68
+ {
69
+ inclusionProof : {
70
+ checkpoint : { envelope : 'rekor.sigstore.dev - 2605736670972794746' } ,
71
+ } ,
72
+ }
73
+ ) ;
95
74
96
75
it ( 'throws a VerificationError' , ( ) => {
97
76
expect ( ( ) => verifyCheckpoint ( entryWithInvalidCheckpoint , tlogs ) ) . toThrow (
@@ -101,14 +80,16 @@ describe('verifyCheckpoint', () => {
101
80
} ) ;
102
81
103
82
describe ( 'when the checkpoint signature is malformed' , ( ) => {
104
- const entryWithInvalidCheckpoint : TransparencyLogEntry = fromPartial ( {
105
- inclusionProof : {
106
- checkpoint : {
107
- envelope :
108
- 'rekor.sigstore.dev - 2605736670972794746\n\n— rekor.sigstore.dev foo\n' ,
83
+ const entryWithInvalidCheckpoint : TLogEntryWithInclusionProof = fromPartial (
84
+ {
85
+ inclusionProof : {
86
+ checkpoint : {
87
+ envelope :
88
+ 'rekor.sigstore.dev - 2605736670972794746\n\n— rekor.sigstore.dev foo\n' ,
89
+ } ,
109
90
} ,
110
- } ,
111
- } ) ;
91
+ }
92
+ ) ;
112
93
113
94
it ( 'throws a VerificationError' , ( ) => {
114
95
expect ( ( ) => verifyCheckpoint ( entryWithInvalidCheckpoint , tlogs ) ) . toThrow (
@@ -118,7 +99,7 @@ describe('verifyCheckpoint', () => {
118
99
} ) ;
119
100
120
101
describe ( 'when the checkpoint has no signature' , ( ) => {
121
- const entryWitInvalidCheckpoint : TransparencyLogEntry = fromPartial ( {
102
+ const entryWitInvalidCheckpoint : TLogEntryWithInclusionProof = fromPartial ( {
122
103
inclusionProof : {
123
104
checkpoint : {
124
105
envelope : 'rekor.sigstore.dev - 2605736670972794746\n\n' ,
@@ -134,14 +115,16 @@ describe('verifyCheckpoint', () => {
134
115
} ) ;
135
116
136
117
describe ( 'when the checkpoint header is too short' , ( ) => {
137
- const entryWithInvalidCheckpoint : TransparencyLogEntry = fromPartial ( {
138
- inclusionProof : {
139
- checkpoint : {
140
- envelope :
141
- 'rekor.sigstore.dev\n\n— rekor.sigstore.dev wNI9ajBFAiEAu\n' ,
118
+ const entryWithInvalidCheckpoint : TLogEntryWithInclusionProof = fromPartial (
119
+ {
120
+ inclusionProof : {
121
+ checkpoint : {
122
+ envelope :
123
+ 'rekor.sigstore.dev\n\n— rekor.sigstore.dev wNI9ajBFAiEAu\n' ,
124
+ } ,
142
125
} ,
143
- } ,
144
- } ) ;
126
+ }
127
+ ) ;
145
128
146
129
it ( 'throws a VerificationError' , ( ) => {
147
130
expect ( ( ) => verifyCheckpoint ( entryWithInvalidCheckpoint , tlogs ) ) . toThrow (
@@ -151,13 +134,15 @@ describe('verifyCheckpoint', () => {
151
134
} ) ;
152
135
153
136
describe ( 'when the checkpoint origin is empty' , ( ) => {
154
- const entryWithInvalidCheckpoint : TransparencyLogEntry = fromPartial ( {
155
- inclusionProof : {
156
- checkpoint : {
157
- envelope : '\nA\nB\nC\n\n— rekor.sigstore.dev wNI9ajBFAiEAu\n' ,
137
+ const entryWithInvalidCheckpoint : TLogEntryWithInclusionProof = fromPartial (
138
+ {
139
+ inclusionProof : {
140
+ checkpoint : {
141
+ envelope : '\nA\nB\nC\n\n— rekor.sigstore.dev wNI9ajBFAiEAu\n' ,
142
+ } ,
158
143
} ,
159
- } ,
160
- } ) ;
144
+ }
145
+ ) ;
161
146
162
147
it ( 'throws a VerificationError' , ( ) => {
163
148
expect ( ( ) => verifyCheckpoint ( entryWithInvalidCheckpoint , tlogs ) ) . toThrow (
@@ -167,46 +152,43 @@ describe('verifyCheckpoint', () => {
167
152
} ) ;
168
153
169
154
describe ( 'when the entry checkpoint has the wrong root hash' , ( ) => {
170
- const entry : TransparencyLogEntry = fromPartial ( {
155
+ const entry : TLogEntryWithInclusionProof = fromPartial ( {
171
156
inclusionProof : { ...inclusionProof , rootHash : Buffer . from ( 'foo' ) } ,
172
157
} ) ;
173
- it ( 'does NOT throw an error' , ( ) => {
174
- expect ( ( ) => verifyCheckpoint ( entry , tlogs ) ) . toThrow ( VerificationError ) ;
158
+
159
+ it ( 'returns false' , ( ) => {
160
+ expect ( verifyCheckpoint ( entry , tlogs ) ) . toBe ( false ) ;
175
161
} ) ;
176
162
} ) ;
177
163
178
164
describe ( 'when the entry checkpoint has a bad signature' , ( ) => {
179
165
const badSignatureCheckpoint =
180
166
'rekor.sigstore.dev - 2605736670972794746\n21428036\nrxnoKyFZlJ7/R6bMh/d3lcqwKqAy5CL1LcNBJP17kgQ=\nTimestamp: 1688058656037355364\n\n— rekor.sigstore.dev wNI9ajBFAiEAuDk7uu5Ae8Own\n' ;
181
167
182
- const entryWithBadCheckpointSig : TransparencyLogEntry = fromPartial ( {
168
+ const entryWithBadCheckpointSig : TLogEntryWithInclusionProof = fromPartial ( {
183
169
inclusionProof : {
184
170
...inclusionProof ,
185
171
checkpoint : { envelope : badSignatureCheckpoint } ,
186
172
} ,
187
173
} ) ;
188
174
189
- it ( 'throws a VerificationError' , ( ) => {
190
- expect ( ( ) => verifyCheckpoint ( entryWithBadCheckpointSig , tlogs ) ) . toThrow (
191
- VerificationError
192
- ) ;
175
+ it ( 'returns false' , ( ) => {
176
+ expect ( verifyCheckpoint ( entryWithBadCheckpointSig , tlogs ) ) . toBe ( false ) ;
193
177
} ) ;
194
178
} ) ;
195
179
196
180
describe ( 'when there is no transparency log with the given key ID' , ( ) => {
197
181
const checkpointWithBadKeyHint =
198
182
'rekor.sigstore.dev - 2605736670972794746\n21428036\nrxnoKyFZlJ7/R6bMh/d3lcqwKqAy5CL1LcNBJP17kgQ=\nTimestamp: 1688058656037355364\n\n— rekor.sigstore.dev xNI9ajBFAiEAuDk7uu5Ae8Own/MjhSZNuVzbLuYH2jBMxbSA0WaNDNACIDV4reKpYiOpkwtvazCClnpUuduF2o/th2xR3gRZAUU4\n' ;
199
- const entryWithBadLogID : TransparencyLogEntry = fromPartial ( {
183
+ const entryWithBadLogID : TLogEntryWithInclusionProof = fromPartial ( {
200
184
inclusionProof : {
201
185
...inclusionProof ,
202
186
checkpoint : { envelope : checkpointWithBadKeyHint } ,
203
187
} ,
204
188
} ) ;
205
189
206
- it ( 'throws a VerificationError' , ( ) => {
207
- expect ( ( ) => verifyCheckpoint ( entryWithBadLogID , tlogs ) ) . toThrow (
208
- VerificationError
209
- ) ;
190
+ it ( 'returns false' , ( ) => {
191
+ expect ( verifyCheckpoint ( entryWithBadLogID , tlogs ) ) . toBe ( false ) ;
210
192
} ) ;
211
193
} ) ;
212
194
@@ -221,10 +203,8 @@ describe('verifyCheckpoint', () => {
221
203
} ,
222
204
] ;
223
205
224
- it ( 'throws a VerificationError' , ( ) => {
225
- expect ( ( ) => verifyCheckpoint ( entry , invalidTLogs ) ) . toThrow (
226
- VerificationError
227
- ) ;
206
+ it ( 'returns false' , ( ) => {
207
+ expect ( verifyCheckpoint ( entry , invalidTLogs ) ) . toBe ( false ) ;
228
208
} ) ;
229
209
} ) ;
230
210
@@ -238,10 +218,9 @@ describe('verifyCheckpoint', () => {
238
218
} ,
239
219
} ,
240
220
] ;
241
- it ( 'throws a VerificationError' , ( ) => {
242
- expect ( ( ) => verifyCheckpoint ( entry , invalidTLogs ) ) . toThrow (
243
- VerificationError
244
- ) ;
221
+
222
+ it ( 'returns false' , ( ) => {
223
+ expect ( verifyCheckpoint ( entry , invalidTLogs ) ) . toBe ( false ) ;
245
224
} ) ;
246
225
} ) ;
247
226
@@ -258,10 +237,9 @@ describe('verifyCheckpoint', () => {
258
237
} ,
259
238
} ,
260
239
] ;
261
- it ( 'throws a VerificationError' , ( ) => {
262
- expect ( ( ) => verifyCheckpoint ( entry , invalidTLogs ) ) . toThrow (
263
- VerificationError
264
- ) ;
240
+
241
+ it ( 'returns false' , ( ) => {
242
+ expect ( verifyCheckpoint ( entry , invalidTLogs ) ) . toBe ( false ) ;
265
243
} ) ;
266
244
} ) ;
267
245
} ) ;
0 commit comments