29
29
import build .bazel .remote .asset .v1 .FetchGrpc .FetchImplBase ;
30
30
import build .bazel .remote .asset .v1 .Qualifier ;
31
31
import build .bazel .remote .execution .v2 .Digest ;
32
+ import build .bazel .remote .execution .v2 .DigestFunction ;
32
33
import build .bazel .remote .execution .v2 .RequestMetadata ;
33
34
import build .bazel .remote .execution .v2 .ServerCapabilities ;
34
35
import com .google .auth .Credentials ;
@@ -96,8 +97,10 @@ public class GrpcRemoteDownloaderTest {
96
97
97
98
private static final ManualClock clock = new ManualClock ();
98
99
100
+ // Use an unusual default to verify that the hash function used to generate a given Checksum is
101
+ // propagated correctly.
99
102
private static final DigestUtil DIGEST_UTIL =
100
- new DigestUtil (SyscallCache .NO_CACHE , DigestHashFunction .SHA256 );
103
+ new DigestUtil (SyscallCache .NO_CACHE , DigestHashFunction .SHA1 );
101
104
102
105
private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry ();
103
106
private final String fakeServerName = "fake server for " + getClass ();
@@ -277,7 +280,8 @@ public void fetchBlob(
277
280
@ Test
278
281
public void testPropagateChecksum () throws Exception {
279
282
final byte [] content = "example content" .getBytes (UTF_8 );
280
- final Digest contentDigest = DIGEST_UTIL .compute (content );
283
+ final DigestUtil digestUtil = new DigestUtil (SyscallCache .NO_CACHE , DigestHashFunction .SHA256 );
284
+ final Digest contentDigest = digestUtil .compute (content );
281
285
282
286
serviceRegistry .addService (
283
287
new FetchImplBase () {
@@ -287,7 +291,7 @@ public void fetchBlob(
287
291
assertThat (request )
288
292
.isEqualTo (
289
293
FetchBlobRequest .newBuilder ()
290
- .setDigestFunction (DIGEST_UTIL .getDigestFunction ())
294
+ .setDigestFunction (digestUtil .getDigestFunction ())
291
295
.addUris ("http://example.com/content.txt" )
292
296
.addQualifiers (
293
297
Qualifier .newBuilder ()
@@ -316,7 +320,8 @@ public void fetchBlob(
316
320
@ Test
317
321
public void testRejectChecksumMismatch () throws Exception {
318
322
final byte [] content = "example content" .getBytes (UTF_8 );
319
- final Digest contentDigest = DIGEST_UTIL .compute (content );
323
+ final DigestUtil digestUtil = new DigestUtil (SyscallCache .NO_CACHE , DigestHashFunction .SHA256 );
324
+ final Digest contentDigest = digestUtil .compute (content );
320
325
321
326
serviceRegistry .addService (
322
327
new FetchImplBase () {
@@ -326,7 +331,7 @@ public void fetchBlob(
326
331
assertThat (request )
327
332
.isEqualTo (
328
333
FetchBlobRequest .newBuilder ()
329
- .setDigestFunction (DIGEST_UTIL .getDigestFunction ())
334
+ .setDigestFunction (digestUtil .getDigestFunction ())
330
335
.addUris ("http://example.com/content.txt" )
331
336
.addQualifiers (
332
337
Qualifier .newBuilder ()
@@ -355,7 +360,7 @@ public void fetchBlob(
355
360
Optional .of (Checksum .fromString (KeyType .SHA256 , contentDigest .getHash ()))));
356
361
357
362
assertThat (e ).hasMessageThat ().contains (contentDigest .getHash ());
358
- assertThat (e ).hasMessageThat ().contains (DIGEST_UTIL .computeAsUtf8 ("wrong content" ).getHash ());
363
+ assertThat (e ).hasMessageThat ().contains (digestUtil .computeAsUtf8 ("wrong content" ).getHash ());
359
364
}
360
365
361
366
@ Test
@@ -382,7 +387,7 @@ public void testFetchBlobRequest() throws Exception {
382
387
.isEqualTo (
383
388
FetchBlobRequest .newBuilder ()
384
389
.setInstanceName ("instance name" )
385
- .setDigestFunction (DIGEST_UTIL . getDigestFunction () )
390
+ .setDigestFunction (DigestFunction . Value . SHA256 )
386
391
.addUris ("http://example.com/a" )
387
392
.addUris ("http://example.com/b" )
388
393
.addUris ("file:/not/limited/to/http" )
@@ -431,7 +436,7 @@ public void testFetchBlobRequest_withCredentialsPropagation() throws Exception {
431
436
.isEqualTo (
432
437
FetchBlobRequest .newBuilder ()
433
438
.setInstanceName ("instance name" )
434
- .setDigestFunction (DIGEST_UTIL . getDigestFunction () )
439
+ .setDigestFunction (DigestFunction . Value . SHA256 )
435
440
.addUris ("http://example.com/a" )
436
441
.addQualifiers (
437
442
Qualifier .newBuilder ()
@@ -474,7 +479,7 @@ public void testFetchBlobRequest_withoutCredentialsPropagation() throws Exceptio
474
479
.isEqualTo (
475
480
FetchBlobRequest .newBuilder ()
476
481
.setInstanceName ("instance name" )
477
- .setDigestFunction (DIGEST_UTIL . getDigestFunction () )
482
+ .setDigestFunction (DigestFunction . Value . SHA256 )
478
483
.addUris ("http://example.com/a" )
479
484
.addQualifiers (
480
485
Qualifier .newBuilder ()
0 commit comments