forked from RobotsAndPencils/go-saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authnrequest_test.go
74 lines (64 loc) · 2.02 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package saml
import (
"crypto/x509"
"encoding/pem"
"io/ioutil"
"os/exec"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetSignedRequest(t *testing.T) {
assert := assert.New(t)
certPem, err := ioutil.ReadFile("./default.crt")
assert.NoError(err)
certBlock, _ := pem.Decode(certPem)
assert.NotEmpty(certBlock)
cert, err := x509.ParseCertificate(certBlock.Bytes)
k, err := ioutil.ReadFile("./default.key")
assert.NoError(err)
kd, _ := pem.Decode(k)
privateKey, err := x509.ParsePKCS1PrivateKey(kd.Bytes)
assert.NoError(err)
sp := ServiceProviderConfig{
PrivateKey: privateKey,
Cert: cert,
IDPSSOURL: "http://www.onelogin.net",
IDPSSODescriptorURL: "http://www.onelogin.net",
IDPCert: cert,
AssertionConsumerServiceURL: "http://localhost:8000/auth/saml/name",
SPSignRequest: true,
}
// Construct an AuthnRequest
authnRequest, err := sp.GetAuthnRequest()
assert.NoError(err)
_, err = exec.LookPath("xmlsec1")
if err != nil {
t.Skip("skipping subsequent test since xmlsec1 is missing")
}
signedXML, err := authnRequest.SignedString(sp.PrivateKey)
assert.NoError(err)
assert.NotEmpty(signedXML)
err = VerifyRequestSignature(signedXML, sp.Cert.Raw)
assert.NoError(err)
}
func TestGetUnsignedRequest(t *testing.T) {
assert := assert.New(t)
certPem, err := ioutil.ReadFile("./default.crt")
assert.NoError(err)
certBlock, _ := pem.Decode(certPem)
assert.NotEmpty(certBlock)
cert, err := x509.ParseCertificate(certBlock.Bytes)
assert.NoError(err)
sp := ServiceProviderConfig{
Cert: cert,
IDPSSOURL: "http://www.onelogin.net",
IDPSSODescriptorURL: "http://www.onelogin.net",
IDPCert: cert,
AssertionConsumerServiceURL: "http://localhost:8000/auth/saml/name",
SPSignRequest: false,
}
// Construct an AuthnRequest
authnRequest, err := sp.GetAuthnRequest()
assert.NoError(err)
assert.NotEmpty(authnRequest)
}