Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conflict between enable_ac_key_instance_mangling and disable_http_ac_validation #792

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (h *httpCache) CacheHandler(w http.ResponseWriter, r *http.Request) {
return
}

if h.mangleACKeys && kind == cache.AC {
if h.mangleACKeys && (kind == cache.AC || kind == cache.RAW) {
hash = cache.TransformActionCacheKey(hash, instance, h.accessLogger)
}

Expand Down
57 changes: 57 additions & 0 deletions server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -506,3 +507,59 @@ func TestRemoteReturnsNotFound(t *testing.T) {
t.Errorf("Wrong status code, expected %d, got %d", http.StatusNotFound, statusCode)
}
}

func TestManglingACKeys(t *testing.T) {
cacheDir, err := os.MkdirTemp("", "bazel-remote")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(cacheDir)

blobSize := int64(1024)
cacheSize := blobSize*2 + disk.BlockSize
diskCache, err := disk.New(cacheDir, cacheSize, disk.WithAccessLogger(testutils.NewSilentLogger()))
if err != nil {
t.Fatal(err)
}

h := NewHTTPCache(diskCache, testutils.NewSilentLogger(), testutils.NewSilentLogger(), false, true, false, false, "")
// create a fake http.Request
data, hash := testutils.RandomDataAndHash(blobSize)
err = diskCache.Put(context.Background(), cache.RAW, hash, int64(len(data)), bytes.NewReader(data))
if err != nil {
t.Fatal(err)
}

url, _ := url.Parse(fmt.Sprintf("http://localhost:8080/ac/%s", hash))
reader := bytes.NewReader([]byte{})
body := io.NopCloser(reader)
req := &http.Request{
Method: "GET",
URL: url,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Body: body,
}
statusCode := 0
respWriter := &fakeResponseWriter{
statusCode: &statusCode,
}
h.CacheHandler(respWriter, req)
if statusCode != 0 {
t.Errorf("Wrong status code, expected %d, got %d", 0, statusCode)
}

url, _ = url.Parse(fmt.Sprintf("http://localhost:8080/test-instance/ac/%s", hash))
reader.Reset([]byte{})
body.Close()
body = io.NopCloser(reader)
req.URL = url
req.Body = body
statusCode = 0

h.CacheHandler(respWriter, req)
if statusCode != http.StatusNotFound {
t.Errorf("Wrong status code, expected %d, got %d", http.StatusNotFound, statusCode)
}
}
Loading