mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 08:36:37 +08:00
fec9bd18dd
* fix(oauth): support Casdoor string user IDs * test(oauth): verify legacy IDs and auth source isolation --------- Co-authored-by: Noru Wyrms <wyrmsnoru@gmail.com>
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// TestOAuthUserInfoIgnoresProviderID verifies nonstandard IDs cannot affect OIDC identity parsing.
|
|
func TestOAuthUserInfoIgnoresProviderID(t *testing.T) {
|
|
for _, providerID := range []string{`"a27dfc56-07ae-4c9d-9e5c-99103bd8805f"`, `"88888"`, `88888`, `null`} {
|
|
t.Run(providerID, func(t *testing.T) {
|
|
payload := `{"id":` + providerID + `,"sub":"external-subject","preferred_username":"oidc-user","email":"oidc@example.com","name":"OIDC User"}`
|
|
var info OAuthUserInfo
|
|
if err := json.Unmarshal([]byte(payload), &info); err != nil {
|
|
t.Fatalf("json.Unmarshal(OAuthUserInfo, id=%s) error = %v, want nil", providerID, err)
|
|
}
|
|
want := OAuthUserInfo{
|
|
Sub: "external-subject",
|
|
PreferredUsername: "oidc-user",
|
|
Email: "oidc@example.com",
|
|
Name: "OIDC User",
|
|
}
|
|
if info != want {
|
|
t.Errorf("json.Unmarshal(OAuthUserInfo, id=%s) = %+v, want %+v", providerID, info, want)
|
|
}
|
|
})
|
|
}
|
|
}
|