Skip to content

Commit

Permalink
Fix the monitor racing test
Browse files Browse the repository at this point in the history
  • Loading branch information
oskirby committed Jul 7, 2024
1 parent 02c9b10 commit ab9c54f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (a *autographer) handleGetAuthKeyIDs(w http.ResponseWriter, r *http.Request
w.Write(signerIDsJSON)
}

func (a *autographer) handleGetX5u(w http.ResponseWriter, r *http.Request) {
func (a *autographer) handleGetX5U(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
httpError(w, r, http.StatusMethodNotAllowed, "%s method not allowed; endpoint accepts GET only", r.Method)
return
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func run(conf configuration, listen string, debug bool) {
router.HandleFunc("/sign/data", ag.handleSignature).Methods("POST")
router.HandleFunc("/sign/hash", ag.handleSignature).Methods("POST")
router.HandleFunc("/auths/{auth_id:[a-zA-Z0-9-_]{1,255}}/keyids", ag.handleGetAuthKeyIDs).Methods("GET")
router.HandleFunc("/x5u/{keyid:[a-zA-Z0-9-_]{1,64}}/{chainfile:[a-zA-Z0-9-_.]{1,255}}", ag.handleGetX5u).Methods("GET")
router.HandleFunc("/x5u/{keyid:[a-zA-Z0-9-_]{1,64}}/{chainfile:[a-zA-Z0-9-_.]{1,255}}", ag.handleGetX5U).Methods("GET")
if os.Getenv("AUTOGRAPH_PROFILE") == "1" {
err = setRuntimeConfig()
if err != nil {
Expand Down
21 changes: 20 additions & 1 deletion monitor_handler_racing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/gorilla/mux"
"github.com/mozilla-services/autograph/formats"
"github.com/mozilla-services/autograph/signer/apk2"
"github.com/mozilla-services/autograph/signer/contentsignature"
Expand All @@ -28,6 +30,23 @@ import (

const autographDevRootHash = `5E:36:F2:14:DE:82:3F:8B:29:96:89:23:5F:03:41:AC:AF:A0:75:AF:82:CB:4C:D4:30:7C:3D:B3:43:39:2A:FE`

func getMirroredX5U(x5u string) (body []byte, err error) {
req, err := http.NewRequest("GET", x5u, nil)
if err != nil {
return nil, err
}
segs := strings.Split(req.URL.Path, "/")
req = mux.SetURLVars(req, map[string]string{"keyid": segs[len(segs)-2], "chainfile": segs[len(segs)-1]})

w := httptest.NewRecorder()
ag.handleGetX5U(w, req)
if w.Code != http.StatusOK || w.Body.String() == "" {
return nil, fmt.Errorf("fetch x5u failed with %d: %s; request was: %+v", w.Code, w.Body.String(), req)
}

return w.Body.Bytes(), nil
}

func TestMonitorPass(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -64,7 +83,7 @@ func TestMonitorPass(t *testing.T) {
t.Fatalf("verification of monitoring response failed: %v", err)
}
case contentsignaturepki.Type:
body, _, err := contentsignaturepki.GetX5U(&http.Client{}, response.X5U)
body, err := getMirroredX5U(response.X5U)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit ab9c54f

Please sign in to comment.