mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-26 21:21:54 +08:00
fix: error if rule has no regex or path
This commit is contained in:
@@ -192,6 +192,26 @@ cors:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigRules(t *testing.T) {
|
func TestConfigRules(t *testing.T) {
|
||||||
|
t.Run("Only Regex or Path", func(t *testing.T) {
|
||||||
|
content := `
|
||||||
|
directory: /
|
||||||
|
rules:
|
||||||
|
- regex: '^.+\.js$'
|
||||||
|
path: /public/access/`
|
||||||
|
|
||||||
|
writeAndParseConfigWithError(t, content, ".yaml", "cannot define both regex and path")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Regex or Path Required", func(t *testing.T) {
|
||||||
|
content := `
|
||||||
|
directory: /
|
||||||
|
rules:
|
||||||
|
- permissions: CRUD`
|
||||||
|
|
||||||
|
writeAndParseConfigWithError(t, content, ".yaml", "must either define a path of a regex")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Parse", func(t *testing.T) {
|
||||||
content := `
|
content := `
|
||||||
directory: /
|
directory: /
|
||||||
rules:
|
rules:
|
||||||
@@ -210,6 +230,8 @@ rules:
|
|||||||
|
|
||||||
require.NotEmpty(t, cfg.Rules[1].Path)
|
require.NotEmpty(t, cfg.Rules[1].Path)
|
||||||
require.Nil(t, cfg.Rules[1].Regex)
|
require.Nil(t, cfg.Rules[1].Regex)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigEnv(t *testing.T) {
|
func TestConfigEnv(t *testing.T) {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ type Rule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Rule) Validate() error {
|
func (r *Rule) Validate() error {
|
||||||
|
if r.Regex == nil && r.Path == "" {
|
||||||
|
return errors.New("invalid rule: must either define a path of a regex")
|
||||||
|
}
|
||||||
|
|
||||||
if r.Regex != nil && r.Path != "" {
|
if r.Regex != nil && r.Path != "" {
|
||||||
return errors.New("invalid rule: cannot define both regex and path")
|
return errors.New("invalid rule: cannot define both regex and path")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user