MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / validateAllow

Method validateAllow

db/functions/function.go:226–257  ·  view source on GitHub ↗

AUTHORIZATION: Looks for bad '$' patterns in the config's Allow strings.

()

Source from the content-addressed store, hash-verified

224
225// Looks for bad '$' patterns in the config's Allow strings.
226func (fn *FunctionConfig) validateAllow() error {
227 if fn.Allow != nil {
228 // Construct an args object with a value for each declared argument:
229 fakeArgs := map[string]any{}
230 for _, argName := range fn.Args {
231 fakeArgs[argName] = "x"
232 }
233 // Subroutine that tests a pattern by trying to expand it with the args.
234 // If the result is a 500 error, something's wrong with the pattern itself.
235 checkPattern := func(pattern string) error {
236 _, err := expandPattern(pattern, fakeArgs, nil)
237 if err, ok := err.(*base.HTTPError); ok {
238 if err != nil && err.Status >= http.StatusInternalServerError {
239 return err
240 }
241 }
242 return nil
243 }
244 // Test each role and channel string:
245 for _, str := range fn.Allow.Roles {
246 if err := checkPattern(str); err != nil {
247 return err
248 }
249 }
250 for _, str := range fn.Allow.Channels {
251 if err := checkPattern(str); err != nil {
252 return err
253 }
254 }
255 }
256 return nil
257}
258
259// Authorizes a User against the function config's Allow object:
260// - The user's name must be contained in Users, OR

Callers 1

compileFunctionFunction · 0.80

Calls 1

expandPatternFunction · 0.85

Tested by

no test coverage detected