Unit test to ensure only SELECT queries can run
(t *testing.T)
| 222 | |
| 223 | // Unit test to ensure only SELECT queries can run |
| 224 | func 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 | } |
nothing calls this directly
no test coverage detected