summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-03 19:39:37 +0300
committerValery Piashchynski <[email protected]>2021-06-03 19:39:37 +0300
commit3b06949c7e9a1fc5b2aec7529a97320a6f398535 (patch)
tree606fc636933e686762354aadde7ee171aa861094
parent9c01e7ab1548e1416598b702d63866fa6dc5707b (diff)
- Use fcgi in the applyMiddlewares for the fcgi, not https
- Add tests
-rw-r--r--plugins/http/serve.go2
-rw-r--r--tests/plugins/http/configs/.rr-fcgi-reqUri.yaml8
-rw-r--r--tests/plugins/http/configs/.rr-fcgi.yaml18
-rw-r--r--tests/plugins/http/configs/.rr-http-static.yaml4
-rw-r--r--tests/plugins/http/http_plugin_test.go88
5 files changed, 96 insertions, 24 deletions
diff --git a/plugins/http/serve.go b/plugins/http/serve.go
index bf1ccafe..6d3f2228 100644
--- a/plugins/http/serve.go
+++ b/plugins/http/serve.go
@@ -73,7 +73,7 @@ func (p *Plugin) serveFCGI(errCh chan error) {
const op = errors.Op("serveFCGI")
if len(p.mdwr) > 0 {
- applyMiddlewares(p.https, p.mdwr, p.cfg.Middleware, p.log)
+ applyMiddlewares(p.fcgi, p.mdwr, p.cfg.Middleware, p.log)
}
l, err := utils.CreateListener(p.cfg.FCGIConfig.Address)
diff --git a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
index 28c70c6f..cbdd211e 100644
--- a/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
+++ b/tests/plugins/http/configs/.rr-fcgi-reqUri.yaml
@@ -1,16 +1,12 @@
server:
command: "php ../../http/client.php request-uri pipes"
- user: ""
- group: ""
- env:
- "RR_HTTP": "true"
relay: "pipes"
relay_timeout: "20s"
http:
address: :8082
max_request_size: 1024
- middleware: [ "" ]
+ middleware: [ ]
uploads:
forbid: [ ".php", ".exe", ".bat" ]
trusted_subnets: [ "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" ]
@@ -33,4 +29,4 @@ http:
maxConcurrentStreams: 128
logs:
mode: development
- level: error \ No newline at end of file
+ level: error
diff --git a/tests/plugins/http/configs/.rr-fcgi.yaml b/tests/plugins/http/configs/.rr-fcgi.yaml
index c749e42b..b0060d85 100644
--- a/tests/plugins/http/configs/.rr-fcgi.yaml
+++ b/tests/plugins/http/configs/.rr-fcgi.yaml
@@ -1,16 +1,16 @@
server:
command: "php ../../http/client.php echo pipes"
- user: ""
- group: ""
- env:
- "RR_HTTP": "true"
relay: "pipes"
relay_timeout: "20s"
http:
address: :8081
max_request_size: 1024
- middleware: [ "" ]
+ middleware: [ "gzip" ]
+ static:
+ dir: "../../../tests"
+ forbid: [ "" ]
+ allow: [ ".txt", ".php" ]
uploads:
forbid: [ ".php", ".exe", ".bat" ]
trusted_subnets: [ "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" ]
@@ -20,12 +20,6 @@ http:
allocate_timeout: 60s
destroy_timeout: 60s
- ssl:
- address: :8889
- redirect: false
- cert: fixtures/server.crt
- key: fixtures/server.key
- # root_ca: root.crt
fcgi:
address: tcp://0.0.0.0:6920
http2:
@@ -33,4 +27,4 @@ http:
maxConcurrentStreams: 128
logs:
mode: development
- level: error \ No newline at end of file
+ level: error
diff --git a/tests/plugins/http/configs/.rr-http-static.yaml b/tests/plugins/http/configs/.rr-http-static.yaml
index e2e3af2a..30bb5b1e 100644
--- a/tests/plugins/http/configs/.rr-http-static.yaml
+++ b/tests/plugins/http/configs/.rr-http-static.yaml
@@ -1,9 +1,5 @@
server:
command: "php ../../http/client.php pid pipes"
- user: ""
- group: ""
- env:
- "RR_HTTP": "true"
relay: "pipes"
relay_timeout: "20s"
diff --git a/tests/plugins/http/http_plugin_test.go b/tests/plugins/http/http_plugin_test.go
index 128eec26..e3dba5d0 100644
--- a/tests/plugins/http/http_plugin_test.go
+++ b/tests/plugins/http/http_plugin_test.go
@@ -364,7 +364,7 @@ func TestSSL(t *testing.T) {
time.Sleep(time.Second * 1)
t.Run("SSLEcho", sslEcho)
t.Run("SSLNoRedirect", sslNoRedirect)
- t.Run("fCGIecho", fcgiEcho)
+ t.Run("FCGEcho", fcgiEcho)
stopCh <- struct{}{}
wg.Wait()
@@ -616,6 +616,92 @@ func sslPush(t *testing.T) {
}
}
+func TestFastCGI_Echo(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-fcgi.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &httpPlugin.Plugin{},
+ &static.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)
+
+ stopCh := make(chan struct{}, 1)
+
+ go func() {
+ 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 <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 1)
+ t.Run("FastCGIEcho", fcgiEcho1)
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
+
+func fcgiEcho1(t *testing.T) {
+ time.Sleep(time.Second * 2)
+ fcgiConnFactory := gofast.SimpleConnFactory("tcp", "127.0.0.1:6920")
+
+ fcgiHandler := gofast.NewHandler(
+ gofast.BasicParamsMap(gofast.BasicSession),
+ gofast.SimpleClientFactory(fcgiConnFactory),
+ )
+
+ w := httptest.NewRecorder()
+ req := httptest.NewRequest("GET", "http://site.local/hello-world", nil)
+ fcgiHandler.ServeHTTP(w, req)
+
+ _, err := ioutil.ReadAll(w.Result().Body) //nolint:bodyclose
+ assert.NoError(t, err)
+ assert.Equal(t, 201, w.Result().StatusCode) //nolint:bodyclose
+}
+
func TestFastCGI_RequestUri(t *testing.T) {
cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
assert.NoError(t, err)