Skip to content

Commit

Permalink
More review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Jan 29, 2025
1 parent b00ee41 commit aeef1f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
10 changes: 7 additions & 3 deletions cmd/outline-ss-server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ func (c *ListenerConfig) UnmarshalYAML(value *yaml.Node) error {
if !ok {
return errors.New("`type` field required")
}
lnTypeStr, ok := rawType.(string)
if !ok {
return fmt.Errorf("`type` is not a string, but %T", rawType)
}
lnType := ListenerType(lnTypeStr)
delete(raw, "type")

lnType := ListenerType(rawType.(string))
fieldName, ok := listenerTypeMap[lnType]
if !ok {
return fmt.Errorf("invalid listener type: %v", lnType)
Expand Down Expand Up @@ -123,8 +127,8 @@ func (c *ListenerConfig) validate() error {
if field.Kind() == reflect.Ptr && field.IsNil() {
continue
}
if field.Type().Implements(reflect.TypeOf((*Validator)(nil)).Elem()) {
if err := field.Interface().(Validator).validate(); err != nil {
if validator, ok := field.Interface().(Validator); ok {
if err := validator.validate(); err != nil {
return fmt.Errorf("invalid config: %v", err)
}
}
Expand Down
21 changes: 18 additions & 3 deletions cmd/outline-ss-server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@ func TestConfigValidate(t *testing.T) {
t.Run("InvalidConfig/InvalidListenerType", func(t *testing.T) {
yaml := `
services:
- listeners:
- type: foo
address: "[::]:9000"
- listeners:
- type:
- tcp
- udp
address: "[::]:9000"
`

_, err := readConfig([]byte(yaml))

require.Error(t, err)
})

t.Run("InvalidConfig/UnknownListenerType", func(t *testing.T) {
yaml := `
services:
- listeners:
- type: foo
address: "[::]:9000"
`

_, err := readConfig([]byte(yaml))
Expand Down

0 comments on commit aeef1f2

Please sign in to comment.