mirror of
https://github.com/hanzoai/base.git
synced 2026-10-21 03:41:50 +00:00
# Conflicts: # core/record_field_resolver_multi_match.go # ui/dist/assets/AuthMethodsDocs-ChShXLwE.js # ui/dist/assets/AuthMethodsDocs-Cqvl0T_l.js # ui/dist/assets/AuthMethodsDocs-DIqhS7qY.js # ui/dist/assets/AuthRefreshDocs-CHakkNnn.js # ui/dist/assets/AuthRefreshDocs-DLb1qree.js # ui/dist/assets/AuthRefreshDocs-DXgrlMdk.js # ui/dist/assets/AuthWithOAuth2Docs-Bl8VRxNv.js # ui/dist/assets/AuthWithOAuth2Docs-DVBOel22.js # ui/dist/assets/AuthWithOAuth2Docs-I213UiJ7.js # ui/dist/assets/AuthWithOtpDocs-B9tL6gIN.js # ui/dist/assets/AuthWithOtpDocs-C2PPm9-Z.js # ui/dist/assets/AuthWithOtpDocs-qEMoMG3D.js # ui/dist/assets/AuthWithPasswordDocs-B8JWDbPL.js # ui/dist/assets/AuthWithPasswordDocs-BTHeYJwE.js # ui/dist/assets/AuthWithPasswordDocs-D9rqgLpO.js # ui/dist/assets/BatchApiDocs-BV4PYYXn.js # ui/dist/assets/BatchApiDocs-DXa997am.js # ui/dist/assets/BatchApiDocs-Di2Qe2dV.js # ui/dist/assets/DeleteApiDocs-C3IINRwz.js # ui/dist/assets/DeleteApiDocs-LfmVp4Uf.js # ui/dist/assets/DeleteApiDocs-SU4XdGhJ.js # ui/dist/assets/EmailChangeDocs-COx1USU5.js # ui/dist/assets/EmailChangeDocs-D-qNHT_P.js # ui/dist/assets/EmailChangeDocs-DpfXIE_V.js # ui/dist/assets/FieldsQueryParam-BYe9ZK-G.js # ui/dist/assets/FieldsQueryParam-L8vpHeF4.js # ui/dist/assets/FieldsQueryParam-z0dGQ6uY.js # ui/dist/assets/ListApiDocs-BCTT-AOz.js # ui/dist/assets/ListApiDocs-C0_GwI7k.js # ui/dist/assets/ListApiDocs-T9_aO-pW.js # ui/dist/assets/PageInstaller-B22bivaN.js # ui/dist/assets/PageInstaller-C0BBhyBx.js # ui/dist/assets/PageInstaller-IYSwJhZW.js # ui/dist/assets/PageOAuth2RedirectFailure-BjbpqlFj.js # ui/dist/assets/PageOAuth2RedirectFailure-COyNF79R.js # ui/dist/assets/PageOAuth2RedirectFailure-DPmGG9zv.js # ui/dist/assets/PageOAuth2RedirectSuccess-6cMXLFAX.js # ui/dist/assets/PageOAuth2RedirectSuccess-CdkCarGH.js # ui/dist/assets/PageOAuth2RedirectSuccess-DSEIHeQL.js # ui/dist/assets/PageRecordConfirmEmailChange-BYW-6ASg.js # ui/dist/assets/PageRecordConfirmEmailChange-Bm1CIYvq.js # ui/dist/assets/PageRecordConfirmEmailChange-BpaqOT4u.js # ui/dist/assets/PageRecordConfirmPasswordReset--wx_u2lI.js # ui/dist/assets/PageRecordConfirmPasswordReset-CoeY2Z_C.js # ui/dist/assets/PageRecordConfirmPasswordReset-Ptya5bfe.js # ui/dist/assets/PageRecordConfirmVerification-6xjF3T0O.js # ui/dist/assets/PageRecordConfirmVerification-C1UTIIJh.js # ui/dist/assets/PageRecordConfirmVerification-C4LixXvA.js # ui/dist/assets/PageSuperuserConfirmPasswordReset-19z2IFg4.js # ui/dist/assets/PageSuperuserConfirmPasswordReset-DwNi0ugQ.js # ui/dist/assets/PageSuperuserConfirmPasswordReset-SMnDTRNi.js # ui/dist/assets/PageSuperuserRequestPasswordReset-BpDW217f.js # ui/dist/assets/PageSuperuserRequestPasswordReset-DK63qE6z.js # ui/dist/assets/PageSuperuserRequestPasswordReset-bG02qLIM.js # ui/dist/assets/PasswordResetDocs-CE67mLC0.js # ui/dist/assets/PasswordResetDocs-CHAK0vma.js # ui/dist/assets/PasswordResetDocs-Dap-N4rx.js # ui/dist/assets/RealtimeApiDocs-BooTSQCb.js # ui/dist/assets/RealtimeApiDocs-CoHmYVEx.js # ui/dist/assets/RealtimeApiDocs-D7ds3fHt.js # ui/dist/assets/VerificationDocs-B42AIoCQ.js # ui/dist/assets/VerificationDocs-BS7b11zH.js # ui/dist/assets/VerificationDocs-ZhkdFVIl.js # ui/dist/assets/ViewApiDocs-BXmRLHZ1.js # ui/dist/assets/ViewApiDocs-DM5JJQjh.js # ui/dist/assets/ViewApiDocs-DRpxcuJR.js # ui/public/fonts/source-sans-pro/source-sans-pro-v18-latin_cyrillic-700.woff2 # ui/public/fonts/ubuntu-mono/ubuntu-mono-v17-cyrillic_latin-700.woff2
318 lines
7.5 KiB
Go
318 lines
7.5 KiB
Go
package auth_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/base/tools/auth"
|
|
)
|
|
|
|
func TestProvidersCount(t *testing.T) {
|
|
expected := 32
|
|
|
|
if total := len(auth.Providers); total != expected {
|
|
t.Fatalf("Expected %d providers, got %d", expected, total)
|
|
}
|
|
}
|
|
|
|
func TestNewProviderByName(t *testing.T) {
|
|
var err error
|
|
var p auth.Provider
|
|
|
|
// invalid
|
|
p, err = auth.NewProviderByName("invalid")
|
|
if err == nil {
|
|
t.Error("Expected error, got nil")
|
|
}
|
|
if p != nil {
|
|
t.Errorf("Expected provider to be nil, got %v", p)
|
|
}
|
|
|
|
// google
|
|
p, err = auth.NewProviderByName(auth.NameGoogle)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Google); !ok {
|
|
t.Error("Expected to be instance of *auth.Google")
|
|
}
|
|
|
|
// facebook
|
|
p, err = auth.NewProviderByName(auth.NameFacebook)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Facebook); !ok {
|
|
t.Error("Expected to be instance of *auth.Facebook")
|
|
}
|
|
|
|
// github
|
|
p, err = auth.NewProviderByName(auth.NameGithub)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Github); !ok {
|
|
t.Error("Expected to be instance of *auth.Github")
|
|
}
|
|
|
|
// gitlab
|
|
p, err = auth.NewProviderByName(auth.NameGitlab)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Gitlab); !ok {
|
|
t.Error("Expected to be instance of *auth.Gitlab")
|
|
}
|
|
|
|
// twitter
|
|
p, err = auth.NewProviderByName(auth.NameTwitter)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Twitter); !ok {
|
|
t.Error("Expected to be instance of *auth.Twitter")
|
|
}
|
|
|
|
// discord
|
|
p, err = auth.NewProviderByName(auth.NameDiscord)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Discord); !ok {
|
|
t.Error("Expected to be instance of *auth.Discord")
|
|
}
|
|
|
|
// microsoft
|
|
p, err = auth.NewProviderByName(auth.NameMicrosoft)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Microsoft); !ok {
|
|
t.Error("Expected to be instance of *auth.Microsoft")
|
|
}
|
|
|
|
// spotify
|
|
p, err = auth.NewProviderByName(auth.NameSpotify)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Spotify); !ok {
|
|
t.Error("Expected to be instance of *auth.Spotify")
|
|
}
|
|
|
|
// kakao
|
|
p, err = auth.NewProviderByName(auth.NameKakao)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Kakao); !ok {
|
|
t.Error("Expected to be instance of *auth.Kakao")
|
|
}
|
|
|
|
// twitch
|
|
p, err = auth.NewProviderByName(auth.NameTwitch)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Twitch); !ok {
|
|
t.Error("Expected to be instance of *auth.Twitch")
|
|
}
|
|
|
|
// strava
|
|
p, err = auth.NewProviderByName(auth.NameStrava)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Strava); !ok {
|
|
t.Error("Expected to be instance of *auth.Strava")
|
|
}
|
|
|
|
// gitee
|
|
p, err = auth.NewProviderByName(auth.NameGitee)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Gitee); !ok {
|
|
t.Error("Expected to be instance of *auth.Gitee")
|
|
}
|
|
|
|
// livechat
|
|
p, err = auth.NewProviderByName(auth.NameLivechat)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Livechat); !ok {
|
|
t.Error("Expected to be instance of *auth.Livechat")
|
|
}
|
|
|
|
// gitea
|
|
p, err = auth.NewProviderByName(auth.NameGitea)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Gitea); !ok {
|
|
t.Error("Expected to be instance of *auth.Gitea")
|
|
}
|
|
|
|
// oidc
|
|
p, err = auth.NewProviderByName(auth.NameOIDC)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.OIDC); !ok {
|
|
t.Error("Expected to be instance of *auth.OIDC")
|
|
}
|
|
|
|
// oidc2
|
|
p, err = auth.NewProviderByName(auth.NameOIDC + "2")
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.OIDC); !ok {
|
|
t.Error("Expected to be instance of *auth.OIDC")
|
|
}
|
|
|
|
// oidc3
|
|
p, err = auth.NewProviderByName(auth.NameOIDC + "3")
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.OIDC); !ok {
|
|
t.Error("Expected to be instance of *auth.OIDC")
|
|
}
|
|
|
|
// apple
|
|
p, err = auth.NewProviderByName(auth.NameApple)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Apple); !ok {
|
|
t.Error("Expected to be instance of *auth.Apple")
|
|
}
|
|
|
|
// instagram
|
|
p, err = auth.NewProviderByName(auth.NameInstagram)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Instagram); !ok {
|
|
t.Error("Expected to be instance of *auth.Instagram")
|
|
}
|
|
|
|
// vk
|
|
p, err = auth.NewProviderByName(auth.NameVK)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.VK); !ok {
|
|
t.Error("Expected to be instance of *auth.VK")
|
|
}
|
|
|
|
// yandex
|
|
p, err = auth.NewProviderByName(auth.NameYandex)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Yandex); !ok {
|
|
t.Error("Expected to be instance of *auth.Yandex")
|
|
}
|
|
|
|
// patreon
|
|
p, err = auth.NewProviderByName(auth.NamePatreon)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Patreon); !ok {
|
|
t.Error("Expected to be instance of *auth.Patreon")
|
|
}
|
|
|
|
// mailcow
|
|
p, err = auth.NewProviderByName(auth.NameMailcow)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Mailcow); !ok {
|
|
t.Error("Expected to be instance of *auth.Mailcow")
|
|
}
|
|
|
|
// bitbucket
|
|
p, err = auth.NewProviderByName(auth.NameBitbucket)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Bitbucket); !ok {
|
|
t.Error("Expected to be instance of *auth.Bitbucket")
|
|
}
|
|
|
|
// planningcenter
|
|
p, err = auth.NewProviderByName(auth.NamePlanningcenter)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Planningcenter); !ok {
|
|
t.Error("Expected to be instance of *auth.Planningcenter")
|
|
}
|
|
|
|
// notion
|
|
p, err = auth.NewProviderByName(auth.NameNotion)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Notion); !ok {
|
|
t.Error("Expected to be instance of *auth.Notion")
|
|
}
|
|
|
|
// monday
|
|
p, err = auth.NewProviderByName(auth.NameMonday)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Monday); !ok {
|
|
t.Error("Expected to be instance of *auth.Monday")
|
|
}
|
|
|
|
// wakatime
|
|
p, err = auth.NewProviderByName(auth.NameWakatime)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Wakatime); !ok {
|
|
t.Error("Expected to be instance of *auth.Wakatime")
|
|
}
|
|
|
|
// box
|
|
p, err = auth.NewProviderByName(auth.NameBox)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Box); !ok {
|
|
t.Error("Expected to be instance of *auth.Box")
|
|
}
|
|
|
|
// linear
|
|
p, err = auth.NewProviderByName(auth.NameLinear)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Linear); !ok {
|
|
t.Error("Expected to be instance of *auth.Linear")
|
|
}
|
|
|
|
// trakt
|
|
p, err = auth.NewProviderByName(auth.NameTrakt)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Trakt); !ok {
|
|
t.Error("Expected to be instance of *auth.Trakt")
|
|
}
|
|
|
|
// lark
|
|
p, err = auth.NewProviderByName(auth.NameLark)
|
|
if err != nil {
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
}
|
|
if _, ok := p.(*auth.Lark); !ok {
|
|
t.Error("Expected to be instance of *auth.Lark")
|
|
}
|
|
}
|