From d099292d99f4b4649ebc4d7c5128d71a016e9d4f Mon Sep 17 00:00:00 2001 From: Misi Date: Tue, 5 Dec 2023 12:13:55 +0100 Subject: [PATCH] Auth: Fix for the github_oauth parse config error (#79063) * Fix for reverting the github_oauth parse config behaviour * minimal changes --- pkg/login/social/github_oauth.go | 12 +++++------- pkg/login/social/github_oauth_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/login/social/github_oauth.go b/pkg/login/social/github_oauth.go index 252c86cf287..95848d21fc5 100644 --- a/pkg/login/social/github_oauth.go +++ b/pkg/login/social/github_oauth.go @@ -57,10 +57,7 @@ func NewGitHubProvider(settings map[string]any, cfg *setting.Cfg, features *feat return nil, err } - teamIds, err := mustInts(util.SplitString(info.Extra[teamIdsKey])) - if err != nil { - return nil, err - } + teamIds := mustInts(util.SplitString(info.Extra[teamIdsKey])) config := createOAuthConfig(info, cfg, GitHubProviderName) provider := &SocialGithub{ @@ -329,14 +326,15 @@ func convertToGroupList(t []GithubTeam) []string { return groups } -func mustInts(s []string) ([]int, error) { +func mustInts(s []string) []int { result := make([]int, 0, len(s)) for _, v := range s { num, err := strconv.Atoi(v) if err != nil { - return nil, err + // TODO: add log here + return []int{} } result = append(result, num) } - return result, nil + return result } diff --git a/pkg/login/social/github_oauth_test.go b/pkg/login/social/github_oauth_test.go index d8aefe2f980..1326c6cde12 100644 --- a/pkg/login/social/github_oauth_test.go +++ b/pkg/login/social/github_oauth_test.go @@ -307,6 +307,16 @@ func TestSocialGitHub_InitializeExtraFields(t *testing.T) { allowedOrganizations: []string{}, }, }, + { + name: "should not error when teamIds are not integers", + settings: map[string]any{ + "team_ids": "abc1234,5678", + }, + want: settingFields{ + teamIds: []int{}, + allowedOrganizations: []string{}, + }, + }, } for _, tc := range testCases {