fix: decode bearer tokens for IM HTTP

This commit is contained in:
richjohnrambo
2026-08-17 15:08:32 +08:00
parent b7a5d5cb17
commit d10c05b030
2 changed files with 22 additions and 1 deletions
+17
View File
@@ -940,6 +940,23 @@ func expectIMBearer(t *testing.T, ctrl *gomock.Controller, token string, tenantI
return mockStore
}
func TestResolveIMHTTPBearerAcceptsBase64Token(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
expectIMBearer(t, ctrl, "token-1", 7, 42)
req := httptest.NewRequest(http.MethodGet, "/v1/im/bootstrap", nil)
req.Header.Set("Authorization", "Bearer "+base64.StdEncoding.EncodeToString([]byte("token-1")))
principal, err := resolveIMHTTPBearer(req)
if err != nil {
t.Fatalf("resolve bearer: %v", err)
}
if principal.TenantID != 7 || principal.Uid != 42 {
t.Fatalf("principal mismatch: %#v", principal)
}
}
func TestIMHTTPProtocolHeaders(t *testing.T) {
apiKey := makeTestAPIKey(t)
called := 0