mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-03-27 22:27:28 +00:00
23 lines
643 B
Go
23 lines
643 B
Go
package codebuddy_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/codebuddy"
|
|
)
|
|
|
|
func TestDecodeUserID_ValidJWT(t *testing.T) {
|
|
// JWT payload: {"sub":"test-user-id-123","iat":1234567890}
|
|
// base64url encode: eyJzdWIiOiJ0ZXN0LXVzZXItaWQtMTIzIiwiaWF0IjoxMjM0NTY3ODkwfQ
|
|
token := "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXItaWQtMTIzIiwiaWF0IjoxMjM0NTY3ODkwfQ.sig"
|
|
auth := codebuddy.NewCodeBuddyAuth(nil)
|
|
userID, err := auth.DecodeUserID(token)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if userID != "test-user-id-123" {
|
|
t.Errorf("expected 'test-user-id-123', got '%s'", userID)
|
|
}
|
|
}
|
|
|