-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom attributes to saml response (#56)
* feat: add custom attributes to saml response * fix: correct unit test with logic changes * fix: correct unit test with logic changes
- Loading branch information
Showing
9 changed files
with
229 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package provider | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/zitadel/saml/pkg/provider/xml/saml" | ||
) | ||
|
||
func TestSSO_Attributes(t *testing.T) { | ||
type args struct { | ||
email string | ||
fullName string | ||
givenName string | ||
surname string | ||
userID string | ||
username string | ||
customAttributes map[string]*CustomAttribute | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
res []*saml.AttributeType | ||
}{ | ||
{ | ||
"empty attributes", | ||
args{}, | ||
[]*saml.AttributeType{}, | ||
}, | ||
{ | ||
"full attributes", | ||
args{ | ||
email: "email", | ||
fullName: "fullname", | ||
givenName: "givenname", | ||
surname: "surname", | ||
userID: "userid", | ||
username: "username", | ||
customAttributes: nil, | ||
}, | ||
[]*saml.AttributeType{ | ||
{ | ||
Name: "Email", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"email"}, | ||
}, | ||
{ | ||
Name: "SurName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"surname"}, | ||
}, | ||
{ | ||
Name: "FirstName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"givenname"}, | ||
}, | ||
{ | ||
Name: "FullName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"fullname"}, | ||
}, | ||
{ | ||
Name: "UserName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"username"}, | ||
}, | ||
{ | ||
Name: "UserID", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"userid"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"full attributes with custom", | ||
args{ | ||
email: "email", | ||
fullName: "fullname", | ||
givenName: "givenname", | ||
surname: "surname", | ||
userID: "userid", | ||
username: "username", | ||
customAttributes: map[string]*CustomAttribute{ | ||
"empty": { | ||
FriendlyName: "fname", | ||
NameFormat: "nameformat", | ||
AttributeValue: []string{""}, | ||
}, | ||
"key1": { | ||
FriendlyName: "fname1", | ||
NameFormat: "nameformat1", | ||
AttributeValue: []string{"first"}, | ||
}, | ||
"key2": { | ||
FriendlyName: "fname2", | ||
NameFormat: "nameformat2", | ||
AttributeValue: []string{"first", "second"}, | ||
}, | ||
"key3": { | ||
FriendlyName: "fname3", | ||
NameFormat: "nameformat3", | ||
AttributeValue: []string{"first", "second", "third"}, | ||
}, | ||
}, | ||
}, | ||
[]*saml.AttributeType{ | ||
{ | ||
Name: "Email", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"email"}, | ||
}, | ||
{ | ||
Name: "SurName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"surname"}, | ||
}, | ||
{ | ||
Name: "FirstName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"givenname"}, | ||
}, | ||
{ | ||
Name: "FullName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"fullname"}, | ||
}, | ||
{ | ||
Name: "UserName", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"username"}, | ||
}, | ||
{ | ||
Name: "UserID", | ||
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:basic", | ||
AttributeValue: []string{"userid"}, | ||
}, | ||
{ | ||
Name: "empty", | ||
NameFormat: "nameformat", | ||
FriendlyName: "fname", | ||
AttributeValue: []string{""}, | ||
}, | ||
{ | ||
Name: "key1", | ||
NameFormat: "nameformat1", | ||
FriendlyName: "fname1", | ||
AttributeValue: []string{"first"}, | ||
}, | ||
{ | ||
Name: "key2", | ||
NameFormat: "nameformat2", | ||
FriendlyName: "fname2", | ||
AttributeValue: []string{"first", "second"}, | ||
}, | ||
{ | ||
Name: "key3", | ||
NameFormat: "nameformat3", | ||
FriendlyName: "fname3", | ||
AttributeValue: []string{"first", "second", "third"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
attrs := &Attributes{ | ||
email: tt.args.email, | ||
fullName: tt.args.fullName, | ||
givenName: tt.args.givenName, | ||
surname: tt.args.surname, | ||
userID: tt.args.userID, | ||
username: tt.args.username, | ||
customAttributes: tt.args.customAttributes, | ||
} | ||
samlResponseAttributes := attrs.GetSAML() | ||
for _, item := range tt.res { | ||
assert.Contains(t, samlResponseAttributes, item) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters