mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-24 16:17:11 +08:00
Fixed findings:
```
lib/services/github_test.go:99:2: SA4006: this value of `kubeUsers` is never used (staticcheck)
logins, kubeGroups, kubeUsers = connector.MapClaims(GithubClaims{
^
lib/services/github_test.go:107:2: SA4006: this value of `kubeUsers` is never used (staticcheck)
logins, kubeGroups, kubeUsers = connector.MapClaims(GithubClaims{
^
lib/services/local/configuration_test.go:84:2: SA4006: this value of `clusterConfig` is never used (staticcheck)
clusterConfig, err := services.NewClusterConfig(services.ClusterConfigSpecV3{
^
lib/services/local/configuration_test.go:102:2: SA4006: this value of `clusterConfig` is never used (staticcheck)
clusterConfig, err := services.NewClusterConfig(services.ClusterConfigSpecV3{})
^
lib/services/local/presence_test.go:108:2: SA4006: this value of `gotTC` is never used (staticcheck)
gotTC, err = presenceBackend.GetTrustedCluster("foo")
^
lib/services/suite/suite.go:157:2: SA4006: this value of `err` is never used (staticcheck)
out, err := s.WebS.GetUser("user1", false)
^
lib/services/suite/suite.go:208:2: SA4006: this value of `u` is never used (staticcheck)
u, err = s.WebS.GetUser("foo", false)
^
lib/services/suite/suite.go:277:2: SA4006: this value of `err` is never used (staticcheck)
err = s.CAS.CompareAndSwapCertAuthority(&newCA, ca)
^
lib/services/suite/suite.go:339:2: SA4006: this value of `err` is never used (staticcheck)
out, err = s.PresenceS.GetProxies()
^
lib/services/suite/suite.go:1136:5: SA4006: this value of `err` is never used (staticcheck)
role, err := services.NewRole("role1", services.RoleSpecV3{
^
lib/services/suite/suite.go:1166:5: SA4006: this value of `err` is never used (staticcheck)
err := s.Users().UpsertUser(user)
^
```
117 lines
3.4 KiB
Go
117 lines
3.4 KiB
Go
/*
|
|
Copyright 2017 Gravitational, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package services
|
|
|
|
import (
|
|
"github.com/gravitational/teleport/lib/utils"
|
|
|
|
check "gopkg.in/check.v1"
|
|
)
|
|
|
|
type GithubSuite struct{}
|
|
|
|
var _ = check.Suite(&GithubSuite{})
|
|
|
|
func (s *GithubSuite) SetUpSuite(c *check.C) {
|
|
utils.InitLoggerForTests()
|
|
}
|
|
|
|
func (s *GithubSuite) TestUnmarshal(c *check.C) {
|
|
data := []byte(`{"kind": "github",
|
|
"version": "v3",
|
|
"metadata": {
|
|
"name": "github"
|
|
},
|
|
"spec": {
|
|
"client_id": "aaa",
|
|
"client_secret": "bbb",
|
|
"display": "Github",
|
|
"redirect_url": "https://localhost:3080/v1/webapi/github/callback",
|
|
"teams_to_logins": [{
|
|
"organization": "gravitational",
|
|
"team": "admins",
|
|
"logins": ["admin"]
|
|
}]
|
|
}}`)
|
|
connector, err := GetGithubConnectorMarshaler().Unmarshal(data)
|
|
c.Assert(err, check.IsNil)
|
|
expected := NewGithubConnector("github", GithubConnectorSpecV3{
|
|
ClientID: "aaa",
|
|
ClientSecret: "bbb",
|
|
RedirectURL: "https://localhost:3080/v1/webapi/github/callback",
|
|
Display: "Github",
|
|
TeamsToLogins: []TeamMapping{
|
|
{
|
|
Organization: "gravitational",
|
|
Team: "admins",
|
|
Logins: []string{"admin"},
|
|
},
|
|
},
|
|
})
|
|
c.Assert(expected, check.DeepEquals, connector)
|
|
}
|
|
|
|
func (s *GithubSuite) TestMapClaims(c *check.C) {
|
|
connector := NewGithubConnector("github", GithubConnectorSpecV3{
|
|
ClientID: "aaa",
|
|
ClientSecret: "bbb",
|
|
RedirectURL: "https://localhost:3080/v1/webapi/github/callback",
|
|
Display: "Github",
|
|
TeamsToLogins: []TeamMapping{
|
|
{
|
|
Organization: "gravitational",
|
|
Team: "admins",
|
|
Logins: []string{"admin", "dev"},
|
|
KubeGroups: []string{"system:masters", "kube-devs"},
|
|
KubeUsers: []string{"alice@example.com"},
|
|
},
|
|
{
|
|
Organization: "gravitational",
|
|
Team: "devs",
|
|
Logins: []string{"dev", "test"},
|
|
KubeGroups: []string{"kube-devs"},
|
|
},
|
|
},
|
|
})
|
|
logins, kubeGroups, kubeUsers := connector.MapClaims(GithubClaims{
|
|
OrganizationToTeams: map[string][]string{
|
|
"gravitational": []string{"admins"},
|
|
},
|
|
})
|
|
c.Assert(logins, check.DeepEquals, []string{"admin", "dev"})
|
|
c.Assert(kubeGroups, check.DeepEquals, []string{"system:masters", "kube-devs"})
|
|
c.Assert(kubeUsers, check.DeepEquals, []string{"alice@example.com"})
|
|
|
|
logins, kubeGroups, kubeUsers = connector.MapClaims(GithubClaims{
|
|
OrganizationToTeams: map[string][]string{
|
|
"gravitational": []string{"devs"},
|
|
},
|
|
})
|
|
c.Assert(logins, check.DeepEquals, []string{"dev", "test"})
|
|
c.Assert(kubeGroups, check.DeepEquals, []string{"kube-devs"})
|
|
c.Assert(kubeUsers, check.DeepEquals, []string(nil))
|
|
|
|
logins, kubeGroups, kubeUsers = connector.MapClaims(GithubClaims{
|
|
OrganizationToTeams: map[string][]string{
|
|
"gravitational": []string{"admins", "devs"},
|
|
},
|
|
})
|
|
c.Assert(logins, check.DeepEquals, []string{"admin", "dev", "test"})
|
|
c.Assert(kubeGroups, check.DeepEquals, []string{"system:masters", "kube-devs"})
|
|
c.Assert(kubeUsers, check.DeepEquals, []string{"alice@example.com"})
|
|
}
|