github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/infra/conf/wireguard_test.go (about)

     1  package conf_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	. "github.com/xmplusdev/xmcore/infra/conf"
     7  	"github.com/xmplusdev/xmcore/proxy/wireguard"
     8  )
     9  
    10  func TestWireGuardConfig(t *testing.T) {
    11  	creator := func() Buildable {
    12  		return new(WireGuardConfig)
    13  	}
    14  
    15  	runMultiTestCase(t, []TestCase{
    16  		{
    17  			Input: `{
    18  				"secretKey": "uJv5tZMDltsiYEn+kUwb0Ll/CXWhMkaSCWWhfPEZM3A=",
    19  				"address": ["10.1.1.1", "fd59:7153:2388:b5fd:0000:0000:1234:0001"],
    20  				"peers": [
    21  					{
    22  						"publicKey": "6e65ce0be17517110c17d77288ad87e7fd5252dcc7d09b95a39d61db03df832a",
    23  						"endpoint": "127.0.0.1:1234"
    24  					}
    25  				],
    26  				"mtu": 1300,
    27  				"workers": 2,
    28  				"domainStrategy": "ForceIPv6v4",
    29  				"kernelMode": false
    30  			}`,
    31  			Parser: loadJSON(creator),
    32  			Output: &wireguard.DeviceConfig{
    33  				// key converted into hex form
    34  				SecretKey: "b89bf9b5930396db226049fe914c1bd0b97f0975a13246920965a17cf1193370",
    35  				Endpoint:  []string{"10.1.1.1", "fd59:7153:2388:b5fd:0000:0000:1234:0001"},
    36  				Peers: []*wireguard.PeerConfig{
    37  					{
    38  						// also can read from hex form directly
    39  						PublicKey:  "6e65ce0be17517110c17d77288ad87e7fd5252dcc7d09b95a39d61db03df832a",
    40  						Endpoint:   "127.0.0.1:1234",
    41  						KeepAlive:  0,
    42  						AllowedIps: []string{"0.0.0.0/0", "::0/0"},
    43  					},
    44  				},
    45  				Mtu:            1300,
    46  				NumWorkers:     2,
    47  				DomainStrategy: wireguard.DeviceConfig_FORCE_IP64,
    48  				KernelMode:     false,
    49  			},
    50  		},
    51  	})
    52  }