diff options
Diffstat (limited to 'service/static')
-rw-r--r-- | service/static/config.go | 7 | ||||
-rw-r--r-- | service/static/config_test.go | 7 | ||||
-rw-r--r-- | service/static/service.go | 10 | ||||
-rw-r--r-- | service/static/service_test.go | 16 |
4 files changed, 21 insertions, 19 deletions
diff --git a/service/static/config.go b/service/static/config.go index be0ac3ed..5df7b013 100644 --- a/service/static/config.go +++ b/service/static/config.go @@ -10,9 +10,6 @@ import ( // Config describes file location and controls access to them. type Config struct { - // Enables StaticFile service. - Enable bool - // Dir contains name of directory to control access to. Dir string @@ -32,10 +29,6 @@ func (c *Config) Hydrate(cfg service.Config) error { // Valid returns nil if config is valid. func (c *Config) Valid() error { - if !c.Enable { - return nil - } - st, err := os.Stat(c.Dir) if err != nil { if os.IsNotExist(err) { diff --git a/service/static/config_test.go b/service/static/config_test.go index d36726c2..e3fa8d16 100644 --- a/service/static/config_test.go +++ b/service/static/config_test.go @@ -36,8 +36,7 @@ func TestConfig_Forbids(t *testing.T) { } func TestConfig_Valid(t *testing.T) { - assert.NoError(t, (&Config{Enable: true, Dir: "./"}).Valid()) - assert.Error(t, (&Config{Enable: true, Dir: "./config.go"}).Valid()) - assert.NoError(t, (&Config{Dir: "./dir/"}).Valid()) - assert.Error(t, (&Config{Enable: true, Dir: "./dir/"}).Valid()) + assert.NoError(t, (&Config{Dir: "./"}).Valid()) + assert.Error(t, (&Config{Dir: "./config.go"}).Valid()) + assert.Error(t, (&Config{Dir: "./dir/"}).Valid()) } diff --git a/service/static/service.go b/service/static/service.go index 98d8313c..b2723e42 100644 --- a/service/static/service.go +++ b/service/static/service.go @@ -4,7 +4,6 @@ import ( rrttp "github.com/spiral/roadrunner/service/http" "net/http" "path" - "strings" ) // ID contains default service name. @@ -22,7 +21,7 @@ type Service struct { // Init must return configure service and return true if service hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. func (s *Service) Init(cfg *Config, r *rrttp.Service) (bool, error) { - if !cfg.Enable || r == nil { + if r == nil { return false, nil } @@ -44,12 +43,7 @@ func (s *Service) middleware(f http.HandlerFunc) http.HandlerFunc { } func (s *Service) handleStatic(w http.ResponseWriter, r *http.Request) bool { - fPath := r.URL.Path - - if !strings.HasPrefix(fPath, "/") { - fPath = "/" + fPath - } - fPath = path.Clean(fPath) + fPath := path.Clean(r.URL.Path) if s.cfg.Forbids(fPath) { return false diff --git a/service/static/service_test.go b/service/static/service_test.go index 7b40b8ad..fbc26a58 100644 --- a/service/static/service_test.go +++ b/service/static/service_test.go @@ -84,6 +84,22 @@ func Test_Files(t *testing.T) { assert.Equal(t, "sample", b) } +func Test_Disabled(t *testing.T) { + logger, _ := test.NewNullLogger() + logger.SetLevel(logrus.DebugLevel) + + c := service.NewContainer(logger) + c.Register(ID, &Service{}) + + assert.NoError(t, c.Init(&testCfg{ + static: `{"enable":true, "dir":"../../tests", "forbid":[]}`, + })) + + s, st := c.Get(ID) + assert.NotNil(t, s) + assert.Equal(t, service.StatusRegistered, st) +} + func Test_Files_Disable(t *testing.T) { logger, _ := test.NewNullLogger() logger.SetLevel(logrus.DebugLevel) |