@@ -10,6 +10,8 @@ import (
10
10
"log"
11
11
"net"
12
12
"net/http"
13
+ "net/http/cookiejar"
14
+ "net/http/httptest"
13
15
"net/netip"
14
16
"sort"
15
17
"strconv"
@@ -747,6 +749,24 @@ func (s *AuthOIDCScenario) runMockOIDC(accessTTL time.Duration, users []mockoidc
747
749
}, nil
748
750
}
749
751
752
+ type LoggingRoundTripper struct {}
753
+
754
+ func (t LoggingRoundTripper ) RoundTrip (req * http.Request ) (* http.Response , error ) {
755
+ noTls := & http.Transport {
756
+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true }, // nolint
757
+ }
758
+ resp , err := noTls .RoundTrip (req )
759
+ if err != nil {
760
+ return nil , err
761
+ }
762
+
763
+ log .Printf ("---" )
764
+ log .Printf ("method: %s | url: %s" , resp .Request .Method , resp .Request .URL .String ())
765
+ log .Printf ("status: %d | cookies: %+v" , resp .StatusCode , resp .Cookies ())
766
+
767
+ return resp , nil
768
+ }
769
+
750
770
func (s * AuthOIDCScenario ) runTailscaleUp (
751
771
userStr , loginServer string ,
752
772
) error {
@@ -758,44 +778,50 @@ func (s *AuthOIDCScenario) runTailscaleUp(
758
778
log .Printf ("running tailscale up for user %s" , userStr )
759
779
if user , ok := s .users [userStr ]; ok {
760
780
for _ , client := range user .Clients {
761
- c := client
781
+ tsc := client
762
782
user .joinWaitGroup .Go (func () error {
763
- loginURL , err := c .LoginWithURL (loginServer )
783
+ loginURL , err := tsc .LoginWithURL (loginServer )
764
784
if err != nil {
765
- log .Printf ("%s failed to run tailscale up: %s" , c .Hostname (), err )
785
+ log .Printf ("%s failed to run tailscale up: %s" , tsc .Hostname (), err )
766
786
}
767
787
768
- loginURL .Host = fmt .Sprintf ("%s:8080" , headscale .GetIP ())
788
+ loginURL .Host = fmt .Sprintf ("%s:8080" , headscale .GetHostname ())
769
789
loginURL .Scheme = "http"
770
790
771
791
if len (headscale .GetCert ()) > 0 {
772
792
loginURL .Scheme = "https"
773
793
}
774
794
775
- insecureTransport := & http.Transport {
776
- TLSClientConfig : & tls.Config {InsecureSkipVerify : true }, // nolint
795
+ httptest .NewRecorder ()
796
+ hc := & http.Client {
797
+ Transport : LoggingRoundTripper {},
798
+ }
799
+ hc .Jar , err = cookiejar .New (nil )
800
+ if err != nil {
801
+ log .Printf ("failed to create cookie jar: %s" , err )
777
802
}
778
803
779
- log .Printf ("%s login url: %s\n " , c .Hostname (), loginURL .String ())
804
+ log .Printf ("%s login url: %s\n " , tsc .Hostname (), loginURL .String ())
780
805
781
- log .Printf ("%s logging in with url" , c .Hostname ())
782
- httpClient := & http.Client {Transport : insecureTransport }
806
+ log .Printf ("%s logging in with url" , tsc .Hostname ())
783
807
ctx := context .Background ()
784
808
req , _ := http .NewRequestWithContext (ctx , http .MethodGet , loginURL .String (), nil )
785
- resp , err := httpClient .Do (req )
809
+ resp , err := hc .Do (req )
786
810
if err != nil {
787
811
log .Printf (
788
812
"%s failed to login using url %s: %s" ,
789
- c .Hostname (),
813
+ tsc .Hostname (),
790
814
loginURL ,
791
815
err ,
792
816
)
793
817
794
818
return err
795
819
}
796
820
821
+ log .Printf ("cookies: %+v" , hc .Jar .Cookies (loginURL ))
822
+
797
823
if resp .StatusCode != http .StatusOK {
798
- log .Printf ("%s response code of oidc login request was %s" , c .Hostname (), resp .Status )
824
+ log .Printf ("%s response code of oidc login request was %s" , tsc .Hostname (), resp .Status )
799
825
body , _ := io .ReadAll (resp .Body )
800
826
log .Printf ("body: %s" , body )
801
827
@@ -806,12 +832,12 @@ func (s *AuthOIDCScenario) runTailscaleUp(
806
832
807
833
_ , err = io .ReadAll (resp .Body )
808
834
if err != nil {
809
- log .Printf ("%s failed to read response body: %s" , c .Hostname (), err )
835
+ log .Printf ("%s failed to read response body: %s" , tsc .Hostname (), err )
810
836
811
837
return err
812
838
}
813
839
814
- log .Printf ("Finished request for %s to join tailnet" , c .Hostname ())
840
+ log .Printf ("Finished request for %s to join tailnet" , tsc .Hostname ())
815
841
return nil
816
842
})
817
843
0 commit comments