2022-07-06 23:19:05 +02:00
|
|
|
package auth_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pocketbase/pocketbase/tools/auth"
|
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2022-08-21 18:38:42 +02:00
|
|
|
|
2022-11-13 13:05:06 +02:00
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
2022-08-21 18:38:42 +02:00
|
|
|
// 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")
|
|
|
|
}
|
2022-10-31 21:17:10 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-11-01 17:06:06 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-11-13 13:05:06 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-11-13 14:20:11 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-12-31 02:21:41 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-12-31 11:46:36 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-01-12 22:12:34 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-01-16 11:47:08 +02:00
|
|
|
|
2023-02-23 21:07:00 +02:00
|
|
|
// gitea
|
|
|
|
p, err = auth.NewProviderByName(auth.NameGitea)
|
2023-01-16 11:47:08 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
|
|
}
|
2023-02-23 21:07:00 +02:00
|
|
|
if _, ok := p.(*auth.Gitea); !ok {
|
|
|
|
t.Error("Expected to be instance of *auth.Gitea")
|
2023-01-16 11:47:08 +02:00
|
|
|
}
|
2023-01-20 10:17:57 +02:00
|
|
|
|
2023-02-23 21:07:00 +02:00
|
|
|
// oidc
|
|
|
|
p, err = auth.NewProviderByName(auth.NameOIDC)
|
2023-01-20 10:17:57 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
|
|
}
|
2023-02-23 21:07:00 +02:00
|
|
|
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")
|
2023-01-20 10:17:57 +02:00
|
|
|
}
|
2023-03-01 23:29:45 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-05-23 21:37:44 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-05-24 14:34:25 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-06-23 13:13:43 +02:00
|
|
|
|
|
|
|
// yandex
|
|
|
|
p, err = auth.NewProviderByName(auth.NameYandex)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected nil, got error %v", err)
|
|
|
|
}
|
|
|
|
if _, ok := p.(*auth.Yandex); !ok {
|
2023-10-14 13:46:01 +02:00
|
|
|
t.Error("Expected to be instance of *auth.Yandex")
|
2023-06-23 13:13:43 +02:00
|
|
|
}
|
2023-09-16 07:20:49 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-10-14 13:46:01 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2023-12-17 15:31:34 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2024-02-24 08:46:22 +02:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|