| 1 |
//go:build unix |
| 2 |
|
| 3 |
package openvpn //nolint:testpackage // Verify the private listener closer used by the shutdown path. |
| 4 |
|
| 5 |
import ( |
| 6 |
"log/slog" |
| 7 |
"net/url" |
| 8 |
"os" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config" |
| 12 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config/types" |
| 13 |
"github.com/stretchr/testify/require" |
| 14 |
"golang.org/x/net/nettest" |
| 15 |
) |
| 16 |
|
| 17 |
func TestClient_SetupPassThroughListener_UnixSocketLifecycle(t *testing.T) { |
| 18 |
t.Parallel() |
| 19 |
|
| 20 |
path, err := nettest.LocalPath() |
| 21 |
require.NoError(t, err) |
| 22 |
t.Cleanup(func() { _ = os.Remove(path) }) |
| 23 |
|
| 24 |
conf := config.Defaults |
| 25 |
conf.OpenVPN.Passthrough.Address = types.URL{URL: &url.URL{Scheme: SchemeUnix, Path: path}} |
| 26 |
|
| 27 |
client := New(slog.New(slog.DiscardHandler), &conf) |
| 28 |
_, closer, err := client.setupPassThroughListener(t.Context()) |
| 29 |
require.NoError(t, err) |
| 30 |
require.FileExists(t, path) |
| 31 |
|
| 32 |
closer() |
| 33 |
|
| 34 |
_, err = os.Lstat(path) |
| 35 |
require.ErrorIs(t, err, os.ErrNotExist) |
| 36 |
} |