Skip to content

Commit

Permalink
Fix operator list config
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
  • Loading branch information
Jarema committed Sep 17, 2024
1 parent cec21b7 commit 0104407
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,22 @@ func (o *Options) processConfigFileLine(k string, v any, errors *[]error, warnin
opFiles = append(opFiles, v)
case []string:
opFiles = append(opFiles, v...)
case []any:
for _, t := range v {
if token, ok := t.(token); ok {
if v, ok := token.Value().(string); ok {
opFiles = append(opFiles, v)
continue
} else {
err := &configErr{tk, fmt.Sprintf("error parsing operators: unsupported type %T where string is expected", token)}
*errors = append(*errors, err)
}
} else {
err := &configErr{tk, fmt.Sprintf("error parsing operators: unsupported type %T", t)}
*errors = append(*errors, err)
}
break
}
default:
err := &configErr{tk, fmt.Sprintf("error parsing operators: unsupported type %T", v)}
*errors = append(*errors, err)
Expand Down
26 changes: 26 additions & 0 deletions server/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,32 @@ func TestReadOperatorJWT(t *testing.T) {
}
}

const operatorJwtList = `
listen: "127.0.0.1:-1"
system_account = SYSACC
operator: [
eyJ0eXAiOiJqd3QiLCJhbGciOiJlZDI1NTE5In0.eyJqdGkiOiJJVEdJNjNCUUszM1VNN1pBSzZWT1RXNUZEU01ESlNQU1pRQ0RMNUlLUzZQTVhBU0ROQ01RIiwiaWF0IjoxNTg5ODM5MjA1LCJpc3MiOiJPQ1k2REUyRVRTTjNVT0RGVFlFWEJaTFFMSTdYNEdTWFI1NE5aQzRCQkxJNlFDVFpVVDY1T0lWTiIsIm5hbWUiOiJPUCIsInN1YiI6Ik9DWTZERTJFVFNOM1VPREZUWUVYQlpMUUxJN1g0R1NYUjU0TlpDNEJCTEk2UUNUWlVUNjVPSVZOIiwidHlwZSI6Im9wZXJhdG9yIiwibmF0c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fFile(t, []byte(operatorJwtList))
opts, err := ProcessConfigFile(confFileName)
if err != nil {
t.Fatalf("Received unexpected error %s", err)
}

require_True(t, len(opts.TrustedOperators) == 2)
require_True(t, opts.TrustedOperators[0].Name == "OP")
require_True(t, opts.TrustedOperators[1].Name == "op2")
require_True(t, opts.TrustedOperators[0].SystemAccount == "ADZ547B24WHPLWOK7TMLNBSA7FQFXR6UM2NZ4HHNIB7RDFVZQFOZ4GQQ")
require_True(t, opts.TrustedOperators[1].SystemAccount == "ACQTWVGSGHYVY3R6D2WMO3V6LV2MGK5B7G47E43BHJB6FQVY7EHNTMMG")
// check if system account precedence is correct
require_True(t, opts.SystemAccount == "SYSACC")

}

// using memory resolver so this test does not have to start the memory resolver
const operatorJwtWithSysAccAndMemResolver = `
listen: "127.0.0.1:-1"
Expand Down

0 comments on commit 0104407

Please sign in to comment.