@@ -233,6 +233,30 @@ func TestHandler(t *testing.T) {
233233 true ,
234234 true ,
235235 },
236+ {
237+ "with short-url" ,
238+ func () config.Config {
239+ conf := config .Defaults
240+ conf .HTTP .Secret = testutils .Secret
241+ conf .HTTP .ShortURL = true
242+ conf .OAuth2 .Provider = generic .Name
243+ conf .OAuth2 .Endpoints = config.OAuth2Endpoints {}
244+ conf .OAuth2 .Scopes = []string {oauth2types .ScopeOpenID , oauth2types .ScopeProfile }
245+ conf .OAuth2 .Validate .Groups = make ([]string , 0 )
246+ conf .OAuth2 .Validate .Roles = make ([]string , 0 )
247+ conf .OAuth2 .Validate .Issuer = true
248+ conf .OAuth2 .Validate .IPAddr = false
249+ conf .OpenVPN .Bypass .CommonNames = make (types.RegexpSlice , 0 )
250+ conf .OpenVPN .AuthTokenUser = true
251+
252+ return conf
253+ }(),
254+ state .New (state.ClientIdentifier {CID : 0 , KID : 1 , CommonName : "name" }, "127.0.0.1" , "12345" , "" ),
255+ false ,
256+ "" ,
257+ true ,
258+ true ,
259+ },
236260 {
237261 "with ipaddr + forwarded-for" ,
238262 func () config.Config {
@@ -429,6 +453,10 @@ func TestHandler(t *testing.T) {
429453
430454 conf , openVPNClient , managementInterface , _ , httpClientListener , httpClient , logger := testutils .SetupMockEnvironment (ctx , t , tc .conf , nil , nil )
431455
456+ httpClient .CheckRedirect = func (_ * http.Request , _ []* http.Request ) error {
457+ return http .ErrUseLastResponse
458+ }
459+
432460 managementInterfaceConn , errOpenVPNClientCh , err := testutils .ConnectToManagementInterface (t , managementInterface , openVPNClient )
433461 require .NoError (t , err )
434462
@@ -477,23 +505,44 @@ func TestHandler(t *testing.T) {
477505 case tc .state == (state.State {}):
478506 session = ""
479507 default :
480- session , err = tc .state .Encode (tc . conf .HTTP .Secret .String ())
508+ session , err = tc .state .Encode (conf .HTTP .Secret .String ())
481509 require .NoError (t , err )
482510 }
483511
512+ urlPath := "/oauth2/start?state="
513+ if conf .HTTP .ShortURL {
514+ urlPath = "/?s="
515+ }
516+
484517 request , err = http .NewRequestWithContext (t .Context (), http .MethodGet ,
485- fmt .Sprintf ("%s/oauth2/start?state=%s " , httpClientListener .URL , session ),
518+ fmt .Sprintf ("%s%s%s " , httpClientListener .URL , urlPath , session ),
486519 nil ,
487520 )
488521
489522 require .NoError (t , err )
490523
491- if tc .xForwardedFor != "" {
492- request .Header .Set ("X-Forwarded-For" , tc .xForwardedFor )
524+ if conf .HTTP .ShortURL {
525+ resp , err = httpClient .Do (request ) //nolint:bodyclose
526+ require .NoError (t , err )
527+
528+ _ , err = io .Copy (io .Discard , resp .Body )
529+ require .NoError (t , err )
530+
531+ err = resp .Body .Close ()
532+ require .NoError (t , err )
533+
534+ require .Equal (t , http .StatusFound , resp .StatusCode )
535+ require .NotEmpty (t , resp .Header .Get ("Location" ))
536+
537+ request , err = http .NewRequestWithContext (t .Context (), http .MethodGet ,
538+ httpClientListener .URL + resp .Header .Get ("Location" ),
539+ nil ,
540+ )
541+ require .NoError (t , err )
493542 }
494543
495- httpClient . CheckRedirect = func ( _ * http. Request , _ [] * http. Request ) error {
496- return http . ErrUseLastResponse
544+ if tc . xForwardedFor != "" {
545+ request . Header . Set ( "X-Forwarded-For" , tc . xForwardedFor )
497546 }
498547
499548 reqErrCh := make (chan error , 1 )
@@ -562,7 +611,7 @@ func TestHandler(t *testing.T) {
562611 case tc .state .Client .UsernameIsDefined == 1 :
563612 testutils .ExpectMessage (t , managementInterfaceConn , reader , "client-auth-nt 0 1" )
564613 testutils .SendMessagef (t , managementInterfaceConn , "SUCCESS: client-auth command succeeded" )
565- case tc . conf .OpenVPN .ClientConfig .Enabled :
614+ case conf .OpenVPN .ClientConfig .Enabled :
566615 if tc .state .Client .CommonName == "name" {
567616 testutils .ExpectMessage (t , managementInterfaceConn , reader , "client-auth 0 1\r \n " +
568617 "push \" ping 60\" \r \n " +
@@ -576,7 +625,7 @@ func TestHandler(t *testing.T) {
576625 testutils .SendMessagef (t , managementInterfaceConn , "SUCCESS: client-auth command succeeded" )
577626 }
578627 default :
579- if tc . conf .OAuth2 .UserInfo {
628+ if conf .OAuth2 .UserInfo {
580629 testutils .ExpectMessage (t , managementInterfaceConn , reader , "client-auth 0 1\r \n push \" auth-token-user dGVzdC11c2VyQGxvY2FsaG9zdA==\" \r \n END" )
581630 } else {
582631 testutils .ExpectMessage (t , managementInterfaceConn , reader , "client-auth 0 1\r \n push \" auth-token-user bmFtZQ==\" \r \n END" )
0 commit comments