Skip to content

Commit c4045a1

Browse files
committed
fix: remove dead token=="" branch and add probeRR HTTP-layer test
adminBearerMiddleware had an unreachable branch (token == "") since admin routes are only registered when a token is configured. Remove it to eliminate dead code. Add TestAdminCreateRecordInvalidMXValue to exercise the probeRR rejection path at the HTTP layer (malformed MX value → 400).
1 parent 4c1ce04 commit c4045a1

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

api.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ type adminRecordRequest struct {
146146
func adminBearerMiddleware(next httprouter.Handle) httprouter.Handle {
147147
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
148148
token := Config.API.Admin.Token
149-
if token == "" {
150-
w.Header().Set("Content-Type", "application/json")
151-
w.WriteHeader(http.StatusUnauthorized)
152-
_, _ = w.Write(jsonError("unauthorized"))
153-
return
154-
}
155149
auth := r.Header.Get("Authorization")
156150
provided := strings.TrimPrefix(auth, "Bearer ")
157151
if subtle.ConstantTimeCompare([]byte(token), []byte(provided)) != 1 {

api_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,20 @@ func TestAdminCreateRecordInvalidValue(t *testing.T) {
616616
Expect().Status(http.StatusBadRequest)
617617
}
618618

619+
func TestAdminCreateRecordInvalidMXValue(t *testing.T) {
620+
_, e := setupAdminRouter(t, "test-token")
621+
payload := map[string]interface{}{
622+
"name": "test.example.com",
623+
"type": "MX",
624+
"value": "not-a-valid-mx",
625+
"ttl": 60,
626+
}
627+
e.POST("/admin/records").
628+
WithHeader("Authorization", "Bearer test-token").
629+
WithJSON(payload).
630+
Expect().Status(http.StatusBadRequest)
631+
}
632+
619633
func TestAdminListRecordsFilter(t *testing.T) {
620634
_, e := setupAdminRouter(t, "test-token")
621635
// Create an A record and a CNAME record

0 commit comments

Comments
 (0)