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

Function TestUserN1QLQueriesInvalid

db/functions/n1ql_function_test.go:224–257  ·  view source on GitHub ↗

Unit test to ensure only SELECT queries can run

(t *testing.T)

Source from the content-addressed store, hash-verified

222
223// Unit test to ensure only SELECT queries can run
224func TestUserN1QLQueriesInvalid(t *testing.T) {
225 var kBadN1QLFunctionsConfig = FunctionsConfig{
226 Definitions: FunctionsDefs{
227 "evil_mutant": &FunctionConfig{
228 Type: "query",
229 Code: `DROP COLLECTION Students`,
230 Allow: &Allow{Channels: []string{"*"}},
231 },
232 },
233 }
234
235 _, err := CompileFunctions(base.TestCtx(t), kBadN1QLFunctionsConfig)
236 assert.ErrorContains(t, err, "only SELECT queries are allowed") // See fn validateN1QLQuery
237
238 var kOKN1QLFunctionsConfig = FunctionsConfig{
239 Definitions: FunctionsDefs{
240 "lowercase": &FunctionConfig{
241 Type: "query",
242 Code: `seleCt $args.city AS city`,
243 Args: []string{"city"},
244 Allow: &Allow{Channels: []string{"*"}},
245 },
246 "parens": &FunctionConfig{
247 Type: "query",
248 Code: ` (select $args.city AS city)`,
249 Args: []string{"city"},
250 Allow: &Allow{Channels: []string{"*"}},
251 },
252 },
253 }
254
255 _, err = CompileFunctions(base.TestCtx(t), kOKN1QLFunctionsConfig)
256 assert.NoError(t, err)
257}

Callers

nothing calls this directly

Calls 2

TestCtxFunction · 0.92
CompileFunctionsFunction · 0.85

Tested by

no test coverage detected