MCPcopy
hub / github.com/pocketbase/pocketbase / TestSQLRun

Function TestSQLRun

apis/sql_test.go:11–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestSQLRun(t *testing.T) {
12 t.Parallel()
13
14 scenarios := []tests.ApiScenario{
15 {
16 Name: "guest",
17 Method: http.MethodPost,
18 URL: "/api/sql",
19 Body: strings.NewReader(`{"query":"select 1"}`),
20 ExpectedStatus: 401,
21 ExpectedContent: []string{`"data":{}`},
22 ExpectedEvents: map[string]int{"*": 0},
23 },
24 {
25 Name: "regular user",
26 Method: http.MethodPost,
27 URL: "/api/sql",
28 Body: strings.NewReader(`{"query":"select 1"}`),
29 Headers: map[string]string{
30 // users, test2@example.com
31 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6Im9hcDY0MGNvdDR5cnUycyIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyNTI0NjA0NDYxLCJyZWZyZXNoYWJsZSI6dHJ1ZX0.GfJo6EHIobgas_AXt-M-tj5IoQendPnrkMSe9ExuSEY",
32 },
33 ExpectedStatus: 403,
34 ExpectedContent: []string{`"data":{}`},
35 ExpectedEvents: map[string]int{"*": 0},
36 },
37 {
38 Name: "superuser",
39 Method: http.MethodPost,
40 URL: "/api/sql",
41 Body: strings.NewReader(`{"query":"select 1"}`),
42 Headers: map[string]string{
43 // superusers, test@example.com
44 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY",
45 },
46 ExpectedStatus: 200,
47 ExpectedContent: []string{
48 `"execTime":`,
49 `"affectedRows":0`,
50 `"columns":[{"name":"1","type":"","nullable":true}]`,
51 `"rows":[["1"]]`,
52 },
53 ExpectedEvents: map[string]int{"*": 0},
54 },
55 {
56 Name: "empty query",
57 Method: http.MethodPost,
58 URL: "/api/sql",
59 Body: strings.NewReader(`{"query":""}`),
60 Headers: map[string]string{
61 // superusers, test@example.com
62 "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY",
63 },
64 ExpectedStatus: 400,
65 ExpectedContent: []string{
66 `"data":{`,
67 `"query":{`,
68 },

Callers

nothing calls this directly

Calls 5

NewReaderMethod · 0.80
NewQueryMethod · 0.80
TestMethod · 0.80
HasTableMethod · 0.65
DBMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…