Rewrite of the entrypoint in Golang (#71)
- General improvements
- Parallel download of only needed files at start
- Prettier console output with all streams merged (openvpn, unbound, shadowsocks etc.)
- Simplified Docker final image
- Faster bootup
- DNS over TLS
- Finer grain blocking at DNS level: malicious, ads and surveillance
- Choose your DNS over TLS providers
- Ability to use multiple DNS over TLS providers for DNS split horizon
- Environment variables for DNS logging
- DNS block lists needed are downloaded and built automatically at start, in parallel
- PIA
- A random region is selected if the REGION parameter is left empty (thanks @rorph for your PR)
- Routing and iptables adjusted so it can work as a Kubernetes pod sidecar (thanks @rorph for your PR)
This commit is contained in:
99
internal/pia/parse_test.go
Normal file
99
internal/pia/parse_test.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package pia
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
loggingMocks "github.com/qdm12/golibs/logging/mocks"
|
||||
"github.com/qdm12/golibs/verification"
|
||||
"github.com/qdm12/private-internet-access-docker/internal/constants"
|
||||
"github.com/qdm12/private-internet-access-docker/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_ParseConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
original, err := ioutil.ReadFile("testdata/ovpn.golden")
|
||||
require.NoError(t, err)
|
||||
exampleLines := strings.Split(string(original), "\n")
|
||||
tests := map[string]struct {
|
||||
lines []string
|
||||
lookupIPs []net.IP
|
||||
lookupIPErr error
|
||||
IPs []net.IP
|
||||
port uint16
|
||||
device models.VPNDevice
|
||||
err error
|
||||
}{
|
||||
"no data": {
|
||||
err: fmt.Errorf("remote line not found in Openvpn configuration"),
|
||||
},
|
||||
"bad remote line": {
|
||||
lines: []string{"remote field2"},
|
||||
err: fmt.Errorf("line \"remote field2\" misses information"),
|
||||
},
|
||||
"bad remote port": {
|
||||
lines: []string{"remote field2 port"},
|
||||
err: fmt.Errorf("line \"remote field2 port\" has an invalid port: port \"port\" is not a valid integer"),
|
||||
},
|
||||
"lookupIP error": {
|
||||
lines: []string{"remote host 1000"},
|
||||
lookupIPErr: fmt.Errorf("lookup error"),
|
||||
err: fmt.Errorf("lookup error"),
|
||||
},
|
||||
"missing dev line": {
|
||||
lines: []string{"remote host 1994"},
|
||||
err: fmt.Errorf("device line not found in Openvpn configuration"),
|
||||
},
|
||||
"bad dev line": {
|
||||
lines: []string{"dev field2 field3"},
|
||||
err: fmt.Errorf("line \"dev field2 field3\" misses information"),
|
||||
},
|
||||
"bad device": {
|
||||
lines: []string{"dev xx"},
|
||||
err: fmt.Errorf("device \"xx0\" is not valid"),
|
||||
},
|
||||
"valid lines": {
|
||||
lines: []string{"remote host 1194", "dev tap", "blabla"},
|
||||
port: 1194,
|
||||
device: constants.TAP,
|
||||
},
|
||||
"real data": {
|
||||
lines: exampleLines,
|
||||
lookupIPs: []net.IP{{100, 100, 100, 100}, {100, 100, 200, 200}},
|
||||
IPs: []net.IP{{100, 100, 100, 100}, {100, 100, 200, 200}},
|
||||
port: 1198,
|
||||
device: constants.TUN,
|
||||
},
|
||||
}
|
||||
for name, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := &loggingMocks.Logger{}
|
||||
logger.On("Info", "%s: parsing openvpn configuration", logPrefix).Once()
|
||||
if tc.err == nil {
|
||||
logger.On("Info", "%s: Found %d PIA server IP addresses, port %d and device %s", logPrefix, len(tc.IPs), tc.port, tc.device).Once()
|
||||
}
|
||||
lookupIP := func(host string) ([]net.IP, error) {
|
||||
return tc.lookupIPs, tc.lookupIPErr
|
||||
}
|
||||
c := &configurator{logger: logger, verifyPort: verification.NewVerifier().VerifyPort, lookupIP: lookupIP}
|
||||
IPs, port, device, err := c.ParseConfig(tc.lines)
|
||||
if tc.err != nil {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, tc.err.Error(), err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
assert.Equal(t, tc.IPs, IPs)
|
||||
assert.Equal(t, tc.port, port)
|
||||
assert.Equal(t, tc.device, device)
|
||||
logger.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user