@ -367,10 +367,6 @@ func TestServeDevConfigMutations(t *testing.T) {
// // tcp
// // tcp
add ( step { reset : true } )
add ( step { reset : true } )
add ( step { // must include scheme for tcp
command : cmd ( "serve --tls-terminated-tcp=443 --bg localhost:5432" ) ,
wantErr : exactErr ( errHelp , "errHelp" ) ,
} )
add ( step { // !somehost, must be localhost or 127.0.0.1
add ( step { // !somehost, must be localhost or 127.0.0.1
command : cmd ( "serve --tls-terminated-tcp=443 --bg tcp://somehost:5432" ) ,
command : cmd ( "serve --tls-terminated-tcp=443 --bg tcp://somehost:5432" ) ,
wantErr : exactErr ( errHelp , "errHelp" ) ,
wantErr : exactErr ( errHelp , "errHelp" ) ,
@ -383,6 +379,18 @@ func TestServeDevConfigMutations(t *testing.T) {
command : cmd ( "serve --tls-terminated-tcp=443 --bg tcp://somehost:65536" ) ,
command : cmd ( "serve --tls-terminated-tcp=443 --bg tcp://somehost:65536" ) ,
wantErr : exactErr ( errHelp , "errHelp" ) ,
wantErr : exactErr ( errHelp , "errHelp" ) ,
} )
} )
add ( step { // support shorthand
command : cmd ( "serve --tls-terminated-tcp=443 --bg 5432" ) ,
want : & ipn . ServeConfig {
TCP : map [ uint16 ] * ipn . TCPPortHandler {
443 : {
TCPForward : "127.0.0.1:5432" ,
TerminateTLS : "foo.test.ts.net" ,
} ,
} ,
} ,
} )
add ( step { reset : true } )
add ( step {
add ( step {
command : cmd ( "serve --tls-terminated-tcp=443 --bg tcp://localhost:5432" ) ,
command : cmd ( "serve --tls-terminated-tcp=443 --bg tcp://localhost:5432" ) ,
want : & ipn . ServeConfig {
want : & ipn . ServeConfig {
@ -956,28 +964,43 @@ func TestSrcTypeFromFlags(t *testing.T) {
func TestExpandProxyTargetDev ( t * testing . T ) {
func TestExpandProxyTargetDev ( t * testing . T ) {
tests := [ ] struct {
tests := [ ] struct {
input string
name string
expected string
input string
wantErr bool
defaultScheme string
supportedSchemes [ ] string
expected string
wantErr bool
} {
} {
{ input : "8080" , expected : "http://127.0.0.1:8080" } ,
{ name : "port-only" , input : "8080" , expected : "http://127.0.0.1:8080" } ,
{ input : "localhost:8080" , expected : "http://127.0.0.1:8080" } ,
{ name : "hostname+port" , input : "localhost:8080" , expected : "http://127.0.0.1:8080" } ,
{ input : "http://localhost:8080" , expected : "http://127.0.0.1:8080" } ,
{ name : "convert-localhost" , input : "http://localhost:8080" , expected : "http://127.0.0.1:8080" } ,
{ input : "http://127.0.0.1:8080" , expected : "http://127.0.0.1:8080" } ,
{ name : "no-change" , input : "http://127.0.0.1:8080" , expected : "http://127.0.0.1:8080" } ,
{ input : "http://127.0.0.1:8080/foo" , expected : "http://127.0.0.1:8080/foo" } ,
{ name : "include-path" , input : "http://127.0.0.1:8080/foo" , expected : "http://127.0.0.1:8080/foo" } ,
{ input : "https://localhost:8080" , expected : "https://127.0.0.1:8080" } ,
{ name : "https-scheme" , input : "https://localhost:8080" , expected : "https://127.0.0.1:8080" } ,
{ input : "https+insecure://localhost:8080" , expected : "https+insecure://127.0.0.1:8080" } ,
{ name : "https+insecure-scheme" , input : "https+insecure://localhost:8080" , expected : "https+insecure://127.0.0.1:8080" } ,
{ name : "change-default-scheme" , input : "localhost:8080" , defaultScheme : "https" , expected : "https://127.0.0.1:8080" } ,
{ name : "change-supported-schemes" , input : "localhost:8080" , defaultScheme : "tcp" , supportedSchemes : [ ] string { "tcp" } , expected : "tcp://127.0.0.1:8080" } ,
// errors
// errors
{ input: "localhost:9999999" , wantErr : true } ,
{ name: "invalid-port" , input: "localhost:9999999" , wantErr : true } ,
{ input: "ftp://localhost:8080" , expected : "" , wantErr : true } ,
{ name: "unsupported-scheme" , input: "ftp://localhost:8080" , expected : "" , wantErr : true } ,
{ input: "https://tailscale.com:8080" , expected : "" , wantErr : true } ,
{ name: "not-localhost" , input: "https://tailscale.com:8080" , expected : "" , wantErr : true } ,
{ input: "" , expected : "" , wantErr : true } ,
{ name: "empty-input" , input: "" , expected : "" , wantErr : true } ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . input , func ( t * testing . T ) {
defaultScheme := "http"
actual , err := expandProxyTargetDev ( tt . input )
supportedSchemes := [ ] string { "http" , "https" , "https+insecure" }
if tt . supportedSchemes != nil {
supportedSchemes = tt . supportedSchemes
}
if tt . defaultScheme != "" {
defaultScheme = tt . defaultScheme
}
t . Run ( tt . name , func ( t * testing . T ) {
actual , err := expandProxyTargetDev ( tt . input , supportedSchemes , defaultScheme )
if tt . wantErr == true && err == nil {
if tt . wantErr == true && err == nil {
t . Errorf ( "Expected an error but got none" )
t . Errorf ( "Expected an error but got none" )