komuw / ong

ong, is a Go http toolkit.
MIT License
16 stars 4 forks source link

mux should raise conflict #450

Closed komuw closed 3 weeks ago

komuw commented 3 weeks ago
mux.NewRoute(
    "/okay",
    mux.MethodAll,
    middleware.BasicAuth(helloHandler, "admin", "sec", ""),
),
mux.NewRoute(
    "/okay",
    mux.MethodGet,
    middleware.BasicAuth(stats, "admin",  "sec", ""),
),

even though they have different methods all vs get, this should raise a conflict since get is a subset of all

komuw commented 3 weeks ago

repro;

package mux

import (
    "net/http"
    "testing"

    "github.com/komuw/ong/config"
)

func TestNew(t *testing.T) {
    routes := func() []Route {
        return []Route{
            NewRoute("/home", MethodGet, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})),
            NewRoute("/home/", MethodAll, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})),
        }
    }

    t.Run("conflict detected", func(t *testing.T) {
        rtz := []Route{}
        rtz = append(rtz, tarpitRoutes()...)
        rtz = append(rtz, routes()...)

        // attest.Panics(t, func() {
        _ = New(config.DevOpts(nil, "secretKey12@34String"), nil, rtz...)
        // })
    })
}

func tarpitRoutes() []Route {
    return []Route{
        NewRoute(
            "/libraries/joomla/",
            MethodAll,
            http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
        ),
    }
}