4
4
"bytes"
5
5
"context"
6
6
"crypto/rand"
7
+ "crypto/tls"
7
8
"math/big"
8
9
"net"
9
10
"net/http"
@@ -25,6 +26,7 @@ import (
25
26
. "github.com/onsi/ginkgo/v2" //nolint:revive //we want to use it for ginkgo
26
27
. "github.com/onsi/gomega" //nolint:revive //we want to use it for gomega
27
28
"github.com/pquerna/otp/totp"
29
+ "golang.org/x/oauth2"
28
30
"golang.org/x/oauth2/clientcredentials"
29
31
)
30
32
@@ -43,8 +45,9 @@ const (
43
45
//nolint:gosec
44
46
loaTestClientSecret = "4z9PoOooXNFmSCPZx0xHXaUxX4eYGFO0"
45
47
timeout = time .Second * 300
46
- idpURI = "http://localhost:8081"
47
- localURI = "http://localhost:"
48
+ idpURI = "https://localhost:8443"
49
+ localURI = "https://localhost:"
50
+ httpLocalURI = "http://localhost:"
48
51
logoutURI = "/oauth" + constant .LogoutURL
49
52
registerURI = "/oauth" + constant .RegistrationURL
50
53
allInterfaces = "0.0.0.0:"
@@ -71,6 +74,50 @@ const (
71
74
pkceCookieName = "TESTPKCECOOKIE"
72
75
umaCookieName = "TESTUMACOOKIE"
73
76
idpRealmURI = idpURI + "/realms/" + testRealm
77
+ //nolint:gosec
78
+ fakePrivateKey = `
79
+ -----BEGIN EC PRIVATE KEY-----
80
+ MHcCAQEEIA0wan+Hp0gsbyyZnN/Q8PzaQirGJYBA9g0UT9WIbnl/oAoGCCqGSM49
81
+ AwEHoUQDQgAEzYuh8kValY9VN7IGdf1o3u7nt57SFCkpgTx7Dt6s/5FxLBih7Z8v
82
+ /6xWYMy1DZ/ftmKhzLdWGBw3/KFTZFW/uQ==
83
+ -----END EC PRIVATE KEY-----
84
+ `
85
+
86
+ fakeCert = `
87
+ -----BEGIN CERTIFICATE-----
88
+ MIIChzCCAi6gAwIBAgIUdNo4UjE80CwFpuB9OabwJfdQx20wCgYIKoZIzj0EAwIw
89
+ eDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBg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FdpZGdldHMsIEluYy4xDDAK
110
+ BgNVBAsTA1dXVzENMAsGA1UEAxMEdGVzdDAeFw0yNTA1MDcyMTUwMDBaFw0zNTA1
111
+ MDUyMTUwMDBaMHgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYw
112
+ FAYDVQQHEw1TYW4gRnJhbmNpc2NvMR8wHQYDVQQKExZJbnRlcm5ldCBXaWRnZXRz
113
+ LCBJbmMuMQwwCgYDVQQLEwNXV1cxDTALBgNVBAMTBHRlc3QwWTATBgcqhkjOPQIB
114
+ BggqhkjOPQMBBwNCAAShk6FOk8ELcojDxVTk/nS2ptKHxtfUPOBVVnxDPgTsSbgU
115
+ i76r16K/GMbQxZ9uLxThdyBE/+zhkEsWZsS7u8roo0IwQDAOBgNVHQ8BAf8EBAMC
116
+ AQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUbpJPTaf4qmNj18IVY2FOVtI7
117
+ 8ZkwCgYIKoZIzj0EAwIDSQAwRgIhAPvq07H/TSu1O6+v4rQR2fBnAoDsGive2scI
118
+ OXGLqAOiAiEA6lFfgFB7AhvaYy1VL5vN10FGBvqg2VWBWdAyIcFlP7k=
119
+ -----END CERTIFICATE-----
120
+ `
74
121
)
75
122
76
123
func generateRandomPort () (string , error ) {
@@ -187,7 +234,8 @@ var _ = Describe("NoRedirects Simple login/logout", func() {
187
234
osArgs := []string {os .Args [0 ]}
188
235
proxyArgs := []string {
189
236
"--discovery-url=" + idpRealmURI ,
190
- "--openid-provider-timeout=120s" ,
237
+ "--openid-provider-timeout=300s" ,
238
+ "--skip-openid-provider-tls-verify=true" ,
191
239
"--listen=" + allInterfaces + portNum ,
192
240
"--client-id=" + testClient ,
193
241
"--client-secret=" + testClientSecret ,
@@ -199,6 +247,9 @@ var _ = Describe("NoRedirects Simple login/logout", func() {
199
247
"--openid-provider-retry-count=30" ,
200
248
"--enable-encrypted-token=false" ,
201
249
"--enable-pkce=false" ,
250
+ "--tls-cert=" + tlsCertificate ,
251
+ "--tls-private-key=" + tlsPrivateKey ,
252
+ "--tls-ca-certificate=" + tlsCaCertificate ,
202
253
}
203
254
204
255
osArgs = append (osArgs , proxyArgs ... )
@@ -217,16 +268,27 @@ var _ = Describe("NoRedirects Simple login/logout", func() {
217
268
TokenURL : idpRealmURI + constant .IdpTokenURI ,
218
269
}
219
270
220
- respToken , err := conf .Token (ctx )
271
+ rClient := resty .New ()
272
+ hClient := rClient .SetTLSClientConfig (
273
+ & tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 }).GetClient ()
274
+ oidcLibCtx := context .WithValue (ctx , oauth2 .HTTPClient , hClient )
275
+
276
+ respToken , err := conf .Token (oidcLibCtx )
221
277
Expect (err ).NotTo (HaveOccurred ())
222
278
223
- request := resty .New ().SetRedirectPolicy (
279
+ rClient = resty .New ()
280
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
281
+
282
+ request := rClient .SetRedirectPolicy (
224
283
resty .NoRedirectPolicy ()).R ().SetAuthToken (respToken .AccessToken )
225
284
resp , err := request .Get (proxyAddress )
226
285
Expect (err ).NotTo (HaveOccurred ())
227
286
Expect (resp .StatusCode ()).To (Equal (http .StatusOK ))
228
287
229
- request = resty .New ().R ().SetAuthToken (respToken .AccessToken )
288
+ rClient = resty .New ()
289
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
290
+
291
+ request = rClient .R ().SetAuthToken (respToken .AccessToken )
230
292
resp , err = request .Get (proxyAddress + logoutURI )
231
293
Expect (err ).NotTo (HaveOccurred ())
232
294
Expect (resp .StatusCode ()).To (Equal (http .StatusOK ))
@@ -249,7 +311,8 @@ var _ = Describe("Code Flow login/logout", func() {
249
311
osArgs := []string {os .Args [0 ]}
250
312
proxyArgs := []string {
251
313
"--discovery-url=" + idpRealmURI ,
252
- "--openid-provider-timeout=120s" ,
314
+ "--openid-provider-timeout=300s" ,
315
+ "--skip-openid-provider-tls-verify=true" ,
253
316
"--listen=" + allInterfaces + portNum ,
254
317
"--client-id=" + testClient ,
255
318
"--client-secret=" + testClientSecret ,
@@ -268,6 +331,9 @@ var _ = Describe("Code Flow login/logout", func() {
268
331
"--enable-register-handler=true" ,
269
332
"--enable-encrypted-token=false" ,
270
333
"--enable-pkce=false" ,
334
+ "--tls-cert=" + tlsCertificate ,
335
+ "--tls-private-key=" + tlsPrivateKey ,
336
+ "--tls-ca-certificate=" + tlsCaCertificate ,
271
337
}
272
338
273
339
osArgs = append (osArgs , proxyArgs ... )
@@ -281,6 +347,7 @@ var _ = Describe("Code Flow login/logout", func() {
281
347
func (_ context.Context ) {
282
348
var err error
283
349
rClient := resty .New ()
350
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
284
351
resp := codeFlowLogin (rClient , proxyAddress , http .StatusOK , testUser , testPass )
285
352
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
286
353
body := resp .Body ()
@@ -345,6 +412,7 @@ var _ = Describe("Code Flow login/logout", func() {
345
412
func (_ context.Context ) {
346
413
var err error
347
414
rClient := resty .New ()
415
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
348
416
resp := codeFlowLogin (rClient , proxyAddress , http .StatusOK , testUser , testPass )
349
417
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
350
418
body := resp .Body ()
@@ -388,6 +456,7 @@ var _ = Describe("Code Flow login/logout", func() {
388
456
func (_ context.Context ) {
389
457
var err error
390
458
rClient := resty .New ()
459
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
391
460
reqAddress := proxyAddress + registerURI
392
461
resp := registerLogin (rClient , reqAddress , http .StatusOK , testRegisterUser , testRegisterPass )
393
462
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
@@ -459,7 +528,8 @@ var _ = Describe("Code Flow PKCE login/logout", func() {
459
528
osArgs := []string {os .Args [0 ]}
460
529
proxyArgs := []string {
461
530
"--discovery-url=" + idpRealmURI ,
462
- "--openid-provider-timeout=120s" ,
531
+ "--openid-provider-timeout=300s" ,
532
+ "--skip-openid-provider-tls-verify=true" ,
463
533
"--listen=" + allInterfaces + portNum ,
464
534
"--client-id=" + pkceTestClient ,
465
535
"--client-secret=" + pkceTestClientSecret ,
@@ -472,6 +542,9 @@ var _ = Describe("Code Flow PKCE login/logout", func() {
472
542
"--enable-pkce=true" ,
473
543
"--cookie-pkce-name=" + pkceCookieName ,
474
544
"--enable-encrypted-token=false" ,
545
+ "--tls-cert=" + tlsCertificate ,
546
+ "--tls-private-key=" + tlsPrivateKey ,
547
+ "--tls-ca-certificate=" + tlsCaCertificate ,
475
548
}
476
549
477
550
osArgs = append (osArgs , proxyArgs ... )
@@ -485,6 +558,8 @@ var _ = Describe("Code Flow PKCE login/logout", func() {
485
558
func (_ context.Context ) {
486
559
var err error
487
560
rClient := resty .New ()
561
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
562
+
488
563
resp := codeFlowLogin (rClient , proxyAddress , http .StatusOK , testUser , testPass )
489
564
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
490
565
@@ -513,12 +588,13 @@ var _ = Describe("Code Flow login/logout with session check", func() {
513
588
server := httptest .NewServer (& testsuite_test.FakeUpstreamService {})
514
589
portNum , err = generateRandomPort ()
515
590
Expect (err ).NotTo (HaveOccurred ())
516
- proxyAddressFirst = "http ://127.0.0.1:" + portNum
591
+ proxyAddressFirst = "https ://127.0.0.1:" + portNum
517
592
518
593
osArgs := []string {os .Args [0 ]}
519
594
proxyArgs := []string {
520
595
"--discovery-url=" + idpRealmURI ,
521
- "--openid-provider-timeout=120s" ,
596
+ "--openid-provider-timeout=300s" ,
597
+ "--skip-openid-provider-tls-verify=true" ,
522
598
"--listen=" + allInterfaces + portNum ,
523
599
"--client-id=" + testClient ,
524
600
"--client-secret=" + testClientSecret ,
@@ -534,6 +610,9 @@ var _ = Describe("Code Flow login/logout with session check", func() {
534
610
"--post-logout-redirect-uri=http://google.com" ,
535
611
"--enable-encrypted-token=false" ,
536
612
"--enable-pkce=false" ,
613
+ "--tls-cert=" + tlsCertificate ,
614
+ "--tls-private-key=" + tlsPrivateKey ,
615
+ "--tls-ca-certificate=" + tlsCaCertificate ,
537
616
}
538
617
539
618
osArgs = append (osArgs , proxyArgs ... )
@@ -545,7 +624,8 @@ var _ = Describe("Code Flow login/logout with session check", func() {
545
624
osArgs = []string {os .Args [0 ]}
546
625
proxyArgs = []string {
547
626
"--discovery-url=" + idpRealmURI ,
548
- "--openid-provider-timeout=120s" ,
627
+ "--openid-provider-timeout=300s" ,
628
+ "--skip-openid-provider-tls-verify=true" ,
549
629
"--listen=" + allInterfaces + portNum ,
550
630
"--client-id=" + pkceTestClient ,
551
631
"--client-secret=" + pkceTestClientSecret ,
@@ -562,6 +642,9 @@ var _ = Describe("Code Flow login/logout with session check", func() {
562
642
"--enable-id-token-cookie=true" ,
563
643
"--post-logout-redirect-uri=http://google.com" ,
564
644
"--enable-encrypted-token=false" ,
645
+ "--tls-cert=" + tlsCertificate ,
646
+ "--tls-private-key=" + tlsPrivateKey ,
647
+ "--tls-ca-certificate=" + tlsCaCertificate ,
565
648
}
566
649
567
650
osArgs = append (osArgs , proxyArgs ... )
@@ -572,6 +655,7 @@ var _ = Describe("Code Flow login/logout with session check", func() {
572
655
It ("should logout on both successfully" , func (_ context.Context ) {
573
656
var err error
574
657
rClient := resty .New ()
658
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
575
659
resp := codeFlowLogin (rClient , proxyAddressFirst , http .StatusOK , testUser , testPass )
576
660
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
577
661
resp = codeFlowLogin (rClient , proxyAddressSec , http .StatusOK , testUser , testPass )
@@ -620,7 +704,8 @@ var _ = Describe("Level Of Authentication Code Flow login/logout", func() {
620
704
osArgs := []string {os .Args [0 ]}
621
705
proxyArgs := []string {
622
706
"--discovery-url=" + idpRealmURI ,
623
- "--openid-provider-timeout=120s" ,
707
+ "--openid-provider-timeout=300s" ,
708
+ "--skip-openid-provider-tls-verify=true" ,
624
709
"--listen=" + allInterfaces + portNum ,
625
710
"--client-id=" + loaTestClient ,
626
711
"--client-secret=" + loaTestClientSecret ,
@@ -641,6 +726,9 @@ var _ = Describe("Level Of Authentication Code Flow login/logout", func() {
641
726
"--post-login-redirect-path=" + postLoginRedirectPath ,
642
727
"--enable-encrypted-token=false" ,
643
728
"--enable-pkce=false" ,
729
+ "--tls-cert=" + tlsCertificate ,
730
+ "--tls-private-key=" + tlsPrivateKey ,
731
+ "--tls-ca-certificate=" + tlsCaCertificate ,
644
732
}
645
733
646
734
osArgs = append (osArgs , proxyArgs ... )
@@ -655,6 +743,7 @@ var _ = Describe("Level Of Authentication Code Flow login/logout", func() {
655
743
func (_ context.Context ) {
656
744
var err error
657
745
rClient := resty .New ()
746
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
658
747
resp := codeFlowLogin (rClient , proxyAddress , http .StatusOK , testLoAUser , testLoAPass )
659
748
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
660
749
body := resp .Body ()
@@ -728,6 +817,7 @@ var _ = Describe("Level Of Authentication Code Flow login/logout", func() {
728
817
func (_ context.Context ) {
729
818
var err error
730
819
rClient := resty .New ()
820
+ rClient .SetTLSClientConfig (& tls.Config {RootCAs : caPool , MinVersion : tls .VersionTLS13 })
731
821
resp := codeFlowLogin (rClient , proxyAddress , http .StatusOK , testLoAUser , testLoAPass )
732
822
Expect (resp .Header ().Get ("Proxy-Accepted" )).To (Equal ("true" ))
733
823
body := resp .Body ()
0 commit comments