Skip to content

Commit

Permalink
fix(agent): SHA256SUMS being looked up in the parent directory (#842)
Browse files Browse the repository at this point in the history
We didn't notice this behaviour in tests because our mocked file server
was serving files in the root directory (since the parent of / is /
everything just worked).

Changing tests to serve and search files inside a subdirectory reveal
the problem: we're not looking for the checksums file beside the rootfs
but rather in the parent directory. We see log lines like below:

> time="2024-07-18T10:42:53-03:00" level=debug msg="Landscape: received
command Install. Target:
testDistro_UP4W_TestInstall_Error_when_the_checksum_entry_is_missing_for_the_rootfs_5721719220902747386"
> time="2024-07-18T10:42:53-03:00" level=info msg="checksums file
http://127.0.0.1:57850/releases/SHA256SUM" not found"

---
UDENG-3669
  • Loading branch information
CarlosNihelton authored Jul 18, 2024
2 parents 2042e21 + b75c5f5 commit 524a934
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion windows-agent/internal/proservices/landscape/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func download(ctx context.Context, u *url.URL, destination string) (err error) {
// ...
func wantRootfsChecksum(ctx context.Context, u *url.URL) (string, error) {
imageName := filepath.Base(u.Path)
shasRelativeURL, err := url.Parse("../SHA256SUMS")
shasRelativeURL, err := url.Parse("SHA256SUMS")
if err != nil {
return "", fmt.Errorf("could not assemble SHA256SUMS location: %v", err)
}
Expand Down
16 changes: 9 additions & 7 deletions windows-agent/internal/proservices/landscape/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func TestInstall(t *testing.T) {
u := tc.sendRootfsURL
var err error
if tc.sendRootfsURL != brokenURL {
u, err = url.JoinPath(fileServerAddr, tc.sendRootfsURL)
u, err = url.JoinPath(fileServerAddr, "/releases/theone", tc.sendRootfsURL)
require.NoError(t, err, "Setup: could not assemble URL: %s + %s", fileServerAddr, tc.sendRootfsURL)
}

Expand Down Expand Up @@ -329,20 +329,22 @@ func mockRootfsFileServer(t *testing.T, ctx context.Context, enableChecksumsFile

mux := http.NewServeMux()

mux.HandleFunc("GET /goodfile", func(w http.ResponseWriter, r *http.Request) {}) // Return empty file
mux.HandleFunc("GET /badchecksum", func(w http.ResponseWriter, r *http.Request) {}) // Return empty file
mux.HandleFunc("GET /rootfswithnochecksum", func(w http.ResponseWriter, r *http.Request) {}) // intentionally not in the checksums file
mux.HandleFunc("GET /badfile", func(w http.ResponseWriter, r *http.Request) {
const getFile = "GET /releases/theone/%s"

mux.HandleFunc(fmt.Sprintf(getFile, "goodfile"), func(w http.ResponseWriter, r *http.Request) {}) // Return empty file
mux.HandleFunc(fmt.Sprintf(getFile, "badchecksum"), func(w http.ResponseWriter, r *http.Request) {}) // Return empty file
mux.HandleFunc(fmt.Sprintf(getFile, "rootfswithnochecksum"), func(w http.ResponseWriter, r *http.Request) {}) // intentionally not in the checksums file
mux.HandleFunc(fmt.Sprintf(getFile, "badfile"), func(w http.ResponseWriter, r *http.Request) {
_, err := fmt.Fprintf(w, "MOCK_ERROR")
if err != nil {
t.Logf("mockRootfsFileServer: could not write response: %v", err)
}
})
mux.HandleFunc("GET /badresponse", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf(getFile, "badresponse"), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
})
if enableChecksumsFile {
mux.HandleFunc("GET /SHA256SUMS", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(fmt.Sprintf(getFile, "SHA256SUMS"), func(w http.ResponseWriter, r *http.Request) {
_, err := fmt.Fprintf(w, `e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 *goodfile
afe55cda4210c2439b47c62c01039027522f7ed4abdb113972b3030b3359532a *badfile
1234 *badchecksum
Expand Down

0 comments on commit 524a934

Please sign in to comment.