Two wasm-era regressions fixed: Routes: the wasm host forwards the FULL request path with no prefix strip, but every route was registered relative — the plugin's entire HTTP surface (slots/book/cancel/date-grid/admin) 404'd at runtime on every instance since 2.0.0. All routes now register under /api/plugins/calcomblock (testplugin's httpBase convention), pinned by a route-matching test. Captcha requirement: blockConfig was hardcoded nil (no capability exposed published block content), so bookingRequiresCaptcha always reported false — the widget never rendered and the gate never ran. publishedBlockResolver now answers it via pluginsdk v0.2.4's content.published_block_configs: any currently-published calcom:booking block matching the posted username+eventTypeSlug with captchaEnabled=true demands the host-stamped X-Bn-Verified-Captcha header; an empty config username applies to any posted username. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package main
|
||
|
||
import (
|
||
"net/http"
|
||
"testing"
|
||
|
||
"git.dev.alexdunmow.com/block/pluginsdk/plugin"
|
||
"github.com/go-chi/chi/v5"
|
||
)
|
||
|
||
// TestRouterMatchesAbsolutePluginPaths pins the wasm routing contract: the
|
||
// host forwards the FULL request path (/api/plugins/calcomblock/...) to the
|
||
// guest with no prefix strip, so every route must be registered absolute.
|
||
// Relative registrations 404 the plugin's entire HTTP surface at runtime —
|
||
// exactly the regression that shipped in 2.0.0–2.0.2.
|
||
func TestRouterMatchesAbsolutePluginPaths(t *testing.T) {
|
||
router, ok := NewCalcomRouter(plugin.CoreServices{}).(chi.Routes)
|
||
if !ok {
|
||
t.Fatal("NewCalcomRouter no longer returns a chi router")
|
||
}
|
||
|
||
for _, tc := range []struct{ method, path string }{
|
||
{http.MethodGet, "/api/plugins/calcomblock/reset"},
|
||
{http.MethodGet, "/api/plugins/calcomblock/slots"},
|
||
{http.MethodGet, "/api/plugins/calcomblock/date-grid"},
|
||
{http.MethodPost, "/api/plugins/calcomblock/book"},
|
||
{http.MethodPost, "/api/plugins/calcomblock/cancel"},
|
||
{http.MethodGet, "/api/plugins/calcomblock/event-types"},
|
||
} {
|
||
rctx := chi.NewRouteContext()
|
||
if !router.Match(rctx, tc.method, tc.path) {
|
||
t.Errorf("%s %s does not match any route — must be registered at the absolute plugin path", tc.method, tc.path)
|
||
}
|
||
}
|
||
}
|