chain works
This commit is contained in:
55
main_test.go
Normal file
55
main_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"local/fproxy/fproxy"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_StandaloneClient(t *testing.T) {
|
||||
conf := map[string]string{
|
||||
"toaddr": "",
|
||||
"mycrt": "./testdata/mainserver.crt",
|
||||
"mykey": "./testdata/mainserver.key",
|
||||
"tocrt": "",
|
||||
"fromcrt": "./testdata/interclient.crt",
|
||||
"port": fproxy.GetPort(),
|
||||
"whitelist": "google.com,,plex.tv",
|
||||
"bypass": "plex.tv",
|
||||
"secure": "",
|
||||
"secret": "secret",
|
||||
}
|
||||
fp := fproxy.New(conf["port"])
|
||||
if err := fp.Apply(conf); err != nil {
|
||||
t.Fatalf("error applying conf: %v", err)
|
||||
}
|
||||
|
||||
client, err := fproxy.NewClient("./testdata/interclient.crt", "./testdata/interclient.key", "./testdata/mainserver.crt", conf["port"])
|
||||
if err != nil {
|
||||
t.Fatalf("cannot make client: %v", err)
|
||||
}
|
||||
|
||||
ready := make(chan struct{})
|
||||
go func() {
|
||||
fp.Start()
|
||||
ready <- struct{}{}
|
||||
<-ready
|
||||
fp.Close()
|
||||
ready <- struct{}{}
|
||||
}()
|
||||
<-ready
|
||||
|
||||
if resp, err := client.Get("http://google.com"); err != nil {
|
||||
t.Errorf("client cannot get: %v", err)
|
||||
} else if resp.StatusCode > 399 {
|
||||
t.Errorf("client status > 399: %v", resp.StatusCode)
|
||||
}
|
||||
|
||||
if resp, err := client.Get("https://google.com"); err != nil {
|
||||
t.Errorf("client cannot get: %v", err)
|
||||
} else if resp.StatusCode > 399 {
|
||||
t.Errorf("client status > 399: %v", resp.StatusCode)
|
||||
}
|
||||
|
||||
ready <- struct{}{}
|
||||
<-ready
|
||||
}
|
||||
Reference in New Issue
Block a user