Skip to content

Commit df86f7e

Browse files
committed
fix: conflict between enable_ac_key_instance_mangling and disable_http_ac_validation
Signed-off-by: hyphennn <[email protected]>
1 parent a563ac2 commit df86f7e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

server/http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (h *httpCache) CacheHandler(w http.ResponseWriter, r *http.Request) {
212212
return
213213
}
214214

215-
if h.mangleACKeys && kind == cache.AC {
215+
if h.mangleACKeys && (kind == cache.AC || kind == cache.RAW) {
216216
hash = cache.TransformActionCacheKey(hash, instance, h.accessLogger)
217217
}
218218

server/http_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package server
22

33
import (
44
"bytes"
5+
"context"
56
"crypto/sha256"
67
"encoding/hex"
78
"encoding/json"
@@ -506,3 +507,59 @@ func TestRemoteReturnsNotFound(t *testing.T) {
506507
t.Errorf("Wrong status code, expected %d, got %d", http.StatusNotFound, statusCode)
507508
}
508509
}
510+
511+
func TestManglingACKeys(t *testing.T) {
512+
cacheDir, err := os.MkdirTemp("", "bazel-remote")
513+
if err != nil {
514+
t.Fatal(err)
515+
}
516+
defer os.RemoveAll(cacheDir)
517+
518+
blobSize := int64(1024)
519+
cacheSize := blobSize*2 + disk.BlockSize
520+
diskCache, err := disk.New(cacheDir, cacheSize, disk.WithAccessLogger(testutils.NewSilentLogger()))
521+
if err != nil {
522+
t.Fatal(err)
523+
}
524+
525+
h := NewHTTPCache(diskCache, testutils.NewSilentLogger(), testutils.NewSilentLogger(), false, true, false, false, "")
526+
// create a fake http.Request
527+
data, hash := testutils.RandomDataAndHash(blobSize)
528+
err = diskCache.Put(context.Background(), cache.RAW, hash, int64(len(data)), bytes.NewReader(data))
529+
if err != nil {
530+
t.Fatal(err)
531+
}
532+
533+
url, _ := url.Parse(fmt.Sprintf("http://localhost:8080/ac/%s", hash))
534+
reader := bytes.NewReader([]byte{})
535+
body := io.NopCloser(reader)
536+
req := &http.Request{
537+
Method: "GET",
538+
URL: url,
539+
Proto: "HTTP/1.1",
540+
ProtoMajor: 1,
541+
ProtoMinor: 1,
542+
Body: body,
543+
}
544+
statusCode := 0
545+
respWriter := &fakeResponseWriter{
546+
statusCode: &statusCode,
547+
}
548+
h.CacheHandler(respWriter, req)
549+
if statusCode != 0 {
550+
t.Errorf("Wrong status code, expected %d, got %d", 0, statusCode)
551+
}
552+
553+
url, _ = url.Parse(fmt.Sprintf("http://localhost:8080/test-instance/ac/%s", hash))
554+
reader.Reset([]byte{})
555+
body.Close()
556+
body = io.NopCloser(reader)
557+
req.URL = url
558+
req.Body = body
559+
statusCode = 0
560+
561+
h.CacheHandler(respWriter, req)
562+
if statusCode != http.StatusNotFound {
563+
t.Errorf("Wrong status code, expected %d, got %d", http.StatusNotFound, statusCode)
564+
}
565+
}

0 commit comments

Comments
 (0)