| 405 | } |
| 406 | |
| 407 | func TestScopingElement(t *testing.T) { |
| 408 | proxyCount := 2 |
| 409 | req := AuthnRequest{Scoping: &Scoping{ |
| 410 | ProxyCount: &proxyCount, |
| 411 | IDPList: &IDPList{ |
| 412 | IDPEntries: []IDPEntry{ |
| 413 | {ProviderID: "https://idp1.example.com"}, |
| 414 | {ProviderID: "https://idp2.example.com", Name: "IDP 2", Loc: "https://idp2.example.com/sso"}, |
| 415 | }, |
| 416 | GetComplete: "https://gateway.example.com/idplist", |
| 417 | }, |
| 418 | RequesterIDs: []string{"https://sp.example.com"}, |
| 419 | }} |
| 420 | |
| 421 | doc := etree.NewDocument() |
| 422 | doc.SetRoot(req.Element()) |
| 423 | x, err := doc.WriteToBytes() |
| 424 | assert.Check(t, err) |
| 425 | assert.Check(t, is.Equal(`<samlp:AuthnRequest xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="" Version="" IssueInstant="0001-01-01T00:00:00Z">`+ |
| 426 | `<samlp:Scoping ProxyCount="2">`+ |
| 427 | `<samlp:IDPList>`+ |
| 428 | `<samlp:IDPEntry ProviderID="https://idp1.example.com"/>`+ |
| 429 | `<samlp:IDPEntry ProviderID="https://idp2.example.com" Name="IDP 2" Loc="https://idp2.example.com/sso"/>`+ |
| 430 | `<samlp:GetComplete>https://gateway.example.com/idplist</samlp:GetComplete>`+ |
| 431 | `</samlp:IDPList>`+ |
| 432 | `<samlp:RequesterID>https://sp.example.com</samlp:RequesterID>`+ |
| 433 | `</samlp:Scoping>`+ |
| 434 | `</samlp:AuthnRequest>`, string(x))) |
| 435 | |
| 436 | // The element form parses back through the encoding/xml struct tags. |
| 437 | var got AuthnRequest |
| 438 | assert.Check(t, xml.Unmarshal(x, &got)) |
| 439 | assert.Assert(t, got.Scoping != nil) |
| 440 | assert.Assert(t, got.Scoping.ProxyCount != nil) |
| 441 | assert.Check(t, is.Equal(2, *got.Scoping.ProxyCount)) |
| 442 | assert.Assert(t, got.Scoping.IDPList != nil) |
| 443 | assert.Check(t, is.Len(got.Scoping.IDPList.IDPEntries, 2)) |
| 444 | assert.Check(t, is.Equal("https://idp1.example.com", got.Scoping.IDPList.IDPEntries[0].ProviderID)) |
| 445 | assert.Check(t, is.Equal("IDP 2", got.Scoping.IDPList.IDPEntries[1].Name)) |
| 446 | assert.Check(t, is.Equal("https://idp2.example.com/sso", got.Scoping.IDPList.IDPEntries[1].Loc)) |
| 447 | assert.Check(t, is.Equal("https://gateway.example.com/idplist", got.Scoping.IDPList.GetComplete)) |
| 448 | assert.Check(t, is.DeepEqual([]string{"https://sp.example.com"}, got.Scoping.RequesterIDs)) |
| 449 | } |
| 450 | |
| 451 | func TestScopingElementMinimal(t *testing.T) { |
| 452 | s := Scoping{IDPList: &IDPList{IDPEntries: []IDPEntry{{ProviderID: "https://idp.example.com"}}}} |