-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: kung-foo <github@jonathan.camp>
- Loading branch information
Showing
6 changed files
with
108 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:1.8-alpine | ||
|
||
RUN apk update && apk add curl build-base iptables libpcap-dev "libnetfilter_queue-dev>=1.0.0" git gcc libc-dev linux-headers | ||
RUN go get golang.org/x/net/bpf | ||
RUN go get golang.org/x/net/context | ||
RUN go get golang.org/x/net/proxy | ||
RUN go get github.com/smartystreets/goconvey | ||
|
||
WORKDIR /go/src/github.com/kung-foo/freki | ||
|
||
RUN curl -s -L https://github.com/kung-foo/waitforit/releases/download/v0.0.1/waitforit-linux-amd64 > /bin/waitforit | ||
RUN chmod +x /bin/waitforit |
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,18 @@ | ||
version: '3.1' | ||
|
||
services: | ||
freki: | ||
build: . | ||
stop_signal: SIGINT | ||
cap_add: | ||
- NET_ADMIN | ||
command: system_test/run_freki.sh | ||
volumes: | ||
- ../:/go/src/github.com/kung-foo/freki:ro | ||
test: | ||
build: . | ||
command: system_test/run_test.sh | ||
volumes: | ||
- ../:/go/src/github.com/kung-foo/freki:ro | ||
links: | ||
- freki |
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,9 @@ | ||
version: 1 | ||
rules: | ||
- match: tcp port 80 or tcp port 8080 | ||
type: log_http | ||
- match: tcp port 1337 | ||
type: proxy | ||
target: tcp://port.party:666 | ||
- match: | ||
type: passthrough |
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,6 @@ | ||
#!/usr/bin/env ash | ||
|
||
set -ex | ||
|
||
go build -o /tmp/freki app/main.go | ||
exec /tmp/freki -v -i eth0 -r system_test/rules.yaml |
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 @@ | ||
#!/usr/bin/env ash | ||
|
||
set -ex | ||
|
||
echo "Wating for freki to start..." | ||
waitforit -r 60 -s http://freki:80 | ||
|
||
go test -v system_test/system_test.go |
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,55 @@ | ||
package system_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestEndToEnd(t *testing.T) { | ||
Convey("Given freki is working...", t, func() { | ||
Convey("Port 80 and 8080 should return OK", func() { | ||
f := func(p int) { | ||
resp, err := http.Get(fmt.Sprintf("http://freki:%d/", p)) | ||
|
||
So(err, ShouldBeNil) | ||
So(resp, ShouldNotBeNil) | ||
|
||
So(resp.StatusCode, ShouldEqual, 200) | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
So(err, ShouldBeNil) | ||
So(bytes.Equal(body, []byte("OK\n")), ShouldBeTrue) | ||
resp.Body.Close() | ||
} | ||
|
||
f(80) | ||
f(8080) | ||
}) | ||
|
||
Convey("Port 1137 should proxy to port.party:666", func() { | ||
resp, err := http.Get("http://freki:1337/cors.json") | ||
So(err, ShouldBeNil) | ||
So(resp, ShouldNotBeNil) | ||
|
||
So(resp.StatusCode, ShouldEqual, 200) | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
So(err, ShouldBeNil) | ||
|
||
j := make(map[string]int) | ||
|
||
So(json.Unmarshal(body, &j), ShouldBeNil) | ||
|
||
So(j, ShouldContainKey, "Port") | ||
So(j["Port"], ShouldEqual, 666) | ||
|
||
resp.Body.Close() | ||
}) | ||
}) | ||
} |