Skip to content

Commit

Permalink
schema: don't include empty Format attributes in samlp:NameIDPolicyEl…
Browse files Browse the repository at this point in the history
…ement

fixes crewjam#177
  • Loading branch information
crewjam committed Nov 4, 2019
1 parent 97dc958 commit 249aa03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ type NameIDPolicy struct {
// Element returns an etree.Element representing the object in XML form.
func (a *NameIDPolicy) Element() *etree.Element {
el := etree.NewElement("samlp:NameIDPolicy")
if a.Format != nil {
if a.Format != nil && *a.Format != "" {
el.CreateAttr("Format", *a.Format)
}
if a.SPNameQualifier != nil {
Expand Down
14 changes: 14 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ func TestAttributeXMLRoundTrip(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}

func TestNameIDFormat(t *testing.T) {
var emptyString string
el := NameIDPolicy{
Format: &emptyString,
}
doc := etree.NewDocument()
doc.SetRoot(el.Element())
x, err := doc.WriteToBytes()
assert.NoError(t, err)
assert.Equal(t,
"<samlp:NameIDPolicy/>",
string(x))
}

0 comments on commit 249aa03

Please sign in to comment.