Skip to content

Commit

Permalink
Merge branch 'main' into aro-6284
Browse files Browse the repository at this point in the history
  • Loading branch information
katherinelc321 authored Apr 17, 2024
2 parents 1e90e12 + 7500875 commit eec8d83
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
10 changes: 5 additions & 5 deletions frontend/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const (
ContextKeyCorrelationData
ContextKeySystemData

// Wildcard path segment names for request multiplexing
// Wildcard path segment names for request multiplexing, must be lowercase as we lowercase the request URL pattern when registering handlers
PageSegmentLocation = "location"
PathSegmentSubscriptionID = "subscriptionId"
PathSegmentResourceGroupName = "resourceGroupName"
PathSegmentResourceName = "resourceName"
PathSegmentActionName = "actionName"
PathSegmentSubscriptionID = "subscriptionid"
PathSegmentResourceGroupName = "resourcegroupname"
PathSegmentResourceName = "resourcename"
PathSegmentActionName = "actionname"
)
2 changes: 1 addition & 1 deletion frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (f *Frontend) ArmSubscriptionAction(writer http.ResponseWriter, request *ht
return
}

subId := request.PathValue(strings.ToLower(PathSegmentSubscriptionID))
subId := request.PathValue(PathSegmentSubscriptionID)
f.cache.SetSubscription(subId, &subscription)

resp, err := json.Marshal(subscription)
Expand Down
2 changes: 1 addition & 1 deletion frontend/middleware_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func MiddlewareBody(w http.ResponseWriter, r *http.Request, next http.HandlerFun

contentType := strings.SplitN(r.Header.Get("Content-Type"), ";", 2)[0]

if contentType != "application/json" && !(len(body) == 0 && contentType == "") {
if !strings.EqualFold(contentType, "application/json") && !(len(body) == 0 && contentType == "") {
arm.WriteError(
w, http.StatusUnsupportedMediaType,
arm.CloudErrorCodeUnsupportedMediaType, "",
Expand Down
8 changes: 8 additions & 0 deletions frontend/middleware_body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func TestMiddlewareBody(t *testing.T) {
},
body: []byte("body"),
},
{
name: "upper-case valid media type allowed with non-empty body",
methods: []string{http.MethodPatch, http.MethodPost, http.MethodPut},
header: http.Header{
"Content-Type": []string{"APPLICATION/JSON"},
},
body: []byte("body"),
},
}

for _, tt := range tests {
Expand Down
6 changes: 6 additions & 0 deletions frontend/middleware_panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ package main
// Licensed under the Apache License 2.0.

import (
"fmt"
"log/slog"
"net/http"
"runtime/debug"

"github.com/Azure/ARO-HCP/internal/api/arm"
)

func MiddlewarePanic(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
defer func() {
if e := recover(); e != nil {
if logger, ok := r.Context().Value(ContextKeyLogger).(*slog.Logger); ok {
logger.Error(fmt.Sprintf("panic: %#v\n%s\n", e, string(debug.Stack())))
}
arm.WriteInternalServerError(w)
}
}()
Expand Down
4 changes: 0 additions & 4 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
Expand Down Expand Up @@ -39,7 +37,5 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=

0 comments on commit eec8d83

Please sign in to comment.