Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Windows claim formats. #2293

Merged
merged 2 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/services/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const UserSpecV2SchemaTemplate = `{
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^[a-zA-Z/.0-9_]+$": {
"^[a-zA-Z/.0-9_:]+$": {
"type": ["array", "null"],
"items": {
"type": "string"
Expand Down
58 changes: 49 additions & 9 deletions lib/services/users_test.go → lib/services/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,65 @@ limitations under the License.
package services

import (
"encoding/json"
"fmt"

"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/utils"
"github.com/russellhaering/gosaml2/types"

"github.com/coreos/go-oidc/jose"
saml2 "github.com/russellhaering/gosaml2"
. "gopkg.in/check.v1"
"github.com/russellhaering/gosaml2/types"
"gopkg.in/check.v1"
)

type UserSuite struct {
}

var _ = Suite(&UserSuite{})
var _ = check.Suite(&UserSuite{})

func (s *UserSuite) SetUpSuite(c *C) {
func (s *UserSuite) SetUpSuite(c *check.C) {
utils.InitLoggerForTests()
}

func (s *UserSuite) TestOIDCMapping(c *C) {
func (s *UserSuite) TestTraits(c *check.C) {
var tests = []struct {
traitName string
}{
// Windows trait names are URLs.
{
traitName: "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname",
},
// Simple strings are the most common trait names.
{
traitName: "groups",
},
}

for _, tt := range tests {
user := &UserV2{
Kind: KindUser,
Version: V2,
Metadata: Metadata{
Name: "foo",
Namespace: defaults.Namespace,
},
Spec: UserSpecV2{
Traits: map[string][]string{
tt.traitName: []string{"foo"},
},
},
}

data, err := json.Marshal(user)
c.Assert(err, check.IsNil)

_, err = GetUserMarshaler().UnmarshalUser(data)
c.Assert(err, check.IsNil)
}
}

func (s *UserSuite) TestOIDCMapping(c *check.C) {
type input struct {
comment string
claims jose.Claims
Expand Down Expand Up @@ -162,9 +202,9 @@ func (s *UserSuite) TestOIDCMapping(c *C) {
},
}
for _, input := range testCase.inputs {
comment := Commentf("OIDC Test case %v %v, input %#v", i, testCase.comment, input)
comment := check.Commentf("OIDC Test case %v %v, input %#v", i, testCase.comment, input)
outRoles := conn.MapClaims(input.claims)
c.Assert(outRoles, DeepEquals, input.roles, comment)
c.Assert(outRoles, check.DeepEquals, input.roles, comment)
}

samlConn := SAMLConnectorV2{
Expand All @@ -173,9 +213,9 @@ func (s *UserSuite) TestOIDCMapping(c *C) {
},
}
for _, input := range testCase.inputs {
comment := Commentf("SAML Test case %v %v, input %#v", i, testCase.comment, input)
comment := check.Commentf("SAML Test case %v %v, input %#v", i, testCase.comment, input)
outRoles := samlConn.MapAttributes(claimsToAttributes(input.claims))
c.Assert(outRoles, DeepEquals, input.roles, comment)
c.Assert(outRoles, check.DeepEquals, input.roles, comment)
}
}
}
Expand Down