@@ -28,11 +28,11 @@ import (
28
28
)
29
29
30
30
type MiddlewareTest struct {
31
- AuthnRequest string
32
- SamlResponse string
31
+ AuthnRequest [] byte
32
+ SamlResponse [] byte
33
33
Key * rsa.PrivateKey
34
34
Certificate * x509.Certificate
35
- IDPMetadata string
35
+ IDPMetadata [] byte
36
36
Middleware * Middleware
37
37
expectedSessionCookie string
38
38
}
@@ -59,14 +59,14 @@ func NewMiddlewareTest(t *testing.T) *MiddlewareTest {
59
59
saml .Clock = dsig .NewFakeClockAt (saml .TimeNow ())
60
60
saml .RandReader = & testRandomReader {}
61
61
62
- test .AuthnRequest = string ( golden .Get (t , "authn_request.url" ) )
63
- test .SamlResponse = string ( golden .Get (t , "saml_response.xml" ) )
64
- test .Key = mustParsePrivateKey (string ( golden .Get (t , "key.pem" ) )).(* rsa.PrivateKey )
65
- test .Certificate = mustParseCertificate (string ( golden .Get (t , "cert.pem" ) ))
66
- test .IDPMetadata = string ( golden .Get (t , "idp_metadata.xml" ) )
62
+ test .AuthnRequest = golden .Get (t , "authn_request.url" )
63
+ test .SamlResponse = golden .Get (t , "saml_response.xml" )
64
+ test .Key = mustParsePrivateKey (golden .Get (t , "key.pem" )).(* rsa.PrivateKey )
65
+ test .Certificate = mustParseCertificate (golden .Get (t , "cert.pem" ))
66
+ test .IDPMetadata = golden .Get (t , "idp_metadata.xml" )
67
67
68
68
var metadata saml.EntityDescriptor
69
- if err := xml .Unmarshal ([] byte ( test .IDPMetadata ) , & metadata ); err != nil {
69
+ if err := xml .Unmarshal (test .IDPMetadata , & metadata ); err != nil {
70
70
panic (err )
71
71
}
72
72
@@ -131,8 +131,7 @@ func TestMiddlewareCanProduceMetadata(t *testing.T) {
131
131
assert .Check (t , is .Equal (http .StatusOK , resp .Code ))
132
132
assert .Check (t , is .Equal ("application/samlmetadata+xml" ,
133
133
resp .Header ().Get ("Content-type" )))
134
- assert .Check (t , is .Equal (string (golden .Get (t , "expected_middleware_metadata.xml" )),
135
- resp .Body .String ()))
134
+ golden .Assert (t , resp .Body .String (), "expected_middleware_metadata.xml" )
136
135
}
137
136
138
137
func TestMiddlewareFourOhFour (t * testing.T ) {
@@ -168,8 +167,7 @@ func TestMiddlewareRequireAccountNoCreds(t *testing.T) {
168
167
assert .Check (t , err )
169
168
decodedRequest , err := testsaml .ParseRedirectRequest (redirectURL )
170
169
assert .Check (t , err )
171
- assert .Check (t , is .Equal (string (golden .Get (t , "expected_authn_request.xml" )),
172
- string (decodedRequest )))
170
+ golden .Assert (t , string (decodedRequest ), "expected_authn_request.xml" )
173
171
}
174
172
175
173
func TestMiddlewareRequireAccountNoCredsSecure (t * testing.T ) {
@@ -192,8 +190,7 @@ func TestMiddlewareRequireAccountNoCredsSecure(t *testing.T) {
192
190
assert .Check (t , err )
193
191
decodedRequest , err := testsaml .ParseRedirectRequest (redirectURL )
194
192
assert .Check (t , err )
195
- assert .Check (t , is .Equal (string (golden .Get (t , "expected_authn_request_secure.xml" )),
196
- string (decodedRequest )))
193
+ golden .Assert (t , string (decodedRequest ), "expected_authn_request_secure.xml" )
197
194
}
198
195
199
196
func TestMiddlewareRequireAccountNoCredsPostBinding (t * testing.T ) {
@@ -214,8 +211,8 @@ func TestMiddlewareRequireAccountNoCredsPostBinding(t *testing.T) {
214
211
assert .Check (t , is .Equal (http .StatusOK , resp .Code ))
215
212
assert .Check (t , is .Equal ("saml_KCosLjAyNDY4Ojw-QEJERkhKTE5QUlRWWFpcXmBiZGZoamxucHJ0dnh6=" + test .makeTrackedRequest ("id-00020406080a0c0e10121416181a1c1e20222426" )+ "; Path=/saml2/acs; Max-Age=90; HttpOnly; Secure" ,
216
213
resp .Header ().Get ("Set-Cookie" )))
217
- assert . Check ( t , is . Equal ( string ( golden . Get ( t , "expected_post_binding_response.html" )),
218
- string ( resp .Body .Bytes ())) )
214
+
215
+ golden . Assert ( t , resp .Body .String (), "expected_post_binding_response.html" )
219
216
220
217
// check that the CSP script hash is set correctly
221
218
scriptContent := "document.getElementById('SAMLSubmitButton').style.visibility=\" hidden\" ;document.getElementById('SAMLRequestForm').submit();"
@@ -279,8 +276,7 @@ func TestMiddlewareRequireAccountBadCreds(t *testing.T) {
279
276
assert .Check (t , err )
280
277
decodedRequest , err := testsaml .ParseRedirectRequest (redirectURL )
281
278
assert .Check (t , err )
282
- assert .Check (t , is .Equal (string (golden .Get (t , "expected_authn_request_secure.xml" )),
283
- string (decodedRequest )))
279
+ golden .Assert (t , string (decodedRequest ), "expected_authn_request_secure.xml" )
284
280
}
285
281
286
282
func TestMiddlewareRequireAccountExpiredCreds (t * testing.T ) {
@@ -310,8 +306,7 @@ func TestMiddlewareRequireAccountExpiredCreds(t *testing.T) {
310
306
assert .Check (t , err )
311
307
decodedRequest , err := testsaml .ParseRedirectRequest (redirectURL )
312
308
assert .Check (t , err )
313
- assert .Check (t , is .Equal (string (golden .Get (t , "expected_authn_request_secure.xml" )),
314
- string (decodedRequest )))
309
+ golden .Assert (t , string (decodedRequest ), "expected_authn_request_secure.xml" )
315
310
}
316
311
317
312
func TestMiddlewareRequireAccountPanicOnRequestToACS (t * testing.T ) {
@@ -401,7 +396,7 @@ func TestMiddlewareRequireAttributeMissingAccount(t *testing.T) {
401
396
func TestMiddlewareCanParseResponse (t * testing.T ) {
402
397
test := NewMiddlewareTest (t )
403
398
v := & url.Values {}
404
- v .Set ("SAMLResponse" , base64 .StdEncoding .EncodeToString ([] byte ( test .SamlResponse ) ))
399
+ v .Set ("SAMLResponse" , base64 .StdEncoding .EncodeToString (test .SamlResponse ))
405
400
v .Set ("RelayState" , "KCosLjAyNDY4Ojw-QEJERkhKTE5QUlRWWFpcXmBiZGZoamxucHJ0dnh6" )
406
401
req , _ := http .NewRequest ("POST" , "/saml2/acs" , bytes .NewReader ([]byte (v .Encode ())))
407
402
req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
@@ -466,7 +461,7 @@ func TestMiddlewareRejectsInvalidRelayState(t *testing.T) {
466
461
}
467
462
468
463
v := & url.Values {}
469
- v .Set ("SAMLResponse" , base64 .StdEncoding .EncodeToString ([] byte ( test .SamlResponse ) ))
464
+ v .Set ("SAMLResponse" , base64 .StdEncoding .EncodeToString (test .SamlResponse ))
470
465
v .Set ("RelayState" , "ICIkJigqLC4wMjQ2ODo8PkBCREZISkxOUFJUVlhaXF5gYmRmaGpsbnBy" )
471
466
req , _ := http .NewRequest ("POST" , "/saml2/acs" , bytes .NewReader ([]byte (v .Encode ())))
472
467
req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
@@ -489,7 +484,7 @@ func TestMiddlewareRejectsInvalidCookie(t *testing.T) {
489
484
}
490
485
491
486
v := & url.Values {}
492
- v .Set ("SAMLResponse" , base64 .StdEncoding .EncodeToString ([] byte ( test .SamlResponse ) ))
487
+ v .Set ("SAMLResponse" , base64 .StdEncoding .EncodeToString (test .SamlResponse ))
493
488
v .Set ("RelayState" , "KCosLjAyNDY4Ojw-QEJERkhKTE5QUlRWWFpcXmBiZGZoamxucHJ0dnh6" )
494
489
req , _ := http .NewRequest ("POST" , "/saml2/acs" , bytes .NewReader ([]byte (v .Encode ())))
495
490
req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
0 commit comments