-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e749217
commit ff99bfd
Showing
3 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package wireproxy | ||
|
||
import ( | ||
"github.com/go-ini/ini" | ||
"testing" | ||
) | ||
|
||
func loadIniConfig(config string) (*ini.File, error) { | ||
iniOpt := ini.LoadOptions{ | ||
Insensitive: true, | ||
AllowShadows: true, | ||
AllowNonUniqueSections: true, | ||
} | ||
|
||
return ini.LoadSources(iniOpt, []byte(config)) | ||
} | ||
|
||
func TestWireguardConfWithoutSubnet(t *testing.T) { | ||
const config = ` | ||
[Interface] | ||
PrivateKey = LAr1aNSNF9d0MjwUgAVC4020T0N/E5NUtqVv5EnsSz0= | ||
Address = 10.5.0.2 | ||
DNS = 1.1.1.1 | ||
[Peer] | ||
PublicKey = e8LKAc+f9xEzq9Ar7+MfKRrs+gZ/4yzvpRJLRJ/VJ1w= | ||
AllowedIPs = 0.0.0.0/0, ::/0 | ||
Endpoint = 94.140.11.15:51820 | ||
PersistentKeepalive = 25` | ||
var cfg DeviceConfig | ||
iniData, err := loadIniConfig(config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = ParseInterface(iniData, &cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestWireguardConfWithSubnet(t *testing.T) { | ||
const config = ` | ||
[Interface] | ||
PrivateKey = LAr1aNSNF9d0MjwUgAVC4020T0N/E5NUtqVv5EnsSz0= | ||
Address = 10.5.0.2/23 | ||
DNS = 1.1.1.1 | ||
[Peer] | ||
PublicKey = e8LKAc+f9xEzq9Ar7+MfKRrs+gZ/4yzvpRJLRJ/VJ1w= | ||
AllowedIPs = 0.0.0.0/0, ::/0 | ||
Endpoint = 94.140.11.15:51820 | ||
PersistentKeepalive = 25` | ||
var cfg DeviceConfig | ||
iniData, err := loadIniConfig(config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = ParseInterface(iniData, &cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestWireguardConfWithManyAddress(t *testing.T) { | ||
const config = ` | ||
[Interface] | ||
PrivateKey = mBsVDahr1XIu9PPd17UmsDdB6E53nvmS47NbNqQCiFM= | ||
Address = 100.96.0.190,2606:B300:FFFF:fe8a:2ac6:c7e8:b021:6f5f/128 | ||
DNS = 198.18.0.1,198.18.0.2 | ||
[Peer] | ||
PublicKey = SHnh4C2aDXhp1gjIqceGhJrhOLSeNYcqWLKcYnzj00U= | ||
AllowedIPs = 0.0.0.0/0,::/0 | ||
Endpoint = 192.200.144.22:51820` | ||
var cfg DeviceConfig | ||
iniData, err := loadIniConfig(config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = ParseInterface(iniData, &cfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters