@@ -617,31 +617,65 @@ func TestTrustlessCarEntityBytes(t *testing.T) {
617
617
),
618
618
},
619
619
{
620
- Name : "GET CAR with entity-bytes requesting a range from the end of a file" ,
620
+ Name : "GET CAR with entity-bytes requesting a negative range bigger than the length of a file" ,
621
621
Hint : `
622
- The response MUST contain only the minimal set of blocks necessary for fulfilling the range request
622
+ When range starts on negative index that makes it bigger than the file
623
+ the request is truncated and starts at the beginning of a file.
624
+ ` ,
625
+ Request : Request ().
626
+ Path ("/ipfs/{{cid}}" , subdirWithMixedBlockFiles .MustGetCidWithCodec (0x70 , "subdir" , "multiblock.txt" )).
627
+ Query ("format" , "car" ).
628
+ Query ("dag-scope" , "entity" ).
629
+ Query ("entity-bytes" , "-9999:*" ), // multiblock.txt size is 1026 (4*256+2)
630
+ Response : Expect ().
631
+ Status (200 ).
632
+ Body (
633
+ IsCar ().
634
+ IgnoreRoots ().
635
+ HasBlocks ( // expect entire file
636
+ flattenStrings (t ,
637
+ subdirWithMixedBlockFiles .MustGetCid ("subdir" , "multiblock.txt" ), // dag-pb root of the file DAG
638
+ "bafkreie5noke3mb7hqxukzcy73nl23k6lxszxi5w3dtmuwz62wnvkpsscm" , // 256 chunk
639
+ "bafkreih4ephajybraj6wnxsbwjwa77fukurtpl7oj7t7pfq545duhot7cq" , // 256
640
+ "bafkreigu7buvm3cfunb35766dn7tmqyh2um62zcio63en2btvxuybgcpue" , // 256
641
+ "bafkreicll3huefkc3qnrzeony7zcfo7cr3nbx64hnxrqzsixpceg332fhe" , // 256
642
+ "bafkreifst3pqztuvj57lycamoi7z34b4emf7gawxs74nwrc2c7jncmpaqm" , // 2
643
+ )... ).
644
+ Exactly ().
645
+ InThatOrder (),
646
+ ),
647
+ },
648
+ {
649
+ Name : "GET CAR with entity-bytes requesting a range from the end of a file that is bigger than a file itself" ,
650
+ Hint : `
651
+ The response MUST contain only the minimal set of blocks necessary for fulfilling the range request,
652
+ everything before file start is ignored and the explicit end of the range is respected.
623
653
` ,
624
654
Request : Request ().
625
655
Path ("/ipfs/{{cid}}" , subdirWithMixedBlockFiles .MustGetCidWithCodec (0x70 , "subdir" , "multiblock.txt" )).
626
656
Query ("format" , "car" ).
627
657
Query ("dag-scope" , "entity" ).
628
- Query ("entity-bytes" , "-999999 :-3" ),
658
+ Query ("entity-bytes" , "-9999 :-3" ), // multiblock.txt size is 1026 (4*256+2)
629
659
Response : Expect ().
630
660
Status (200 ).
631
661
Body (
632
662
IsCar ().
633
663
IgnoreRoots ().
634
664
HasBlocks (
635
665
flattenStrings (t ,
636
- subdirWithMixedBlockFiles .MustGetCid ("subdir" , "multiblock.txt" ),
637
- subdirWithMixedBlockFiles .MustGetDescendantsCids ("subdir" , "multiblock.txt" )[:5 ])... ,
638
- ).
666
+ subdirWithMixedBlockFiles .MustGetCid ("subdir" , "multiblock.txt" ), // dag-pb root of the file DAG
667
+ "bafkreie5noke3mb7hqxukzcy73nl23k6lxszxi5w3dtmuwz62wnvkpsscm" , // 256 chunk
668
+ "bafkreih4ephajybraj6wnxsbwjwa77fukurtpl7oj7t7pfq545duhot7cq" , // 256
669
+ "bafkreigu7buvm3cfunb35766dn7tmqyh2um62zcio63en2btvxuybgcpue" , // 256
670
+ "bafkreicll3huefkc3qnrzeony7zcfo7cr3nbx64hnxrqzsixpceg332fhe" , // 256
671
+ // skip "bafkreifst3pqztuvj57lycamoi7z34b4emf7gawxs74nwrc2c7jncmpaqm", // 2
672
+ )... ).
639
673
Exactly ().
640
674
InThatOrder (),
641
675
),
642
676
},
643
677
{
644
- Name : "GET CAR with entity-bytes requesting the first byte of a file" ,
678
+ Name : "GET CAR with entity-bytes requesting only the blocks for the first byte of a file" ,
645
679
Hint : `
646
680
The response MUST contain only the first block of the file.
647
681
` ,
@@ -835,6 +869,7 @@ func TestTrustlessCarOrderAndDuplicates(t *testing.T) {
835
869
RunWithSpecs (t , tests , specs .TrustlessGatewayCAROptional )
836
870
}
837
871
872
+ // TODO: this feels like it could be an internal detail of HasBlocks
838
873
func flattenStrings (t * testing.T , values ... interface {}) []string {
839
874
var res []string
840
875
for _ , v := range values {
0 commit comments