mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:38:50 +02:00
fix deserialization panics on empty map
This commit is contained in:
65
internal/route/provider/all_fields.yaml
Normal file
65
internal/route/provider/all_fields.yaml
Normal file
@@ -0,0 +1,65 @@
|
||||
example: # matching `example.y.z`
|
||||
scheme: http
|
||||
host: 10.0.0.254
|
||||
port: 80
|
||||
path_patterns: # Check https://pkg.go.dev/net/http#hdr-Patterns-ServeMux for syntax
|
||||
- GET / # accept any GET request
|
||||
- POST /auth # for /auth and /auth/* accept only POST
|
||||
- GET /home/{$} # for exactly /home
|
||||
healthcheck:
|
||||
disabled: false
|
||||
path: /
|
||||
interval: 5s
|
||||
load_balance:
|
||||
link: app
|
||||
mode: ip_hash
|
||||
options:
|
||||
header: X-Forwarded-For
|
||||
middlewares:
|
||||
cidr_whitelist:
|
||||
allow:
|
||||
- 127.0.0.1
|
||||
- 10.0.0.0/8
|
||||
status_code: 403
|
||||
message: IP not allowed
|
||||
hideXForwarded:
|
||||
homepage:
|
||||
name: Example App
|
||||
icon: png/example.png
|
||||
description: An example app
|
||||
category: example
|
||||
access_log:
|
||||
buffer_size: 100
|
||||
path: /var/log/example.log
|
||||
filters:
|
||||
status_codes:
|
||||
values:
|
||||
- 200-299
|
||||
- 101
|
||||
method:
|
||||
values:
|
||||
- GET
|
||||
host:
|
||||
values:
|
||||
- example.y.z
|
||||
headers:
|
||||
negative: true
|
||||
values:
|
||||
- foo=bar
|
||||
- baz
|
||||
cidr:
|
||||
values:
|
||||
- 192.168.10.0/24
|
||||
fields:
|
||||
headers:
|
||||
default: keep
|
||||
config:
|
||||
foo: redact
|
||||
query:
|
||||
default: drop
|
||||
config:
|
||||
foo: keep
|
||||
cookies:
|
||||
default: redact
|
||||
config:
|
||||
foo: keep
|
||||
@@ -31,8 +31,12 @@ func FileProviderImpl(filename string) (ProviderImpl, error) {
|
||||
return impl, nil
|
||||
}
|
||||
|
||||
func validate(data []byte) (route.RawEntries, E.Error) {
|
||||
return utils.DeserializeYAMLMap[*route.RawEntry](data)
|
||||
}
|
||||
|
||||
func Validate(data []byte) (err E.Error) {
|
||||
_, err = utils.DeserializeYAMLMap[*route.RawEntry](data)
|
||||
_, err = validate(data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -52,7 +56,7 @@ func (p *FileProvider) loadRoutesImpl() (route.Routes, E.Error) {
|
||||
return routes, E.From(err)
|
||||
}
|
||||
|
||||
entries, err := utils.DeserializeYAMLMap[*route.RawEntry](data)
|
||||
entries, err := validate(data)
|
||||
if err == nil {
|
||||
return route.FromEntries(entries)
|
||||
}
|
||||
|
||||
17
internal/route/provider/file_test.go
Normal file
17
internal/route/provider/file_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
_ "embed"
|
||||
|
||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||
)
|
||||
|
||||
//go:embed all_fields.yaml
|
||||
var yaml []byte
|
||||
|
||||
func TestFile(t *testing.T) {
|
||||
_, err := validate(yaml)
|
||||
ExpectNoError(t, err)
|
||||
}
|
||||
Reference in New Issue
Block a user