mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-11 02:46:47 +08:00
- Introduced `FrontendAuthProviderExclusive` capability to restrict authentication to a single selected provider. - Added `SetExclusiveProvider` and `ClearExclusiveProvider` methods for managing exclusive providers in the access registry. - Updated `pluginhost` to prioritize and enforce exclusive providers based on plugin priority and ID. - Enhanced RPC capabilities schema to include `FrontendAuthProviderExclusive` field. - Added example plugin and tests for exclusive frontend auth behavior.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package pluginhost
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v7/sdk/pluginapi"
|
|
)
|
|
|
|
func TestRPCCapabilitiesIncludeFrontendAuthProviderExclusive(t *testing.T) {
|
|
plugin := pluginapi.Plugin{
|
|
Capabilities: pluginapi.Capabilities{
|
|
FrontendAuthProvider: frontendAuthProviderFunc{identifier: "exclusive-auth"},
|
|
FrontendAuthProviderExclusive: true,
|
|
},
|
|
}
|
|
|
|
caps := rpcCapabilitiesFromPlugin(plugin)
|
|
if !caps.FrontendAuthProvider {
|
|
t.Fatal("FrontendAuthProvider = false, want true")
|
|
}
|
|
if !caps.FrontendAuthProviderExclusive {
|
|
t.Fatal("FrontendAuthProviderExclusive = false, want true")
|
|
}
|
|
|
|
raw, errMarshal := json.Marshal(caps)
|
|
if errMarshal != nil {
|
|
t.Fatalf("Marshal() error = %v", errMarshal)
|
|
}
|
|
if !json.Valid(raw) {
|
|
t.Fatalf("marshaled capabilities are invalid JSON: %s", raw)
|
|
}
|
|
var decoded map[string]any
|
|
if errUnmarshal := json.Unmarshal(raw, &decoded); errUnmarshal != nil {
|
|
t.Fatalf("Unmarshal() error = %v", errUnmarshal)
|
|
}
|
|
if decoded["frontend_auth_provider_exclusive"] != true {
|
|
t.Fatalf("frontend_auth_provider_exclusive = %#v, want true", decoded["frontend_auth_provider_exclusive"])
|
|
}
|
|
}
|