summaryrefslogtreecommitdiff
path: root/plugins/http
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-11-24 15:52:15 +0300
committerValery Piashchynski <[email protected]>2020-11-24 15:52:15 +0300
commitbe4aadb5384fd8b97c927f3ef48383dc5b23b345 (patch)
tree0cf046f503ad916af03f7424e7ae0975943da04a /plugins/http
parentbc0be9c17220220ae9b40b65e874701edaecd8ce (diff)
md5 -> sha512
h2c tests fcgi tests plugin tests updated
Diffstat (limited to 'plugins/http')
-rw-r--r--plugins/http/plugin.go37
-rw-r--r--plugins/http/tests/configs/.rr-fcgi-reqUri.yaml35
-rw-r--r--plugins/http/tests/configs/.rr-fcgi.yaml4
-rw-r--r--plugins/http/tests/configs/.rr-h2c.yaml8
-rw-r--r--plugins/http/tests/configs/.rr-http.yaml6
-rw-r--r--plugins/http/tests/configs/.rr-ssl-push.yaml35
-rw-r--r--plugins/http/tests/configs/.rr-ssl-redirect.yaml35
-rw-r--r--plugins/http/tests/configs/.rr-ssl.yaml4
-rw-r--r--plugins/http/tests/fcgi_test.go104
-rw-r--r--plugins/http/tests/h2c_test.go81
-rw-r--r--plugins/http/tests/http_test.go481
-rw-r--r--plugins/http/tests/plugin_test_old.go (renamed from plugins/http/tests/plugin_test.go)0
-rw-r--r--plugins/http/tests/rpc_test_old.go (renamed from plugins/http/tests/rpc_test.go)0
-rw-r--r--plugins/http/tests/ssl_test.go178
-rw-r--r--plugins/http/tests/uploads_test.go22
15 files changed, 591 insertions, 439 deletions
diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go
index aae42891..38539d52 100644
--- a/plugins/http/plugin.go
+++ b/plugins/http/plugin.go
@@ -251,15 +251,12 @@ func (s *Plugin) Stop() error {
// ServeHTTP handles connection using set of middleware and pool PSR-7 server.
func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- if s.https != nil && r.TLS == nil && s.cfg.SSL.Redirect {
- target := &url.URL{
- Scheme: "https",
- Host: s.tlsAddr(r.Host, false),
- Path: r.URL.Path,
- RawQuery: r.URL.RawQuery,
- }
+ if headerContainsUpgrade(r, s) {
+ http.Error(w, "server does not support upgrade header", http.StatusInternalServerError)
+ return
+ }
- http.Redirect(w, r, target.String(), http.StatusTemporaryRedirect)
+ if s.redirect(w, r) {
return
}
@@ -277,6 +274,30 @@ func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) {
f(w, r)
}
+func (s *Plugin) redirect(w http.ResponseWriter, r *http.Request) bool {
+ if s.https != nil && r.TLS == nil && s.cfg.SSL.Redirect {
+ target := &url.URL{
+ Scheme: "https",
+ Host: s.tlsAddr(r.Host, false),
+ Path: r.URL.Path,
+ RawQuery: r.URL.RawQuery,
+ }
+
+ http.Redirect(w, r, target.String(), http.StatusTemporaryRedirect)
+ return true
+ }
+ return false
+}
+
+func headerContainsUpgrade(r *http.Request, s *Plugin) bool {
+ if _, ok := r.Header["Upgrade"]; ok {
+ // https://golang.org/pkg/net/http/#Hijacker
+ s.log.Error("server does not support Upgrade header")
+ return true
+ }
+ return false
+}
+
// append RootCA to the https server TLS config
func (s *Plugin) appendRootCa() error {
const op = errors.Op("append root CA")
diff --git a/plugins/http/tests/configs/.rr-fcgi-reqUri.yaml b/plugins/http/tests/configs/.rr-fcgi-reqUri.yaml
new file mode 100644
index 00000000..c42ff6a3
--- /dev/null
+++ b/plugins/http/tests/configs/.rr-fcgi-reqUri.yaml
@@ -0,0 +1,35 @@
+server:
+ command: "php ../../../tests/http/client.php request-uri pipes"
+ user: ""
+ group: ""
+ env:
+ "RR_HTTP": "true"
+ relay: "pipes"
+ relayTimeout: "20s"
+
+http:
+ debug: true
+ address: :8082
+ maxRequestSize: 1024
+ middleware: [ "" ]
+ uploads:
+ forbid: [ ".php", ".exe", ".bat" ]
+ trustedSubnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
+ pool:
+ numWorkers: 1
+ maxJobs: 0
+ allocateTimeout: 60s
+ destroyTimeout: 60s
+
+ ssl:
+ port: 8890
+ redirect: false
+ cert: fixtures/server.crt
+ key: fixtures/server.key
+ # rootCa: root.crt
+ fcgi:
+ address: tcp://0.0.0.0:6921
+ http2:
+ enabled: false
+ h2c: false
+ maxConcurrentStreams: 128 \ No newline at end of file
diff --git a/plugins/http/tests/configs/.rr-fcgi.yaml b/plugins/http/tests/configs/.rr-fcgi.yaml
index cdfdd969..0cbd6d02 100644
--- a/plugins/http/tests/configs/.rr-fcgi.yaml
+++ b/plugins/http/tests/configs/.rr-fcgi.yaml
@@ -9,7 +9,7 @@ server:
http:
debug: true
- address: :8080
+ address: :8081
maxRequestSize: 1024
middleware: [ "" ]
uploads:
@@ -22,7 +22,7 @@ http:
destroyTimeout: 60s
ssl:
- port: 8888
+ port: 8889
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
diff --git a/plugins/http/tests/configs/.rr-h2c.yaml b/plugins/http/tests/configs/.rr-h2c.yaml
index cdfdd969..316daea9 100644
--- a/plugins/http/tests/configs/.rr-h2c.yaml
+++ b/plugins/http/tests/configs/.rr-h2c.yaml
@@ -9,7 +9,7 @@ server:
http:
debug: true
- address: :8080
+ address: :8083
maxRequestSize: 1024
middleware: [ "" ]
uploads:
@@ -22,7 +22,7 @@ http:
destroyTimeout: 60s
ssl:
- port: 8888
+ port: 8891
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
@@ -30,6 +30,6 @@ http:
fcgi:
address: tcp://0.0.0.0:6920
http2:
- enabled: false
- h2c: false
+ enabled: true
+ h2c: true
maxConcurrentStreams: 128 \ No newline at end of file
diff --git a/plugins/http/tests/configs/.rr-http.yaml b/plugins/http/tests/configs/.rr-http.yaml
index a566c794..caf7dfe3 100644
--- a/plugins/http/tests/configs/.rr-http.yaml
+++ b/plugins/http/tests/configs/.rr-http.yaml
@@ -9,7 +9,7 @@ server:
http:
debug: true
- address: 127.0.0.1:8080
+ address: 127.0.0.1:8084
maxRequestSize: 200
middleware: [ "" ]
uploads:
@@ -22,13 +22,13 @@ http:
destroyTimeout: 60s
ssl:
- port: 8888
+ port: 8892
redirect: true
cert: fixtures/server.crt
key: fixtures/server.key
# rootCa: root.crt
fcgi:
- address: tcp://0.0.0.0:6920
+ address: tcp://0.0.0.0:6921
http2:
enabled: false
h2c: false
diff --git a/plugins/http/tests/configs/.rr-ssl-push.yaml b/plugins/http/tests/configs/.rr-ssl-push.yaml
new file mode 100644
index 00000000..90a99192
--- /dev/null
+++ b/plugins/http/tests/configs/.rr-ssl-push.yaml
@@ -0,0 +1,35 @@
+server:
+ command: "php ../../../tests/http/client.php push pipes"
+ user: ""
+ group: ""
+ env:
+ "RR_HTTP": "true"
+ relay: "pipes"
+ relayTimeout: "20s"
+
+http:
+ debug: true
+ address: :8086
+ maxRequestSize: 1024
+ middleware: [ "" ]
+ uploads:
+ forbid: [ ".php", ".exe", ".bat" ]
+ trustedSubnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
+ pool:
+ numWorkers: 1
+ maxJobs: 0
+ allocateTimeout: 60s
+ destroyTimeout: 60s
+
+ ssl:
+ port: 8894
+ redirect: true
+ cert: fixtures/server.crt
+ key: fixtures/server.key
+ # rootCa: root.crt
+ fcgi:
+ address: tcp://0.0.0.0:6920
+ http2:
+ enabled: false
+ h2c: false
+ maxConcurrentStreams: 128 \ No newline at end of file
diff --git a/plugins/http/tests/configs/.rr-ssl-redirect.yaml b/plugins/http/tests/configs/.rr-ssl-redirect.yaml
new file mode 100644
index 00000000..1878ba53
--- /dev/null
+++ b/plugins/http/tests/configs/.rr-ssl-redirect.yaml
@@ -0,0 +1,35 @@
+server:
+ command: "php ../../../tests/http/client.php echo pipes"
+ user: ""
+ group: ""
+ env:
+ "RR_HTTP": "true"
+ relay: "pipes"
+ relayTimeout: "20s"
+
+http:
+ debug: true
+ address: :8087
+ maxRequestSize: 1024
+ middleware: [ "" ]
+ uploads:
+ forbid: [ ".php", ".exe", ".bat" ]
+ trustedSubnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ]
+ pool:
+ numWorkers: 1
+ maxJobs: 0
+ allocateTimeout: 60s
+ destroyTimeout: 60s
+
+ ssl:
+ port: 8895
+ redirect: true
+ cert: fixtures/server.crt
+ key: fixtures/server.key
+ # rootCa: root.crt
+ fcgi:
+ address: tcp://0.0.0.0:6920
+ http2:
+ enabled: false
+ h2c: false
+ maxConcurrentStreams: 128 \ No newline at end of file
diff --git a/plugins/http/tests/configs/.rr-ssl.yaml b/plugins/http/tests/configs/.rr-ssl.yaml
index cdfdd969..127c1678 100644
--- a/plugins/http/tests/configs/.rr-ssl.yaml
+++ b/plugins/http/tests/configs/.rr-ssl.yaml
@@ -9,7 +9,7 @@ server:
http:
debug: true
- address: :8080
+ address: :8085
maxRequestSize: 1024
middleware: [ "" ]
uploads:
@@ -22,7 +22,7 @@ http:
destroyTimeout: 60s
ssl:
- port: 8888
+ port: 8893
redirect: false
cert: fixtures/server.crt
key: fixtures/server.key
diff --git a/plugins/http/tests/fcgi_test.go b/plugins/http/tests/fcgi_test.go
deleted file mode 100644
index 0a0b2b41..00000000
--- a/plugins/http/tests/fcgi_test.go
+++ /dev/null
@@ -1,104 +0,0 @@
-package tests
-
-//
-//import (
-// "io/ioutil"
-// "net/http/fcgi"
-// "net/http/httptest"
-// "testing"
-// "time"
-//
-// "github.com/stretchr/testify/assert"
-//)
-//
-//func Test_FCGI_Service_Echo(t *testing.T) {
-// logger, _ := test.NewNullLogger()
-// logger.SetLevel(logrus.DebugLevel)
-//
-// c := service.NewContainer(logger)
-// c.Register(ID, &Service{})
-//
-// assert.NoError(t, c.Init(&testCfg{httpCfg: `{
-// "fcgi": {
-// "address": "tcp://0.0.0.0:6082"
-// },
-// "workers":{
-// "command": "php ../../tests/http/client.php echo pipes",
-// "pool": {"numWorkers": 1}
-// }
-// }`}))
-//
-// s, st := c.Get(ID)
-// assert.NotNil(t, s)
-// assert.Equal(t, service.StatusOK, st)
-//
-// // should do nothing
-// s.(*Service).Stop()
-//
-// go func() { assert.NoError(t, c.Serve()) }()
-// time.Sleep(time.Second * 1)
-//
-// fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6082")
-//
-// fcgiHandler := gofast.NewHandler(
-// gofast.BasicParamsMap(gofast.BasicSession),
-// gofast.SimpleClientFactory(fcgiConnFactory, 0),
-// )
-//
-// w := httptest.NewRecorder()
-// req := httptest.NewRequest("GET", "http://site.local/?hello=world", nil)
-// fcgiHandler.ServeHTTP(w, req)
-//
-// body, err := ioutil.ReadAll(w.Result().Body)
-//
-// assert.NoError(t, err)
-// assert.Equal(t, 201, w.Result().StatusCode)
-// assert.Equal(t, "WORLD", string(body))
-// c.Stop()
-//}
-//
-//func Test_FCGI_Service_Request_Uri(t *testing.T) {
-// logger, _ := test.NewNullLogger()
-// logger.SetLevel(logrus.DebugLevel)
-//
-// c := service.NewContainer(logger)
-// c.Register(ID, &Service{})
-//
-// assert.NoError(t, c.Init(&testCfg{httpCfg: `{
-// "fcgi": {
-// "address": "tcp://0.0.0.0:6083"
-// },
-// "workers":{
-// "command": "php ../../tests/http/client.php request-uri pipes",
-// "pool": {"numWorkers": 1}
-// }
-// }`}))
-//
-// s, st := c.Get(ID)
-// assert.NotNil(t, s)
-// assert.Equal(t, service.StatusOK, st)
-//
-// // should do nothing
-// s.(*Service).Stop()
-//
-// go func() { assert.NoError(t, c.Serve()) }()
-// time.Sleep(time.Second * 1)
-//
-// fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6083")
-//
-// fcgiHandler := gofast.NewHandler(
-// gofast.BasicParamsMap(gofast.BasicSession),
-// gofast.SimpleClientFactory(fcgiConnFactory, 0),
-// )
-//
-// w := httptest.NewRecorder()
-// req := httptest.NewRequest("GET", "http://site.local/hello-world", nil)
-// fcgiHandler.ServeHTTP(w, req)
-//
-// body, err := ioutil.ReadAll(w.Result().Body)
-//
-// assert.NoError(t, err)
-// assert.Equal(t, 200, w.Result().StatusCode)
-// assert.Equal(t, "http://site.local/hello-world", string(body))
-// c.Stop()
-//}
diff --git a/plugins/http/tests/h2c_test.go b/plugins/http/tests/h2c_test.go
deleted file mode 100644
index c85ce942..00000000
--- a/plugins/http/tests/h2c_test.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package tests
-
-//
-//import (
-// "net/http"
-// "testing"
-// "time"
-//
-// "github.com/cenkalti/backoff/v4"
-// "github.com/stretchr/testify/assert"
-//)
-//
-//func Test_Service_H2C(t *testing.T) {
-// bkoff := backoff.NewExponentialBackOff()
-// bkoff.MaxElapsedTime = time.Second * 15
-//
-// err := backoff.Retry(func() error {
-// logger, _ := test.NewNullLogger()
-// logger.SetLevel(logrus.DebugLevel)
-//
-// c := service.NewContainer(logger)
-// c.Register(ID, &Service{})
-//
-// err := c.Init(&testCfg{httpCfg: `{
-// "address": ":6029",
-// "http2": {"h2c":true},
-// "workers":{
-// "command": "php ../../tests/http/client.php echo pipes",
-// "relay": "pipes",
-// "pool": {
-// "numWorkers": 1
-// }
-// }
-// }`})
-// if err != nil {
-// return err
-// }
-//
-// s, st := c.Get(ID)
-// assert.NotNil(t, s)
-// assert.Equal(t, service.StatusOK, st)
-//
-// // should do nothing
-// s.(*Service).Stop()
-//
-// go func() {
-// err := c.Serve()
-// if err != nil {
-// t.Errorf("error serving: %v", err)
-// }
-// }()
-// time.Sleep(time.Millisecond * 100)
-// defer c.Stop()
-//
-// req, err := http.NewRequest("PRI", "http://localhost:6029?hello=world", nil)
-// if err != nil {
-// return err
-// }
-//
-// req.Header.Add("Upgrade", "h2c")
-// req.Header.Add("Connection", "HTTP2-Settings")
-// req.Header.Add("HTTP2-Settings", "")
-//
-// r, err2 := http.DefaultClient.Do(req)
-// if err2 != nil {
-// return err2
-// }
-//
-// assert.Equal(t, "101 Switching Protocols", r.Status)
-//
-// err3 := r.Body.Close()
-// if err3 != nil {
-// return err3
-// }
-// return nil
-// }, bkoff)
-//
-// if err != nil {
-// t.Fatal(err)
-// }
-//}
diff --git a/plugins/http/tests/http_test.go b/plugins/http/tests/http_test.go
index 4f43ca1e..47ad0e51 100644
--- a/plugins/http/tests/http_test.go
+++ b/plugins/http/tests/http_test.go
@@ -4,11 +4,11 @@ import (
"bytes"
"crypto/tls"
"io/ioutil"
- "net"
"net/http"
"net/http/httptest"
"os"
"os/signal"
+ "sync"
"syscall"
"testing"
"time"
@@ -17,6 +17,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/yookoala/gofast"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/spiral/roadrunner/v2/plugins/server"
@@ -60,30 +61,37 @@ func TestHTTPInit(t *testing.T) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
- tt := time.NewTimer(time.Second * 1000)
- for {
- select {
- case e := <-ch:
- assert.Fail(t, "error", e.Error.Error())
- err = cont.Stop()
- if err != nil {
- assert.FailNow(t, "error", err.Error())
- }
- case <-sig:
- err = cont.Stop()
- if err != nil {
- assert.FailNow(t, "error", err.Error())
- }
- return
- case <-tt.C:
- // timeout
- err = cont.Stop()
- if err != nil {
- assert.FailNow(t, "error", err.Error())
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+ go func() {
+ tt := time.NewTimer(time.Second * 2)
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-tt.C:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
}
- return
}
- }
+ }()
+
+ wg.Wait()
}
func TestSSL(t *testing.T) {
@@ -115,8 +123,11 @@ func TestSSL(t *testing.T) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
go func() {
- tt := time.NewTimer(time.Second * 1000)
+ tt := time.NewTimer(time.Second * 5)
+ defer wg.Done()
for {
select {
case e := <-ch:
@@ -143,10 +154,35 @@ func TestSSL(t *testing.T) {
}()
t.Run("SSLEcho", sslEcho)
+ t.Run("SSLNoRedirect", sslNoRedirect)
+ t.Run("fCGIecho", fcgiEcho)
+ wg.Wait()
+}
+
+func sslNoRedirect(t *testing.T) {
+ req, err := http.NewRequest("GET", "http://localhost:8085?hello=world", nil)
+ assert.NoError(t, err)
+
+ r, err := sslClient.Do(req)
+ assert.NoError(t, err)
+
+ assert.Nil(t, r.TLS)
+
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+
+ assert.NoError(t, err)
+ assert.Equal(t, 201, r.StatusCode)
+ assert.Equal(t, "WORLD", string(b))
+
+ err2 := r.Body.Close()
+ if err2 != nil {
+ t.Errorf("fail to close the Body: error %v", err2)
+ }
}
func sslEcho(t *testing.T) {
- req, err := http.NewRequest("GET", "https://localhost:8888?hello=world", nil)
+ req, err := http.NewRequest("GET", "https://localhost:8893?hello=world", nil)
assert.NoError(t, err)
r, err := sslClient.Do(req)
@@ -165,12 +201,31 @@ func sslEcho(t *testing.T) {
}
}
-func TestFastCGI(t *testing.T) {
+func fcgiEcho(t *testing.T) {
+ fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6920")
+
+ fcgiHandler := gofast.NewHandler(
+ gofast.BasicParamsMap(gofast.BasicSession),
+ gofast.SimpleClientFactory(fcgiConnFactory, 0),
+ )
+
+ w := httptest.NewRecorder()
+ req := httptest.NewRequest("GET", "http://site.local/?hello=world", nil)
+ fcgiHandler.ServeHTTP(w, req)
+
+ body, err := ioutil.ReadAll(w.Result().Body)
+
+ assert.NoError(t, err)
+ assert.Equal(t, 201, w.Result().StatusCode)
+ assert.Equal(t, "WORLD", string(body))
+}
+
+func TestSSLRedirect(t *testing.T) {
cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, ""))
assert.NoError(t, err)
cfg := &config.Viper{
- Path: "configs/.rr-fcgi.yaml",
+ Path: "configs/.rr-ssl-redirect.yaml",
Prefix: "rr",
}
@@ -194,8 +249,11 @@ func TestFastCGI(t *testing.T) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
go func() {
- tt := time.NewTimer(time.Second * 1000)
+ tt := time.NewTimer(time.Second * 5)
+ defer wg.Done()
for {
select {
case e := <-ch:
@@ -221,40 +279,371 @@ func TestFastCGI(t *testing.T) {
}
}()
- t.Run("FastCGIEcho", fcgiEcho)
+ t.Run("SSLRedirect", sslRedirect)
+ wg.Wait()
}
-func fcgiEcho(t *testing.T) {
- conn, err := net.Dial("tcp", "0.0.0.0:6920")
+func sslRedirect(t *testing.T) {
+ req, err := http.NewRequest("GET", "http://localhost:8087?hello=world", nil)
+ assert.NoError(t, err)
+
+ r, err := sslClient.Do(req)
+ assert.NoError(t, err)
+ assert.NotNil(t, r.TLS)
+
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+
+ assert.NoError(t, err)
+ assert.Equal(t, 201, r.StatusCode)
+ assert.Equal(t, "WORLD", string(b))
+
+ err2 := r.Body.Close()
+ if err2 != nil {
+ t.Errorf("fail to close the Body: error %v", err2)
+ }
+}
+
+func TestSSLPushPipes(t *testing.T) {
+ time.Sleep(time.Second)
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, ""))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-ssl-push.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
if err != nil {
t.Fatal(err)
}
- _, err = conn.Write([]byte("data"))
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+ go func() {
+ tt := time.NewTimer(time.Second * 5)
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-tt.C:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ t.Run("SSLPush", sslPush)
+ wg.Wait()
+}
+
+func sslPush(t *testing.T) {
+ req, err := http.NewRequest("GET", "https://localhost:8894?hello=world", nil)
+ assert.NoError(t, err)
+
+ r, err := sslClient.Do(req)
+ assert.NoError(t, err)
+
+ assert.NotNil(t, r.TLS)
+
+ b, err := ioutil.ReadAll(r.Body)
+ assert.NoError(t, err)
+
+ assert.Equal(t, "", r.Header.Get("Http2-Push"))
+
+ assert.NoError(t, err)
+ assert.Equal(t, 201, r.StatusCode)
+ assert.Equal(t, "WORLD", string(b))
+
+ err2 := r.Body.Close()
+ if err2 != nil {
+ t.Errorf("fail to close the Body: error %v", err2)
+ }
+}
+
+func TestFastCGI_RequestUri(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, ""))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-fcgi-reqUri.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
if err != nil {
t.Fatal(err)
}
- //fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6920")
- //
- //fcgiHandler := gofast.NewHandler(
- // gofast.BasicParamsMap(gofast.BasicSession),
- // gofast.SimpleClientFactory(fcgiConnFactory, 0),
- //)
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+ go func() {
+ tt := time.NewTimer(time.Second * 5)
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-tt.C:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ t.Run("FastCGIServiceRequestUri", fcgiReqUri)
+ wg.Wait()
+}
+
+func fcgiReqUri(t *testing.T) {
+ fcgiConnFactory := gofast.SimpleConnFactory("tcp", "0.0.0.0:6921")
+
+ fcgiHandler := gofast.NewHandler(
+ gofast.BasicParamsMap(gofast.BasicSession),
+ gofast.SimpleClientFactory(fcgiConnFactory, 0),
+ )
w := httptest.NewRecorder()
- //req := httptest.NewRequest("GET", "http://site.local/?hello=world", nil)
- //err = fcgi.Serve(, req)
- //if err != nil {
- // t.Fatal(err)
- //}
- //fcgiHandler.ServeHTTP(w, req)
+ req := httptest.NewRequest("GET", "http://site.local/hello-world", nil)
+ fcgiHandler.ServeHTTP(w, req)
body, err := ioutil.ReadAll(w.Result().Body)
+ assert.NoError(t, err)
+ assert.Equal(t, 200, w.Result().StatusCode)
+ assert.Equal(t, "http://site.local/hello-world", string(body))
+}
+func TestH2CUpgrade(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, ""))
assert.NoError(t, err)
- assert.Equal(t, 201, w.Result().StatusCode)
- assert.Equal(t, "WORLD", string(body))
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-h2c.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ tt := time.NewTimer(time.Second * 5)
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-tt.C:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ t.Run("H2cUpgrade", h2cUpgrade)
+ wg.Wait()
+}
+
+func h2cUpgrade(t *testing.T) {
+ req, err := http.NewRequest("PRI", "http://localhost:8083?hello=world", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ req.Header.Add("Upgrade", "h2c")
+ req.Header.Add("Connection", "HTTP2-Settings")
+ req.Header.Add("HTTP2-Settings", "")
+
+ r, err2 := http.DefaultClient.Do(req)
+ if err2 != nil {
+ t.Fatal(err)
+ }
+
+ assert.Equal(t, "101 Switching Protocols", r.Status)
+
+ err3 := r.Body.Close()
+ if err3 != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestH2C(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel), endure.Visualize(endure.StdOut, ""))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-h2c.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ tt := time.NewTimer(time.Second * 5)
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-tt.C:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ t.Run("H2c", h2c)
+ wg.Wait()
+}
+
+func h2c(t *testing.T) {
+ req, err := http.NewRequest("PRI", "http://localhost:8083?hello=world", nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ req.Header.Add("Connection", "HTTP2-Settings")
+ req.Header.Add("HTTP2-Settings", "")
+
+ r, err2 := http.DefaultClient.Do(req)
+ if err2 != nil {
+ t.Fatal(err)
+ }
+
+ assert.Equal(t, "201 Created", r.Status)
+
+ err3 := r.Body.Close()
+ if err3 != nil {
+ t.Fatal(err)
+ }
}
func get(url string) (string, *http.Response, error) {
diff --git a/plugins/http/tests/plugin_test.go b/plugins/http/tests/plugin_test_old.go
index 852e5545..852e5545 100644
--- a/plugins/http/tests/plugin_test.go
+++ b/plugins/http/tests/plugin_test_old.go
diff --git a/plugins/http/tests/rpc_test.go b/plugins/http/tests/rpc_test_old.go
index 925aa082..925aa082 100644
--- a/plugins/http/tests/rpc_test.go
+++ b/plugins/http/tests/rpc_test_old.go
diff --git a/plugins/http/tests/ssl_test.go b/plugins/http/tests/ssl_test.go
deleted file mode 100644
index ee0e6e98..00000000
--- a/plugins/http/tests/ssl_test.go
+++ /dev/null
@@ -1,178 +0,0 @@
-package tests
-
-//func Test_SSL_Service_NoRedirect(t *testing.T) {
-// logger, _ := test.NewNullLogger()
-// logger.SetLevel(logrus.DebugLevel)
-//
-// c := service.NewContainer(logger)
-// c.Register(ID, &Service{})
-//
-// assert.NoError(t, c.Init(&testCfg{httpCfg: `{
-// "address": ":6030",
-// "ssl": {
-// "port": 6901,
-// "key": "fixtures/server.key",
-// "cert": "fixtures/server.crt"
-// },
-// "workers":{
-// "command": "php ../../tests/http/client.php echo pipes",
-// "pool": {"numWorkers": 1}
-// }
-// }`}))
-//
-// s, st := c.Get(ID)
-// assert.NotNil(t, s)
-// assert.Equal(t, service.StatusOK, st)
-//
-// // should do nothing
-// s.(*Service).Stop()
-//
-// go func() {
-// err := c.Serve()
-// if err != nil {
-// t.Errorf("error during the Serve: error %v", err)
-// }
-// }()
-//
-// time.Sleep(time.Millisecond * 500)
-//
-// req, err := http.NewRequest("GET", "http://localhost:6030?hello=world", nil)
-// assert.NoError(t, err)
-//
-// r, err := sslClient.Do(req)
-// assert.NoError(t, err)
-//
-// assert.Nil(t, r.TLS)
-//
-// b, err := ioutil.ReadAll(r.Body)
-// assert.NoError(t, err)
-//
-// assert.NoError(t, err)
-// assert.Equal(t, 201, r.StatusCode)
-// assert.Equal(t, "WORLD", string(b))
-//
-// err2 := r.Body.Close()
-// if err2 != nil {
-// t.Errorf("fail to close the Body: error %v", err2)
-// }
-// c.Stop()
-//}
-//
-//func Test_SSL_Service_Redirect(t *testing.T) {
-// logger, _ := test.NewNullLogger()
-// logger.SetLevel(logrus.DebugLevel)
-//
-// c := service.NewContainer(logger)
-// c.Register(ID, &Service{})
-//
-// assert.NoError(t, c.Init(&testCfg{httpCfg: `{
-// "address": ":6831",
-// "ssl": {
-// "port": 6902,
-// "redirect": true,
-// "key": "fixtures/server.key",
-// "cert": "fixtures/server.crt"
-// },
-// "workers":{
-// "command": "php ../../tests/http/client.php echo pipes",
-// "pool": {"numWorkers": 1}
-// }
-// }`}))
-//
-// s, st := c.Get(ID)
-// assert.NotNil(t, s)
-// assert.Equal(t, service.StatusOK, st)
-//
-// // should do nothing
-// s.(*Service).Stop()
-//
-// go func() {
-// err := c.Serve()
-// if err != nil {
-// t.Errorf("error during the Serve: error %v", err)
-// }
-// }()
-//
-// time.Sleep(time.Millisecond * 500)
-//
-// req, err := http.NewRequest("GET", "http://localhost:6831?hello=world", nil)
-// assert.NoError(t, err)
-//
-// r, err := sslClient.Do(req)
-// assert.NoError(t, err)
-// assert.NotNil(t, r.TLS)
-//
-// b, err := ioutil.ReadAll(r.Body)
-// assert.NoError(t, err)
-//
-// assert.NoError(t, err)
-// assert.Equal(t, 201, r.StatusCode)
-// assert.Equal(t, "WORLD", string(b))
-//
-// err2 := r.Body.Close()
-// if err2 != nil {
-// t.Errorf("fail to close the Body: error %v", err2)
-// }
-// c.Stop()
-//}
-//
-//func Test_SSL_Service_Push(t *testing.T) {
-// logger, _ := test.NewNullLogger()
-// logger.SetLevel(logrus.DebugLevel)
-//
-// c := service.NewContainer(logger)
-// c.Register(ID, &Service{})
-//
-// assert.NoError(t, c.Init(&testCfg{httpCfg: `{
-// "address": ":6032",
-// "ssl": {
-// "port": 6903,
-// "redirect": true,
-// "key": "fixtures/server.key",
-// "cert": "fixtures/server.crt"
-// },
-// "workers":{
-// "command": "php ../../tests/http/client.php push pipes",
-// "pool": {"numWorkers": 1}
-// }
-// }`}))
-//
-// s, st := c.Get(ID)
-// assert.NotNil(t, s)
-// assert.Equal(t, service.StatusOK, st)
-//
-// // should do nothing
-// s.(*Service).Stop()
-//
-// go func() {
-// err := c.Serve()
-// if err != nil {
-// t.Errorf("error during the Serve: error %v", err)
-// }
-// }()
-// time.Sleep(time.Millisecond * 500)
-//
-// req, err := http.NewRequest("GET", "https://localhost:6903?hello=world", nil)
-// assert.NoError(t, err)
-//
-// r, err := sslClient.Do(req)
-// assert.NoError(t, err)
-//
-// assert.NotNil(t, r.TLS)
-//
-// b, err := ioutil.ReadAll(r.Body)
-// assert.NoError(t, err)
-//
-// assert.Equal(t, "", r.Header.Get("Http2-Push"))
-//
-// assert.NoError(t, err)
-// assert.Equal(t, 201, r.StatusCode)
-// assert.Equal(t, "WORLD", string(b))
-//
-//
-// err2 := r.Body.Close()
-// if err2 != nil {
-// t.Errorf("fail to close the Body: error %v", err2)
-// }
-// c.Stop()
-//}
diff --git a/plugins/http/tests/uploads_test.go b/plugins/http/tests/uploads_test.go
index 770e447f..ee244c06 100644
--- a/plugins/http/tests/uploads_test.go
+++ b/plugins/http/tests/uploads_test.go
@@ -371,11 +371,11 @@ func mustOpen(f string) *os.File {
}
type fInfo struct {
- Name string `json:"name"`
- Size int64 `json:"size"`
- Mime string `json:"mime"`
- Error int `json:"error"`
- MD5 string `json:"md5,omitempty"`
+ Name string `json:"name"`
+ Size int64 `json:"size"`
+ Mime string `json:"mime"`
+ Error int `json:"error"`
+ Sha512 string `json:"sha512,omitempty"`
}
func fileString(f string, errNo int, mime string) string {
@@ -403,15 +403,15 @@ func fileString(f string, errNo int, mime string) string {
}
v := &fInfo{
- Name: s.Name(),
- Size: s.Size(),
- Error: errNo,
- Mime: mime,
- MD5: hex.EncodeToString(h.Sum(nil)),
+ Name: s.Name(),
+ Size: s.Size(),
+ Error: errNo,
+ Mime: mime,
+ Sha512: hex.EncodeToString(h.Sum(nil)),
}
if errNo != 0 {
- v.MD5 = ""
+ v.Sha512 = ""
v.Size = 0
}