Skip to content

Commit

Permalink
MM-19864 Implement Scoping Element for AD/LDAP (#1)
Browse files Browse the repository at this point in the history
* Implement Scoping Element for AD/LDAP

* Add tests for omitting ScopingIDProvider
  • Loading branch information
sbishel authored and srkgupta committed Nov 19, 2019
1 parent 2506a07 commit 8380e0f
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 21 deletions.
2 changes: 1 addition & 1 deletion attribute.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package saml2

import "github.com/russellhaering/gosaml2/types"
import "github.com/mattermost/gosaml2/types"

// Values is a convenience wrapper for a map of strings to Attributes, which
// can be used for easy access to the string values of Attribute lists.
Expand Down
10 changes: 9 additions & 1 deletion build_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/url"

"github.com/beevik/etree"
"github.com/russellhaering/gosaml2/uuid"
"github.com/mattermost/gosaml2/uuid"
)

const issueInstantFormat = "2006-01-02T15:04:05Z"
Expand Down Expand Up @@ -55,6 +55,14 @@ func (sp *SAMLServiceProvider) buildAuthnRequest(includeSig bool) (*etree.Docume
}
}

if sp.ScopingIDPProviderId != "" && sp.ScopingIDPProviderName != "" {
scoping := authnRequest.CreateElement("samlp:Scoping")
idpList := scoping.CreateElement("samlp:IDPList")
idpEntry := idpList.CreateElement("samlp:IDPEntry")
idpEntry.CreateAttr("ProviderID", sp.ScopingIDPProviderId)
idpEntry.CreateAttr("Name", sp.ScopingIDPProviderName)
}

doc := etree.NewDocument()

// Only POST binding includes <Signature> in <AuthnRequest> (includeSig)
Expand Down
60 changes: 60 additions & 0 deletions build_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,63 @@ func TestRequestedAuthnContextIncluded(t *testing.T) {
require.Equal(t, el.Tag, "AuthnContextClassRef")
require.Equal(t, el.Text(), AuthnContextPasswordProtectedTransport)
}

func TestScopingIDProviderIncluded(t *testing.T) {
spURL := "https://sp.test"
sp := SAMLServiceProvider{
AssertionConsumerServiceURL: spURL,
AudienceURI: spURL,
IdentityProviderIssuer: spURL,
IdentityProviderSSOURL: "https://idp.test/saml/sso",
SignAuthnRequests: false,
ScopingIDPProviderId: "providerID",
ScopingIDPProviderName: "providerName",
}

request, err := sp.BuildAuthRequest()
require.NoError(t, err)

doc := etree.NewDocument()
err = doc.ReadFromString(request)
require.NoError(t, err)

idpEntry := doc.FindElement("./AuthnRequest/Scoping/IDPList/IDPEntry")

require.Equal(t, idpEntry.SelectAttrValue("ProviderID", ""), "providerID")
require.Equal(t, idpEntry.SelectAttrValue("Name", ""), "providerName")
}

func TestScopingIDProviderOmitted(t *testing.T) {
spURL := "https://sp.test"

cases := []struct {
ScopingIDPProviderId string
ScopingIDPProviderName string
}{
{"", ""},
{"", "providerName"},
{"providerId", ""},
}

for _, tc := range cases {
sp := SAMLServiceProvider{
AssertionConsumerServiceURL: spURL,
AudienceURI: spURL,
IdentityProviderIssuer: spURL,
IdentityProviderSSOURL: "https://idp.test/saml/sso",
SignAuthnRequests: false,
ScopingIDPProviderId: tc.ScopingIDPProviderId,
ScopingIDPProviderName: tc.ScopingIDPProviderName,
}

request, err := sp.BuildAuthRequest()
require.NoError(t, err)

doc := etree.NewDocument()
err = doc.ReadFromString(request)
require.NoError(t, err)

el := doc.FindElement("./AuthnRequest/Scoping")
require.Nil(t, el)
}
}
2 changes: 1 addition & 1 deletion decode_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"encoding/xml"

"github.com/beevik/etree"
"github.com/russellhaering/gosaml2/types"
"github.com/mattermost/gosaml2/types"
dsig "github.com/russellhaering/goxmldsig"
"github.com/russellhaering/goxmldsig/etreeutils"
)
Expand Down
2 changes: 1 addition & 1 deletion providertests/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package providertests
import (
"testing"

saml2 "github.com/russellhaering/gosaml2"
saml2 "github.com/mattermost/gosaml2"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion providertests/exercise_go_1_6.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package providertests
import (
"testing"

saml2 "github.com/russellhaering/gosaml2"
saml2 "github.com/mattermost/gosaml2"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions providertests/oktadev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"time"

"github.com/jonboulle/clockwork"
"github.com/russellhaering/gosaml2"
"github.com/russellhaering/goxmldsig"
saml2 "github.com/mattermost/gosaml2"
dsig "github.com/russellhaering/goxmldsig"
)

var oktaScenarioErrors = map[int]string{
Expand Down
2 changes: 1 addition & 1 deletion providertests/onelogin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/russellhaering/gosaml2"
saml2 "github.com/mattermost/gosaml2"
)

var oneLoginScenarioErrors = map[int]string{
Expand Down
2 changes: 1 addition & 1 deletion providertests/pingfed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/russellhaering/gosaml2"
saml2 "github.com/mattermost/gosaml2"
)

var pingFedScenarioErrors = map[int]string{
Expand Down
8 changes: 4 additions & 4 deletions providertests/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"time"

"github.com/jonboulle/clockwork"
"github.com/russellhaering/gosaml2"
"github.com/russellhaering/goxmldsig"
saml2 "github.com/mattermost/gosaml2"
dsig "github.com/russellhaering/goxmldsig"
)

func TestValidateResponses(t *testing.T) {
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestValidateResponses(t *testing.T) {
AudienceURI: "{audience}",
SkipSignatureValidation: false,
AllowMissingAttributes: true,
Clock: dsig.NewFakeClock(clockwork.NewFakeClockAt(time.Date(2017, 3, 8, 7, 51, 0, 0, time.UTC))),
Clock: dsig.NewFakeClock(clockwork.NewFakeClockAt(time.Date(2017, 3, 8, 7, 51, 0, 0, time.UTC))),
},
},
{
Expand All @@ -108,7 +108,7 @@ func TestValidateResponses(t *testing.T) {
AudienceURI: "JSAuth",
SkipSignatureValidation: false,
AllowMissingAttributes: true,
Clock: dsig.NewFakeClock(clockwork.NewFakeClockAt(time.Date(2016, 12, 12, 16, 55, 0, 0, time.UTC))),
Clock: dsig.NewFakeClock(clockwork.NewFakeClockAt(time.Date(2016, 12, 12, 16, 55, 0, 0, time.UTC))),
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions providertests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"time"

"github.com/jonboulle/clockwork"
"github.com/russellhaering/gosaml2"
"github.com/russellhaering/gosaml2/types"
"github.com/russellhaering/goxmldsig"
saml2 "github.com/mattermost/gosaml2"
"github.com/mattermost/gosaml2/types"
dsig "github.com/russellhaering/goxmldsig"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions s2example/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"encoding/base64"
"encoding/xml"

saml2 "github.com/russellhaering/gosaml2"
"github.com/russellhaering/gosaml2/types"
saml2 "github.com/mattermost/gosaml2"
"github.com/mattermost/gosaml2/types"
dsig "github.com/russellhaering/goxmldsig"
)

Expand Down
4 changes: 3 additions & 1 deletion saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/russellhaering/gosaml2/types"
"github.com/mattermost/gosaml2/types"
dsig "github.com/russellhaering/goxmldsig"
dsigtypes "github.com/russellhaering/goxmldsig/types"
)
Expand Down Expand Up @@ -46,6 +46,8 @@ type SAMLServiceProvider struct {
ValidateEncryptionCert bool
SkipSignatureValidation bool
AllowMissingAttributes bool
ScopingIDPProviderId string
ScopingIDPProviderName string
Clock *dsig.Clock
signingContextMu sync.RWMutex
signingContext *dsig.SigningContext
Expand Down
2 changes: 1 addition & 1 deletion saml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"testing"

"github.com/beevik/etree"
"github.com/russellhaering/gosaml2/types"
"github.com/mattermost/gosaml2/types"
dsig "github.com/russellhaering/goxmldsig"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/russellhaering/gosaml2/types"
"github.com/mattermost/gosaml2/types"
)

//ErrParsing indicates that the value present in an assertion could not be
Expand Down

0 comments on commit 8380e0f

Please sign in to comment.