internal: fix URL generation for websocket connection (#12439)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
		
							
								
								
									
										32
									
								
								internal/outpost/ak/api_ws_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								internal/outpost/ak/api_ws_test.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
package ak
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net/url"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func URLMustParse(u string) *url.URL {
 | 
			
		||||
	ur, err := url.Parse(u)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	return ur
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestWebsocketURL(t *testing.T) {
 | 
			
		||||
	u := URLMustParse("http://localhost:9000?foo=bar")
 | 
			
		||||
	uuid := "23470845-7263-4fe3-bd79-ec1d7bf77d77"
 | 
			
		||||
	ac := &APIController{}
 | 
			
		||||
	nu := ac.getWebsocketURL(*u, uuid)
 | 
			
		||||
	assert.Equal(t, "ws://localhost:9000/ws/outpost/23470845-7263-4fe3-bd79-ec1d7bf77d77?foo=bar", nu.String())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestWebsocketURL_Subpath(t *testing.T) {
 | 
			
		||||
	u := URLMustParse("http://localhost:9000/foo/bar/")
 | 
			
		||||
	uuid := "23470845-7263-4fe3-bd79-ec1d7bf77d77"
 | 
			
		||||
	ac := &APIController{}
 | 
			
		||||
	nu := ac.getWebsocketURL(*u, uuid)
 | 
			
		||||
	assert.Equal(t, "ws://localhost:9000/foo/bar/ws/outpost/23470845-7263-4fe3-bd79-ec1d7bf77d77", nu.String())
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user