forked from RobotsAndPencils/go-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authnrequest_test.go
49 lines (42 loc) · 1.36 KB
/
authnrequest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package saml
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetSignedRequest(t *testing.T) {
assert := assert.New(t)
sp := ServiceProviderSettings{
PublicCertPath: "./default.crt",
PrivateKeyPath: "./default.key",
IDPSSOURL: "http://www.onelogin.net",
IDPSSODescriptorURL: "http://www.onelogin.net",
IDPPublicCertPath: "./default.crt",
AssertionConsumerServiceURL: "http://localhost:8000/auth/saml/name",
SPSignRequest: true,
}
err := sp.Init()
assert.NoError(err)
// Construct an AuthnRequest
authnRequest := sp.GetAuthnRequest()
signedXML, err := authnRequest.SignedString(sp.PrivateKeyPath)
assert.NoError(err)
assert.NotEmpty(signedXML)
err = VerifyRequestSignature(signedXML, sp.PublicCertPath)
assert.NoError(err)
}
func TestGetUnsignedRequest(t *testing.T) {
assert := assert.New(t)
sp := ServiceProviderSettings{
IDPSSOURL: "http://www.onelogin.net",
IDPSSODescriptorURL: "http://www.onelogin.net",
IDPPublicCertPath: "./default.crt",
AssertionConsumerServiceURL: "http://localhost:8000/auth/saml/name",
SPSignRequest: false,
}
err := sp.Init()
assert.NoError(err)
// Construct an AuthnRequest
authnRequest := sp.GetAuthnRequest()
assert.NoError(err)
assert.NotEmpty(authnRequest)
}