| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | package settings_test | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	"bytes" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	"strings" | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 	validation "github.com/go-ozzo/ozzo-validation/v4" | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	"github.com/pocketbase/pocketbase/models/settings" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	"github.com/pocketbase/pocketbase/tools/auth" | 
					
						
							| 
									
										
										
										
											2022-12-13 17:45:59 +08:00
										 |  |  | 	"github.com/pocketbase/pocketbase/tools/mailer" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSettingsValidate(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	s := settings.New() | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// set invalid settings data
 | 
					
						
							|  |  |  | 	s.Meta.AppName = "" | 
					
						
							|  |  |  | 	s.Logs.MaxDays = -10 | 
					
						
							|  |  |  | 	s.Smtp.Enabled = true | 
					
						
							|  |  |  | 	s.Smtp.Host = "" | 
					
						
							|  |  |  | 	s.S3.Enabled = true | 
					
						
							|  |  |  | 	s.S3.Endpoint = "invalid" | 
					
						
							|  |  |  | 	s.AdminAuthToken.Duration = -10 | 
					
						
							|  |  |  | 	s.AdminPasswordResetToken.Duration = -10 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:47:03 +08:00
										 |  |  | 	s.AdminFileToken.Duration = -10 | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 	s.RecordAuthToken.Duration = -10 | 
					
						
							|  |  |  | 	s.RecordPasswordResetToken.Duration = -10 | 
					
						
							|  |  |  | 	s.RecordEmailChangeToken.Duration = -10 | 
					
						
							|  |  |  | 	s.RecordVerificationToken.Duration = -10 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 	s.RecordFileToken.Duration = -10 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	s.GoogleAuth.Enabled = true | 
					
						
							|  |  |  | 	s.GoogleAuth.ClientId = "" | 
					
						
							|  |  |  | 	s.FacebookAuth.Enabled = true | 
					
						
							|  |  |  | 	s.FacebookAuth.ClientId = "" | 
					
						
							|  |  |  | 	s.GithubAuth.Enabled = true | 
					
						
							|  |  |  | 	s.GithubAuth.ClientId = "" | 
					
						
							|  |  |  | 	s.GitlabAuth.Enabled = true | 
					
						
							|  |  |  | 	s.GitlabAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-08-22 00:38:42 +08:00
										 |  |  | 	s.DiscordAuth.Enabled = true | 
					
						
							|  |  |  | 	s.DiscordAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-09-01 21:46:06 +08:00
										 |  |  | 	s.TwitterAuth.Enabled = true | 
					
						
							|  |  |  | 	s.TwitterAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-11-01 03:17:10 +08:00
										 |  |  | 	s.MicrosoftAuth.Enabled = true | 
					
						
							|  |  |  | 	s.MicrosoftAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-11-01 23:06:06 +08:00
										 |  |  | 	s.SpotifyAuth.Enabled = true | 
					
						
							|  |  |  | 	s.SpotifyAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-11-13 19:05:06 +08:00
										 |  |  | 	s.KakaoAuth.Enabled = true | 
					
						
							|  |  |  | 	s.KakaoAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-11-13 20:20:11 +08:00
										 |  |  | 	s.TwitchAuth.Enabled = true | 
					
						
							|  |  |  | 	s.TwitchAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-12-31 08:21:41 +08:00
										 |  |  | 	s.StravaAuth.Enabled = true | 
					
						
							|  |  |  | 	s.StravaAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-12-31 17:46:36 +08:00
										 |  |  | 	s.GiteeAuth.Enabled = true | 
					
						
							|  |  |  | 	s.GiteeAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2023-01-13 04:12:34 +08:00
										 |  |  | 	s.LivechatAuth.Enabled = true | 
					
						
							|  |  |  | 	s.LivechatAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2023-01-20 16:17:57 +08:00
										 |  |  | 	s.GiteaAuth.Enabled = true | 
					
						
							|  |  |  | 	s.GiteaAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s.OIDCAuth.Enabled = true | 
					
						
							|  |  |  | 	s.OIDCAuth.ClientId = "" | 
					
						
							|  |  |  | 	s.OIDC2Auth.Enabled = true | 
					
						
							|  |  |  | 	s.OIDC2Auth.ClientId = "" | 
					
						
							|  |  |  | 	s.OIDC3Auth.Enabled = true | 
					
						
							|  |  |  | 	s.OIDC3Auth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2023-03-02 05:29:45 +08:00
										 |  |  | 	s.AppleAuth.Enabled = true | 
					
						
							|  |  |  | 	s.AppleAuth.ClientId = "" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// check if Validate() is triggering the members validate methods.
 | 
					
						
							|  |  |  | 	err := s.Validate() | 
					
						
							|  |  |  | 	if err == nil { | 
					
						
							|  |  |  | 		t.Fatalf("Expected error, got nil") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expectations := []string{ | 
					
						
							|  |  |  | 		`"meta":{`, | 
					
						
							|  |  |  | 		`"logs":{`, | 
					
						
							|  |  |  | 		`"smtp":{`, | 
					
						
							|  |  |  | 		`"s3":{`, | 
					
						
							|  |  |  | 		`"adminAuthToken":{`, | 
					
						
							|  |  |  | 		`"adminPasswordResetToken":{`, | 
					
						
							| 
									
										
										
										
											2023-04-05 01:47:03 +08:00
										 |  |  | 		`"adminFileToken":{`, | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 		`"recordAuthToken":{`, | 
					
						
							|  |  |  | 		`"recordPasswordResetToken":{`, | 
					
						
							|  |  |  | 		`"recordEmailChangeToken":{`, | 
					
						
							|  |  |  | 		`"recordVerificationToken":{`, | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 		`"recordFileToken":{`, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		`"googleAuth":{`, | 
					
						
							|  |  |  | 		`"facebookAuth":{`, | 
					
						
							|  |  |  | 		`"githubAuth":{`, | 
					
						
							|  |  |  | 		`"gitlabAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-08-22 00:38:42 +08:00
										 |  |  | 		`"discordAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 		`"twitterAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-11-01 03:17:10 +08:00
										 |  |  | 		`"microsoftAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-11-01 23:06:06 +08:00
										 |  |  | 		`"spotifyAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-11-13 19:05:06 +08:00
										 |  |  | 		`"kakaoAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-11-13 20:20:11 +08:00
										 |  |  | 		`"twitchAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-12-31 08:21:41 +08:00
										 |  |  | 		`"stravaAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-12-31 17:46:36 +08:00
										 |  |  | 		`"giteeAuth":{`, | 
					
						
							| 
									
										
										
										
											2023-01-13 04:12:34 +08:00
										 |  |  | 		`"livechatAuth":{`, | 
					
						
							| 
									
										
										
										
											2023-01-20 16:17:57 +08:00
										 |  |  | 		`"giteaAuth":{`, | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 		`"oidcAuth":{`, | 
					
						
							|  |  |  | 		`"oidc2Auth":{`, | 
					
						
							|  |  |  | 		`"oidc3Auth":{`, | 
					
						
							| 
									
										
										
										
											2023-03-02 05:29:45 +08:00
										 |  |  | 		`"appleAuth":{`, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	errBytes, _ := json.Marshal(err) | 
					
						
							|  |  |  | 	jsonErr := string(errBytes) | 
					
						
							|  |  |  | 	for _, expected := range expectations { | 
					
						
							|  |  |  | 		if !strings.Contains(jsonErr, expected) { | 
					
						
							|  |  |  | 			t.Errorf("Expected error key %s in %v", expected, jsonErr) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSettingsMerge(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	s1 := settings.New() | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	s1.Meta.AppUrl = "old_app_url" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	s2 := settings.New() | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	s2.Meta.AppName = "test" | 
					
						
							|  |  |  | 	s2.Logs.MaxDays = 123 | 
					
						
							|  |  |  | 	s2.Smtp.Host = "test" | 
					
						
							|  |  |  | 	s2.Smtp.Enabled = true | 
					
						
							|  |  |  | 	s2.S3.Enabled = true | 
					
						
							|  |  |  | 	s2.S3.Endpoint = "test" | 
					
						
							|  |  |  | 	s2.AdminAuthToken.Duration = 1 | 
					
						
							|  |  |  | 	s2.AdminPasswordResetToken.Duration = 2 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:47:03 +08:00
										 |  |  | 	s2.AdminFileToken.Duration = 2 | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 	s2.RecordAuthToken.Duration = 3 | 
					
						
							|  |  |  | 	s2.RecordPasswordResetToken.Duration = 4 | 
					
						
							|  |  |  | 	s2.RecordEmailChangeToken.Duration = 5 | 
					
						
							|  |  |  | 	s2.RecordVerificationToken.Duration = 6 | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 	s2.RecordFileToken.Duration = 7 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	s2.GoogleAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.GoogleAuth.ClientId = "google_test" | 
					
						
							|  |  |  | 	s2.FacebookAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.FacebookAuth.ClientId = "facebook_test" | 
					
						
							|  |  |  | 	s2.GithubAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.GithubAuth.ClientId = "github_test" | 
					
						
							|  |  |  | 	s2.GitlabAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.GitlabAuth.ClientId = "gitlab_test" | 
					
						
							| 
									
										
										
										
											2022-08-22 00:38:42 +08:00
										 |  |  | 	s2.DiscordAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.DiscordAuth.ClientId = "discord_test" | 
					
						
							| 
									
										
										
										
											2022-09-01 21:46:06 +08:00
										 |  |  | 	s2.TwitterAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.TwitterAuth.ClientId = "twitter_test" | 
					
						
							| 
									
										
										
										
											2022-11-01 03:17:10 +08:00
										 |  |  | 	s2.MicrosoftAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.MicrosoftAuth.ClientId = "microsoft_test" | 
					
						
							| 
									
										
										
										
											2022-11-01 23:06:06 +08:00
										 |  |  | 	s2.SpotifyAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.SpotifyAuth.ClientId = "spotify_test" | 
					
						
							| 
									
										
										
										
											2022-11-13 19:05:06 +08:00
										 |  |  | 	s2.KakaoAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.KakaoAuth.ClientId = "kakao_test" | 
					
						
							| 
									
										
										
										
											2022-11-13 20:20:11 +08:00
										 |  |  | 	s2.TwitchAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.TwitchAuth.ClientId = "twitch_test" | 
					
						
							| 
									
										
										
										
											2022-12-31 08:21:41 +08:00
										 |  |  | 	s2.StravaAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.StravaAuth.ClientId = "strava_test" | 
					
						
							| 
									
										
										
										
											2022-12-31 17:46:36 +08:00
										 |  |  | 	s2.GiteeAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.GiteeAuth.ClientId = "gitee_test" | 
					
						
							| 
									
										
										
										
											2023-01-13 04:12:34 +08:00
										 |  |  | 	s2.LivechatAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.LivechatAuth.ClientId = "livechat_test" | 
					
						
							| 
									
										
										
										
											2023-01-20 16:17:57 +08:00
										 |  |  | 	s2.GiteaAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.GiteaAuth.ClientId = "gitea_test" | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s2.OIDCAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.OIDCAuth.ClientId = "oidc_test" | 
					
						
							|  |  |  | 	s2.OIDC2Auth.Enabled = true | 
					
						
							|  |  |  | 	s2.OIDC2Auth.ClientId = "oidc2_test" | 
					
						
							|  |  |  | 	s2.OIDC3Auth.Enabled = true | 
					
						
							|  |  |  | 	s2.OIDC3Auth.ClientId = "oidc3_test" | 
					
						
							| 
									
										
										
										
											2023-03-02 05:29:45 +08:00
										 |  |  | 	s2.AppleAuth.Enabled = true | 
					
						
							|  |  |  | 	s2.AppleAuth.ClientId = "apple_test" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if err := s1.Merge(s2); err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s1Encoded, err := json.Marshal(s1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s2Encoded, err := json.Marshal(s2) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if string(s1Encoded) != string(s2Encoded) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected the same serialization, got %v VS %v", string(s1Encoded), string(s2Encoded)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSettingsClone(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	s1 := settings.New() | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s2, err := s1.Clone() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s1Bytes, err := json.Marshal(s1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s2Bytes, err := json.Marshal(s2) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if string(s1Bytes) != string(s2Bytes) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected equivalent serialization, got %v VS %v", string(s1Bytes), string(s2Bytes)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// verify that it is a deep copy
 | 
					
						
							|  |  |  | 	s1.Meta.AppName = "new" | 
					
						
							|  |  |  | 	if s1.Meta.AppName == s2.Meta.AppName { | 
					
						
							|  |  |  | 		t.Fatalf("Expected s1 and s2 to have different Meta.AppName, got %s", s1.Meta.AppName) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSettingsRedactClone(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	testSecret := "test_secret" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	s1 := settings.New() | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// control fields
 | 
					
						
							|  |  |  | 	s1.Meta.AppName = "test123" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// secrets
 | 
					
						
							|  |  |  | 	s1.Smtp.Password = testSecret | 
					
						
							|  |  |  | 	s1.S3.Secret = testSecret | 
					
						
							|  |  |  | 	s1.AdminAuthToken.Secret = testSecret | 
					
						
							|  |  |  | 	s1.AdminPasswordResetToken.Secret = testSecret | 
					
						
							| 
									
										
										
										
											2023-04-05 01:47:03 +08:00
										 |  |  | 	s1.AdminFileToken.Secret = testSecret | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s1.RecordAuthToken.Secret = testSecret | 
					
						
							|  |  |  | 	s1.RecordPasswordResetToken.Secret = testSecret | 
					
						
							|  |  |  | 	s1.RecordEmailChangeToken.Secret = testSecret | 
					
						
							|  |  |  | 	s1.RecordVerificationToken.Secret = testSecret | 
					
						
							| 
									
										
										
										
											2023-04-05 01:33:35 +08:00
										 |  |  | 	s1.RecordFileToken.Secret = testSecret | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s1.GoogleAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.FacebookAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.GithubAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.GitlabAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.DiscordAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.TwitterAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.MicrosoftAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.SpotifyAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.KakaoAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.TwitchAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.StravaAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.GiteeAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.LivechatAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.GiteaAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.OIDCAuth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.OIDC2Auth.ClientSecret = testSecret | 
					
						
							|  |  |  | 	s1.OIDC3Auth.ClientSecret = testSecret | 
					
						
							| 
									
										
										
										
											2023-03-02 05:29:45 +08:00
										 |  |  | 	s1.AppleAuth.ClientSecret = testSecret | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s1Bytes, err := json.Marshal(s1) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s2, err := s1.RedactClone() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s2Bytes, err := json.Marshal(s2) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	if bytes.Equal(s1Bytes, s2Bytes) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected the 2 settings to differ, got \n%s", s2Bytes) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if strings.Contains(string(s2Bytes), testSecret) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected %q secret to be replaced with mask, got \n%s", testSecret, s2Bytes) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	if !strings.Contains(string(s2Bytes), settings.SecretMask) { | 
					
						
							|  |  |  | 		t.Fatalf("Expected the secrets to be replaced with the secret mask, got \n%s", s2Bytes) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !strings.Contains(string(s2Bytes), `"appName":"test123"`) { | 
					
						
							|  |  |  | 		t.Fatalf("Missing control field in \n%s", s2Bytes) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestNamedAuthProviderConfigs(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	s := settings.New() | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s.GoogleAuth.ClientId = "google_test" | 
					
						
							|  |  |  | 	s.FacebookAuth.ClientId = "facebook_test" | 
					
						
							|  |  |  | 	s.GithubAuth.ClientId = "github_test" | 
					
						
							|  |  |  | 	s.GitlabAuth.ClientId = "gitlab_test" | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s.GitlabAuth.Enabled = true // control
 | 
					
						
							| 
									
										
										
										
											2022-08-22 00:38:42 +08:00
										 |  |  | 	s.DiscordAuth.ClientId = "discord_test" | 
					
						
							| 
									
										
										
										
											2022-09-01 21:46:06 +08:00
										 |  |  | 	s.TwitterAuth.ClientId = "twitter_test" | 
					
						
							| 
									
										
										
										
											2022-11-01 03:17:10 +08:00
										 |  |  | 	s.MicrosoftAuth.ClientId = "microsoft_test" | 
					
						
							| 
									
										
										
										
											2022-11-01 23:06:06 +08:00
										 |  |  | 	s.SpotifyAuth.ClientId = "spotify_test" | 
					
						
							| 
									
										
										
										
											2022-11-13 19:05:06 +08:00
										 |  |  | 	s.KakaoAuth.ClientId = "kakao_test" | 
					
						
							| 
									
										
										
										
											2022-11-13 20:20:11 +08:00
										 |  |  | 	s.TwitchAuth.ClientId = "twitch_test" | 
					
						
							| 
									
										
										
										
											2022-12-31 08:21:41 +08:00
										 |  |  | 	s.StravaAuth.ClientId = "strava_test" | 
					
						
							| 
									
										
										
										
											2022-12-31 17:46:36 +08:00
										 |  |  | 	s.GiteeAuth.ClientId = "gitee_test" | 
					
						
							| 
									
										
										
										
											2023-01-13 04:12:34 +08:00
										 |  |  | 	s.LivechatAuth.ClientId = "livechat_test" | 
					
						
							| 
									
										
										
										
											2023-01-20 16:17:57 +08:00
										 |  |  | 	s.GiteaAuth.ClientId = "gitea_test" | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 	s.OIDCAuth.ClientId = "oidc_test" | 
					
						
							|  |  |  | 	s.OIDC2Auth.ClientId = "oidc2_test" | 
					
						
							|  |  |  | 	s.OIDC3Auth.ClientId = "oidc3_test" | 
					
						
							| 
									
										
										
										
											2023-03-02 05:29:45 +08:00
										 |  |  | 	s.AppleAuth.ClientId = "apple_test" | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result := s.NamedAuthProviderConfigs() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	encoded, err := json.Marshal(result) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-11-13 19:05:06 +08:00
										 |  |  | 	encodedStr := string(encoded) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expectedParts := []string{ | 
					
						
							| 
									
										
										
										
											2023-02-24 03:07:00 +08:00
										 |  |  | 		`"discord":{"enabled":false,"clientId":"discord_test"`, | 
					
						
							|  |  |  | 		`"facebook":{"enabled":false,"clientId":"facebook_test"`, | 
					
						
							|  |  |  | 		`"github":{"enabled":false,"clientId":"github_test"`, | 
					
						
							|  |  |  | 		`"gitlab":{"enabled":true,"clientId":"gitlab_test"`, | 
					
						
							|  |  |  | 		`"google":{"enabled":false,"clientId":"google_test"`, | 
					
						
							|  |  |  | 		`"microsoft":{"enabled":false,"clientId":"microsoft_test"`, | 
					
						
							|  |  |  | 		`"spotify":{"enabled":false,"clientId":"spotify_test"`, | 
					
						
							|  |  |  | 		`"twitter":{"enabled":false,"clientId":"twitter_test"`, | 
					
						
							|  |  |  | 		`"kakao":{"enabled":false,"clientId":"kakao_test"`, | 
					
						
							|  |  |  | 		`"twitch":{"enabled":false,"clientId":"twitch_test"`, | 
					
						
							|  |  |  | 		`"strava":{"enabled":false,"clientId":"strava_test"`, | 
					
						
							|  |  |  | 		`"gitee":{"enabled":false,"clientId":"gitee_test"`, | 
					
						
							|  |  |  | 		`"livechat":{"enabled":false,"clientId":"livechat_test"`, | 
					
						
							|  |  |  | 		`"gitea":{"enabled":false,"clientId":"gitea_test"`, | 
					
						
							|  |  |  | 		`"oidc":{"enabled":false,"clientId":"oidc_test"`, | 
					
						
							|  |  |  | 		`"oidc2":{"enabled":false,"clientId":"oidc2_test"`, | 
					
						
							|  |  |  | 		`"oidc3":{"enabled":false,"clientId":"oidc3_test"`, | 
					
						
							| 
									
										
										
										
											2023-03-02 05:29:45 +08:00
										 |  |  | 		`"apple":{"enabled":false,"clientId":"apple_test"`, | 
					
						
							| 
									
										
										
										
											2022-11-13 19:05:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for _, p := range expectedParts { | 
					
						
							|  |  |  | 		if !strings.Contains(encodedStr, p) { | 
					
						
							|  |  |  | 			t.Fatalf("Expected \n%s \nin \n%s", p, encodedStr) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestTokenConfigValidate(t *testing.T) { | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		config      settings.TokenConfig | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		expectError bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// zero values
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.TokenConfig{}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.TokenConfig{ | 
					
						
							| 
									
										
										
										
											2022-08-25 15:57:50 +08:00
										 |  |  | 				Secret:   strings.Repeat("a", 5), | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Duration: 4, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-08-25 15:57:50 +08:00
										 |  |  | 		// valid secret but invalid duration
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.TokenConfig{ | 
					
						
							| 
									
										
										
										
											2022-08-25 15:57:50 +08:00
										 |  |  | 				Secret:   strings.Repeat("a", 30), | 
					
						
							|  |  |  | 				Duration: 63072000 + 1, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		// valid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.TokenConfig{ | 
					
						
							| 
									
										
										
										
											2022-08-25 15:57:50 +08:00
										 |  |  | 				Secret:   strings.Repeat("a", 30), | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Duration: 100, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, scenario := range scenarios { | 
					
						
							|  |  |  | 		result := scenario.config.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result != nil && !scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Didn't expect error, got %v", i, result) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result == nil && scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error, got nil", i) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestSmtpConfigValidate(t *testing.T) { | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		config      settings.SmtpConfig | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		expectError bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// zero values (disabled)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.SmtpConfig{}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// zero values (enabled)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.SmtpConfig{Enabled: true}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.SmtpConfig{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled: true, | 
					
						
							|  |  |  | 				Host:    "test:test:test", | 
					
						
							|  |  |  | 				Port:    -10, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-12-13 17:45:59 +08:00
										 |  |  | 		// invalid auth method
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			settings.SmtpConfig{ | 
					
						
							|  |  |  | 				Enabled:    true, | 
					
						
							|  |  |  | 				Host:       "example.com", | 
					
						
							|  |  |  | 				Port:       100, | 
					
						
							|  |  |  | 				AuthMethod: "example", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data (no explicit auth method)
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.SmtpConfig{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled: true, | 
					
						
							|  |  |  | 				Host:    "example.com", | 
					
						
							|  |  |  | 				Port:    100, | 
					
						
							|  |  |  | 				Tls:     true, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-12-13 17:45:59 +08:00
										 |  |  | 		// valid data (explicit auth method - login)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			settings.SmtpConfig{ | 
					
						
							|  |  |  | 				Enabled:    true, | 
					
						
							|  |  |  | 				Host:       "example.com", | 
					
						
							|  |  |  | 				Port:       100, | 
					
						
							|  |  |  | 				AuthMethod: mailer.SmtpAuthLogin, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, scenario := range scenarios { | 
					
						
							|  |  |  | 		result := scenario.config.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result != nil && !scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Didn't expect error, got %v", i, result) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result == nil && scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error, got nil", i) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestS3ConfigValidate(t *testing.T) { | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		config      settings.S3Config | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		expectError bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// zero values (disabled)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.S3Config{}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// zero values (enabled)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.S3Config{Enabled: true}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.S3Config{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled:  true, | 
					
						
							|  |  |  | 				Endpoint: "test:test:test", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2022-07-12 02:00:17 +08:00
										 |  |  | 		// valid data (url endpoint)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.S3Config{ | 
					
						
							| 
									
										
										
										
											2022-07-12 02:00:17 +08:00
										 |  |  | 				Enabled:   true, | 
					
						
							|  |  |  | 				Endpoint:  "https://localhost:8090", | 
					
						
							|  |  |  | 				Bucket:    "test", | 
					
						
							|  |  |  | 				Region:    "test", | 
					
						
							|  |  |  | 				AccessKey: "test", | 
					
						
							|  |  |  | 				Secret:    "test", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data (hostname endpoint)
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.S3Config{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled:   true, | 
					
						
							|  |  |  | 				Endpoint:  "example.com", | 
					
						
							|  |  |  | 				Bucket:    "test", | 
					
						
							|  |  |  | 				Region:    "test", | 
					
						
							|  |  |  | 				AccessKey: "test", | 
					
						
							|  |  |  | 				Secret:    "test", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, scenario := range scenarios { | 
					
						
							|  |  |  | 		result := scenario.config.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result != nil && !scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Didn't expect error, got %v", i, result) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result == nil && scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error, got nil", i) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestMetaConfigValidate(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	invalidTemplate := settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 		Subject:   "test", | 
					
						
							|  |  |  | 		ActionUrl: "test", | 
					
						
							|  |  |  | 		Body:      "test", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	noPlaceholdersTemplate := settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 		Subject:   "test", | 
					
						
							|  |  |  | 		ActionUrl: "http://example.com", | 
					
						
							|  |  |  | 		Body:      "test", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	withPlaceholdersTemplate := settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 		Subject:   "test", | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		ActionUrl: "http://example.com" + settings.EmailPlaceholderToken, | 
					
						
							|  |  |  | 		Body:      "test" + settings.EmailPlaceholderActionUrl, | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		config      settings.MetaConfig | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		expectError bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// zero values
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.MetaConfig{}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.MetaConfig{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				AppName:                    strings.Repeat("a", 300), | 
					
						
							|  |  |  | 				AppUrl:                     "test", | 
					
						
							|  |  |  | 				SenderName:                 strings.Repeat("a", 300), | 
					
						
							|  |  |  | 				SenderAddress:              "invalid_email", | 
					
						
							|  |  |  | 				VerificationTemplate:       invalidTemplate, | 
					
						
							|  |  |  | 				ResetPasswordTemplate:      invalidTemplate, | 
					
						
							|  |  |  | 				ConfirmEmailChangeTemplate: invalidTemplate, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data (missing required placeholders)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.MetaConfig{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				AppName:                    "test", | 
					
						
							|  |  |  | 				AppUrl:                     "https://example.com", | 
					
						
							|  |  |  | 				SenderName:                 "test", | 
					
						
							|  |  |  | 				SenderAddress:              "test@example.com", | 
					
						
							|  |  |  | 				VerificationTemplate:       noPlaceholdersTemplate, | 
					
						
							|  |  |  | 				ResetPasswordTemplate:      noPlaceholdersTemplate, | 
					
						
							|  |  |  | 				ConfirmEmailChangeTemplate: noPlaceholdersTemplate, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.MetaConfig{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				AppName:                    "test", | 
					
						
							|  |  |  | 				AppUrl:                     "https://example.com", | 
					
						
							|  |  |  | 				SenderName:                 "test", | 
					
						
							|  |  |  | 				SenderAddress:              "test@example.com", | 
					
						
							|  |  |  | 				VerificationTemplate:       withPlaceholdersTemplate, | 
					
						
							|  |  |  | 				ResetPasswordTemplate:      withPlaceholdersTemplate, | 
					
						
							|  |  |  | 				ConfirmEmailChangeTemplate: withPlaceholdersTemplate, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, scenario := range scenarios { | 
					
						
							|  |  |  | 		result := scenario.config.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result != nil && !scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Didn't expect error, got %v", i, result) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result == nil && scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error, got nil", i) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | func TestEmailTemplateValidate(t *testing.T) { | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		emailTemplate  settings.EmailTemplate | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 		expectedErrors []string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// require values
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.EmailTemplate{}, | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 			[]string{"subject", "actionUrl", "body"}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// missing placeholders
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				Subject:   "test", | 
					
						
							|  |  |  | 				ActionUrl: "test", | 
					
						
							|  |  |  | 				Body:      "test", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			[]string{"actionUrl", "body"}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				Subject:   "test", | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 				ActionUrl: "test" + settings.EmailPlaceholderToken, | 
					
						
							|  |  |  | 				Body:      "test" + settings.EmailPlaceholderActionUrl, | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			[]string{}, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, s := range scenarios { | 
					
						
							|  |  |  | 		result := s.emailTemplate.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// parse errors
 | 
					
						
							|  |  |  | 		errs, ok := result.(validation.Errors) | 
					
						
							|  |  |  | 		if !ok && result != nil { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Failed to parse errors %v", i, result) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// check errors
 | 
					
						
							|  |  |  | 		if len(errs) > len(s.expectedErrors) { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error keys %v, got %v", i, s.expectedErrors, errs) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for _, k := range s.expectedErrors { | 
					
						
							|  |  |  | 			if _, ok := errs[k]; !ok { | 
					
						
							|  |  |  | 				t.Errorf("(%d) Missing expected error key %q in %v", i, k, errs) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestEmailTemplateResolve(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	allPlaceholders := settings.EmailPlaceholderActionUrl + settings.EmailPlaceholderToken + settings.EmailPlaceholderAppName + settings.EmailPlaceholderAppUrl | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		emailTemplate     settings.EmailTemplate | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 		expectedSubject   string | 
					
						
							|  |  |  | 		expectedBody      string | 
					
						
							|  |  |  | 		expectedActionUrl string | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// no placeholders
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			emailTemplate: settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				Subject:   "subject:", | 
					
						
							|  |  |  | 				Body:      "body:", | 
					
						
							|  |  |  | 				ActionUrl: "/actionUrl////", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedSubject:   "subject:", | 
					
						
							|  |  |  | 			expectedActionUrl: "/actionUrl/", | 
					
						
							|  |  |  | 			expectedBody:      "body:", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// with placeholders
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			emailTemplate: settings.EmailTemplate{ | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				ActionUrl: "/actionUrl////" + allPlaceholders, | 
					
						
							|  |  |  | 				Subject:   "subject:" + allPlaceholders, | 
					
						
							|  |  |  | 				Body:      "body:" + allPlaceholders, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			expectedActionUrl: fmt.Sprintf( | 
					
						
							|  |  |  | 				"/actionUrl/%%7BACTION_URL%%7D%s%s%s", | 
					
						
							|  |  |  | 				"token_test", | 
					
						
							|  |  |  | 				"name_test", | 
					
						
							|  |  |  | 				"url_test", | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			expectedSubject: fmt.Sprintf( | 
					
						
							|  |  |  | 				"subject:%s%s%s%s", | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 				settings.EmailPlaceholderActionUrl, | 
					
						
							|  |  |  | 				settings.EmailPlaceholderToken, | 
					
						
							| 
									
										
										
										
											2022-08-15 00:30:45 +08:00
										 |  |  | 				"name_test", | 
					
						
							|  |  |  | 				"url_test", | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			expectedBody: fmt.Sprintf( | 
					
						
							|  |  |  | 				"body:%s%s%s%s", | 
					
						
							|  |  |  | 				fmt.Sprintf( | 
					
						
							|  |  |  | 					"/actionUrl/%%7BACTION_URL%%7D%s%s%s", | 
					
						
							|  |  |  | 					"token_test", | 
					
						
							|  |  |  | 					"name_test", | 
					
						
							|  |  |  | 					"url_test", | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				"token_test", | 
					
						
							|  |  |  | 				"name_test", | 
					
						
							|  |  |  | 				"url_test", | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, s := range scenarios { | 
					
						
							|  |  |  | 		subject, body, actionUrl := s.emailTemplate.Resolve("name_test", "url_test", "token_test") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if s.expectedSubject != subject { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected subject %q got %q", i, s.expectedSubject, subject) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if s.expectedBody != body { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected body \n%v got \n%v", i, s.expectedBody, body) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if s.expectedActionUrl != actionUrl { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected actionUrl \n%v got \n%v", i, s.expectedActionUrl, actionUrl) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | func TestLogsConfigValidate(t *testing.T) { | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		config      settings.LogsConfig | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		expectError bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// zero values
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.LogsConfig{}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.LogsConfig{MaxDays: -10}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.LogsConfig{MaxDays: 1}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, scenario := range scenarios { | 
					
						
							|  |  |  | 		result := scenario.config.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result != nil && !scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Didn't expect error, got %v", i, result) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result == nil && scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error, got nil", i) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestAuthProviderConfigValidate(t *testing.T) { | 
					
						
							|  |  |  | 	scenarios := []struct { | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 		config      settings.AuthProviderConfig | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		expectError bool | 
					
						
							|  |  |  | 	}{ | 
					
						
							|  |  |  | 		// zero values (disabled)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.AuthProviderConfig{}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// zero values (enabled)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.AuthProviderConfig{Enabled: true}, | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// invalid data
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.AuthProviderConfig{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled:      true, | 
					
						
							|  |  |  | 				ClientId:     "", | 
					
						
							|  |  |  | 				ClientSecret: "", | 
					
						
							|  |  |  | 				AuthUrl:      "test", | 
					
						
							|  |  |  | 				TokenUrl:     "test", | 
					
						
							|  |  |  | 				UserApiUrl:   "test", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			true, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data (only the required)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.AuthProviderConfig{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled:      true, | 
					
						
							|  |  |  | 				ClientId:     "test", | 
					
						
							|  |  |  | 				ClientSecret: "test", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		// valid data (fill all fields)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 			settings.AuthProviderConfig{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 				Enabled:      true, | 
					
						
							|  |  |  | 				ClientId:     "test", | 
					
						
							|  |  |  | 				ClientSecret: "test", | 
					
						
							|  |  |  | 				AuthUrl:      "https://example.com", | 
					
						
							|  |  |  | 				TokenUrl:     "https://example.com", | 
					
						
							|  |  |  | 				UserApiUrl:   "https://example.com", | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, scenario := range scenarios { | 
					
						
							|  |  |  | 		result := scenario.config.Validate() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result != nil && !scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Didn't expect error, got %v", i, result) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if result == nil && scenario.expectError { | 
					
						
							|  |  |  | 			t.Errorf("(%d) Expected error, got nil", i) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestAuthProviderConfigSetupProvider(t *testing.T) { | 
					
						
							|  |  |  | 	provider := auth.NewGithubProvider() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// disabled config
 | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	c1 := settings.AuthProviderConfig{Enabled: false} | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	if err := c1.SetupProvider(provider); err == nil { | 
					
						
							|  |  |  | 		t.Errorf("Expected error, got nil") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 20:42:45 +08:00
										 |  |  | 	c2 := settings.AuthProviderConfig{ | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 		Enabled:      true, | 
					
						
							|  |  |  | 		ClientId:     "test_ClientId", | 
					
						
							|  |  |  | 		ClientSecret: "test_ClientSecret", | 
					
						
							|  |  |  | 		AuthUrl:      "test_AuthUrl", | 
					
						
							|  |  |  | 		UserApiUrl:   "test_UserApiUrl", | 
					
						
							|  |  |  | 		TokenUrl:     "test_TokenUrl", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if err := c2.SetupProvider(provider); err != nil { | 
					
						
							|  |  |  | 		t.Error(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if provider.ClientId() != c2.ClientId { | 
					
						
							|  |  |  | 		t.Fatalf("Expected ClientId %s, got %s", c2.ClientId, provider.ClientId()) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 	if provider.ClientSecret() != c2.ClientSecret { | 
					
						
							|  |  |  | 		t.Fatalf("Expected ClientSecret %s, got %s", c2.ClientSecret, provider.ClientSecret()) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 	if provider.AuthUrl() != c2.AuthUrl { | 
					
						
							|  |  |  | 		t.Fatalf("Expected AuthUrl %s, got %s", c2.AuthUrl, provider.AuthUrl()) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 	if provider.UserApiUrl() != c2.UserApiUrl { | 
					
						
							|  |  |  | 		t.Fatalf("Expected UserApiUrl %s, got %s", c2.UserApiUrl, provider.UserApiUrl()) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-30 16:28:14 +08:00
										 |  |  | 	if provider.TokenUrl() != c2.TokenUrl { | 
					
						
							|  |  |  | 		t.Fatalf("Expected TokenUrl %s, got %s", c2.TokenUrl, provider.TokenUrl()) | 
					
						
							| 
									
										
										
										
											2022-07-07 05:19:05 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |