@@ -102,6 +102,8 @@ type TestInputs struct {
102
102
CurvePreferences []tls.CurveID
103
103
Username string
104
104
Password string
105
+ Token string
106
+ Authorization string // Raw authorization
105
107
ClientCertificate string
106
108
}
107
109
@@ -516,6 +518,12 @@ func (test *TestInputs) Test(t *testing.T) {
516
518
if test .Username != "" {
517
519
req .SetBasicAuth (test .Username , test .Password )
518
520
}
521
+ if test .Token != "" {
522
+ req .Header .Set ("Authorization" , "Bearer " + test .Token )
523
+ }
524
+ if test .Authorization != "" {
525
+ req .Header .Set ("Authorization" , test .Authorization )
526
+ }
519
527
return client .Do (req )
520
528
}
521
529
go func () {
@@ -698,3 +706,93 @@ func TestUsers(t *testing.T) {
698
706
t .Run (testInputs .Name , testInputs .Test )
699
707
}
700
708
}
709
+
710
+ func TestTokens (t * testing.T ) {
711
+ testTables := []* TestInputs {
712
+ {
713
+ Name : `with correct token` ,
714
+ YAMLConfigPath : "testdata/web_config_tokens_noTLS.good.yml" ,
715
+ Token : "TokenTest12345" ,
716
+ ExpectedError : nil ,
717
+ },
718
+ {
719
+ Name : `with incorrect token` ,
720
+ YAMLConfigPath : "testdata/web_config_tokens_noTLS.good.yml" ,
721
+ Token : "TokenTest12345" ,
722
+ ExpectedError : nil ,
723
+ },
724
+ {
725
+ Name : `without token and TLS` ,
726
+ YAMLConfigPath : "testdata/web_config_tokens.good.yml" ,
727
+ UseTLSClient : true ,
728
+ ExpectedError : ErrorMap ["Unauthorized" ],
729
+ },
730
+ {
731
+ Name : `with correct token and TLS` ,
732
+ YAMLConfigPath : "testdata/web_config_tokens.good.yml" ,
733
+ UseTLSClient : true ,
734
+ Token : "TokenTest12345" ,
735
+ ExpectedError : nil ,
736
+ },
737
+ {
738
+ Name : `with incorrect token and TLS` ,
739
+ YAMLConfigPath : "testdata/web_config_tokens.good.yml" ,
740
+ UseTLSClient : true ,
741
+ Token : "nonexistent" ,
742
+ ExpectedError : ErrorMap ["Unauthorized" ],
743
+ },
744
+ }
745
+ for _ , testInputs := range testTables {
746
+ t .Run (testInputs .Name , testInputs .Test )
747
+ }
748
+ }
749
+
750
+ func TestRawAuthorization (t * testing.T ) {
751
+ testTables := []* TestInputs {
752
+ {
753
+ Name : `with raw authorization vs expected user` ,
754
+ YAMLConfigPath : "testdata/web_config_users_noTLS.good.yml" ,
755
+ Authorization : "FakeAuth FakeAuthMagic12345" ,
756
+ UseTLSClient : false ,
757
+ ExpectedError : ErrorMap ["Unauthorized" ],
758
+ },
759
+ {
760
+ Name : `with raw authorization and TLS vs expected user` ,
761
+ YAMLConfigPath : "testdata/web_config_users.good.yml" ,
762
+ Authorization : "FakeAuth FakeAuthMagic12345" ,
763
+ UseTLSClient : true ,
764
+ ExpectedError : ErrorMap ["Unauthorized" ],
765
+ },
766
+ {
767
+ Name : `with raw authorization vs expected token` ,
768
+ YAMLConfigPath : "testdata/web_config_tokens_noTLS.good.yml" ,
769
+ Authorization : "FakeAuth FakeAuthMagic12345" ,
770
+ UseTLSClient : false ,
771
+ ExpectedError : ErrorMap ["Unauthorized" ],
772
+ },
773
+ {
774
+ Name : `with raw authorization and TLS vs expected token` ,
775
+ YAMLConfigPath : "testdata/web_config_tokens.good.yml" ,
776
+ Authorization : "FakeAuth FakeAuthMagic12345" ,
777
+ UseTLSClient : true ,
778
+ ExpectedError : ErrorMap ["Unauthorized" ],
779
+ },
780
+ {
781
+ Name : `with raw authorization vs no auth expected` ,
782
+ YAMLConfigPath : "testdata/web_config_noAuth.good.yml" ,
783
+ Authorization : "FakeAuth FakeAuthMagic12345" ,
784
+ UseTLSClient : true ,
785
+ ExpectedError : nil ,
786
+ },
787
+ {
788
+ Name : `with raw authorization, no TLS, vs no auth expected` ,
789
+ YAMLConfigPath : "testdata/web_config_empty.yml" ,
790
+ Authorization : "FakeAuth FakeAuthMagic12345" ,
791
+ UseTLSClient : false ,
792
+ ExpectedError : nil ,
793
+ },
794
+ }
795
+ for _ , testInputs := range testTables {
796
+ t .Run (testInputs .Name , testInputs .Test )
797
+ }
798
+ }
0 commit comments