mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-17 12:44:36 +03:00
Some checks are pending
Build docker image / build-image (push) Waiting to run
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Waiting to run
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Waiting to run
Build and Release / build (386, freebsd, ) (push) Waiting to run
Build and Release / build (386, linux, ) (push) Waiting to run
Build and Release / build (386, openbsd, ) (push) Waiting to run
Build and Release / build (386, windows, ) (push) Waiting to run
Build and Release / build (amd64, darwin, ) (push) Waiting to run
Build and Release / build (amd64, freebsd, ) (push) Waiting to run
Build and Release / build (amd64, linux, ) (push) Waiting to run
Build and Release / build (amd64, openbsd, ) (push) Waiting to run
Build and Release / build (amd64, windows, ) (push) Waiting to run
Build and Release / build (arm, 5, linux) (push) Waiting to run
Build and Release / build (arm, 6, linux) (push) Waiting to run
Build and Release / build (arm, 7, freebsd) (push) Waiting to run
Build and Release / build (arm, 7, linux) (push) Waiting to run
Build and Release / build (arm, 7, openbsd) (push) Waiting to run
Build and Release / build (arm, 7, windows) (push) Waiting to run
Build and Release / build (arm64, android) (push) Waiting to run
Build and Release / build (arm64, darwin) (push) Waiting to run
Build and Release / build (arm64, freebsd) (push) Waiting to run
Build and Release / build (arm64, linux) (push) Waiting to run
Build and Release / build (arm64, openbsd) (push) Waiting to run
Build and Release / build (arm64, windows) (push) Waiting to run
Build and Release / build (loong64, linux) (push) Waiting to run
Build and Release / build (mips, linux) (push) Waiting to run
Build and Release / build (mips64, linux) (push) Waiting to run
Build and Release / build (mips64le, linux) (push) Waiting to run
Build and Release / build (mipsle, linux) (push) Waiting to run
Build and Release / build (ppc64, linux) (push) Waiting to run
Build and Release / build (ppc64le, linux) (push) Waiting to run
Build and Release / build (riscv64, linux) (push) Waiting to run
Build and Release / build (s390x, linux) (push) Waiting to run
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run
https://github.com/XTLS/Xray-core/pull/4566#issuecomment-2764779273
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package wireguard_test
|
|
|
|
import (
|
|
"context"
|
|
"github.com/stretchr/testify/assert"
|
|
"runtime/debug"
|
|
"testing"
|
|
|
|
"github.com/xtls/xray-core/core"
|
|
"github.com/xtls/xray-core/proxy/wireguard"
|
|
)
|
|
|
|
// TestWireGuardServerInitializationError verifies that an error during TUN initialization
|
|
// (triggered by an empty SecretKey) in the WireGuard server does not cause a panic and returns an error instead.
|
|
func TestWireGuardServerInitializationError(t *testing.T) {
|
|
// Create a minimal core instance with default features
|
|
config := &core.Config{}
|
|
instance, err := core.New(config)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create core instance: %v", err)
|
|
}
|
|
// Set the Xray instance in the context
|
|
ctx := context.WithValue(context.Background(), core.XrayKey(1), instance)
|
|
|
|
// Define the server configuration with an empty SecretKey to trigger error
|
|
conf := &wireguard.DeviceConfig{
|
|
IsClient: false,
|
|
Endpoint: []string{"10.0.0.1/32"},
|
|
Mtu: 1420,
|
|
SecretKey: "", // Empty SecretKey to trigger error
|
|
Peers: []*wireguard.PeerConfig{
|
|
{
|
|
PublicKey: "some_public_key",
|
|
AllowedIps: []string{"10.0.0.2/32"},
|
|
},
|
|
},
|
|
}
|
|
|
|
// Use defer to catch any panic and fail the test explicitly
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("TUN initialization panicked: %v", r)
|
|
debug.PrintStack()
|
|
}
|
|
}()
|
|
|
|
// Attempt to initialize the WireGuard server
|
|
_, err = wireguard.NewServer(ctx, conf)
|
|
|
|
// Check that an error is returned
|
|
assert.ErrorContains(t, err, "failed to set private_key: hex string does not fit the slice")
|
|
}
|