hysteria/extras/auth/http_test.go
2023-08-11 19:14:07 -07:00

36 lines
760 B
Go

package auth
import (
"net"
"os/exec"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestHTTPAuthenticator(t *testing.T) {
// Run the Python test auth server
cmd := exec.Command("python", "http_test.py")
err := cmd.Start()
assert.NoError(t, err)
defer cmd.Process.Kill()
time.Sleep(1 * time.Second) // Wait for the server to start
auth := NewHTTPAuthenticator("http://127.0.0.1:5000/auth", false)
ok, id := auth.Authenticate(&net.UDPAddr{
IP: net.ParseIP("1.2.3.4"),
Port: 34567,
}, "idk", 123)
assert.False(t, ok)
assert.Equal(t, "", id)
ok, id = auth.Authenticate(&net.UDPAddr{
IP: net.ParseIP("123.123.123.123"),
Port: 5566,
}, "wahaha", 12345)
assert.True(t, ok)
assert.Equal(t, "some_unique_id", id)
}