busweb: web UIs over the YAPL bus; httpsec.BearerTokens
busweb.Serve runs a <name>.web@N request (verse/web, D-200) against a UI's http.Handler; Prefix/User/FromBus tell the handler where it is mounted and who yasta says is logged in; WithPrefix serves the same handler on a TCP port. httpsec.BearerTokens is the access control of a UI without user management (a reverse proxy or yasta sends the token). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb2cb7bcfa
commit
7afb6a022a
7 files changed
+365
No files matched your search
@@ -132,3 +132,29 @@ func TestSecureCookies(t *testing.T) {
|
||||
t.Fatal("TLS")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBearerTokens(t *testing.T) {
|
||||
ok := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(204) })
|
||||
h := BearerTokens(ok, []string{" one ", "", "two"})
|
||||
for auth, want := range map[string]int{
|
||||
"": 401, "Bearer one": 204, "bearer two": 204, "Bearer three": 401, "Basic one": 401, "Bearer": 401, "Bearer onex": 401,
|
||||
} {
|
||||
r := httptest.NewRequest("GET", "/", nil)
|
||||
if auth != "" {
|
||||
r.Header.Set("Authorization", auth)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, r)
|
||||
if w.Code != want {
|
||||
t.Errorf("%q: %d, want %d", auth, w.Code, want)
|
||||
}
|
||||
if want == 401 && w.Header().Get("WWW-Authenticate") == "" {
|
||||
t.Errorf("%q: no WWW-Authenticate", auth)
|
||||
}
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
BearerTokens(ok, []string{" ", ""}).ServeHTTP(w, httptest.NewRequest("GET", "/", nil))
|
||||
if w.Code != 204 {
|
||||
t.Errorf("no tokens: %d", w.Code)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user