-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from mysteriumnetwork/feature/e2e-test
Feature/e2e test
- Loading branch information
Showing
4 changed files
with
129 additions
and
60 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
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,8 @@ | ||
FROM golang:1.18-alpine | ||
|
||
# Install packages | ||
RUN apk add --update --no-cache bash git gcc musl-dev make iptables bind-tools | ||
|
||
# Install application | ||
WORKDIR /go/src/github.com/mysteriumnetwork/openvpn-forwarder | ||
ADD . . |
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,89 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
/* | ||
* Copyright (C) 2019 The "MysteriumNetwork/openvpn-forwarder" Authors. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/magefile/mage/sh" | ||
) | ||
|
||
var ( | ||
ipTablesAppend = sh.RunCmd("iptables", "-t", "nat", "-A") | ||
ipTablesDelete = sh.RunCmd("iptables", "-t", "nat", "-D") | ||
) | ||
|
||
// TestHTTPS runs end-to-end test for HTTPS traffic forwarding | ||
func TestHTTPS(t *testing.T) { | ||
// given | ||
originalIP, err := checkIP("https://api.ipify.org/?format=text") | ||
t.Log("Original IP:", originalIP) | ||
assert.NoError(t, err) | ||
|
||
forwarderIP, err := getForwarderIP() | ||
assert.NoError(t, err) | ||
|
||
// when | ||
redirectRule := []string{"OUTPUT", "-p", "tcp", "-m", "tcp", "--dport", "443", "-j", "DNAT", "--to-destination", forwarderIP + ":8443"} | ||
err = ipTablesAppend(redirectRule...) | ||
defer ipTablesDelete(redirectRule...) | ||
assert.NoError(t, err) | ||
|
||
// then | ||
currentIP, err := checkIP("https://api.ipify.org/?format=text") | ||
t.Log("Current IP:", currentIP) | ||
assert.NoError(t, err) | ||
|
||
assert.NotEqualf(t, originalIP, currentIP, "Request proxying failed: %s -> %s", originalIP, currentIP) | ||
} | ||
|
||
// TestHTTP runs end-to-end test for HTTP traffic forwarding | ||
func TestHTTP(t *testing.T) { | ||
// given | ||
originalIP, err := checkIP("http://api.ipify.org/?format=text") | ||
t.Log("Original IP:", originalIP) | ||
assert.NoError(t, err) | ||
|
||
forwarderIP, err := getForwarderIP() | ||
assert.NoError(t, err) | ||
|
||
// when | ||
redirectRule := []string{"OUTPUT", "-p", "tcp", "-m", "tcp", "--dport", "80", "-j", "DNAT", "--to-destination", forwarderIP + ":8443"} | ||
err = ipTablesAppend(redirectRule...) | ||
defer ipTablesDelete(redirectRule...) | ||
assert.NoError(t, err) | ||
|
||
currentIP, err := checkIP("http://api.ipify.org/?format=text") | ||
t.Log("Current IP:", currentIP) | ||
assert.NoError(t, err) | ||
|
||
assert.NotEqualf(t, originalIP, currentIP, "Request proxying failed: %s -> %s", originalIP, currentIP) | ||
} | ||
|
||
func getForwarderIP() (string, error) { | ||
return sh.Output("dig", "forwarder", "+short") | ||
} | ||
|
||
func checkIP(apiURL string) (string, error) { | ||
return sh.Output("wget", "-q", "-O", "-", apiURL) | ||
} |