2021-11-09 11:37:51 +00:00
|
|
|
//go:build !windows
|
2021-08-03 11:08:08 +00:00
|
|
|
// +build !windows
|
|
|
|
|
2022-02-07 09:42:07 +00:00
|
|
|
package proxy
|
2021-08-03 11:08:08 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnixSocketOrigin(t *testing.T) {
|
2023-07-15 01:42:48 +00:00
|
|
|
file, err := os.CreateTemp("", "unix.sock")
|
2021-08-03 11:08:08 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
os.Remove(file.Name()) // remove the file since binding the socket expects to create it
|
|
|
|
|
|
|
|
l, err := net.Listen("unix", file.Name())
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer l.Close()
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
|
|
|
|
api := &httptest.Server{
|
|
|
|
Listener: l,
|
|
|
|
Config: &http.Server{Handler: mockAPI{}},
|
|
|
|
}
|
|
|
|
api.Start()
|
|
|
|
defer api.Close()
|
|
|
|
|
|
|
|
unvalidatedIngress := []config.UnvalidatedIngressRule{
|
|
|
|
{
|
|
|
|
Hostname: "unix.example.com",
|
|
|
|
Service: "unix:" + file.Name(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Hostname: "*",
|
|
|
|
Service: "http_status:404",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []MultipleIngressTest{
|
|
|
|
{
|
|
|
|
url: "http://unix.example.com",
|
|
|
|
expectedStatus: http.StatusCreated,
|
|
|
|
expectedBody: []byte("Created"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
runIngressTestScenarios(t, unvalidatedIngress, tests)
|
|
|
|
}
|