(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestSettingsList(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | |
| 21 | scenarios := []tests.ApiScenario{ |
| 22 | { |
| 23 | Name: "unauthorized", |
| 24 | Method: http.MethodGet, |
| 25 | URL: "/api/settings", |
| 26 | ExpectedStatus: 401, |
| 27 | ExpectedContent: []string{`"data":{}`}, |
| 28 | ExpectedEvents: map[string]int{"*": 0}, |
| 29 | }, |
| 30 | { |
| 31 | Name: "authorized as regular user", |
| 32 | Method: http.MethodGet, |
| 33 | URL: "/api/settings", |
| 34 | Headers: map[string]string{ |
| 35 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyNTI0NjA0NDYxLCJyZWZyZXNoYWJsZSI6dHJ1ZX0.ZT3F0Z3iM-xbGgSG3LEKiEzHrPHr8t8IuHLZGGNuxLo", |
| 36 | }, |
| 37 | ExpectedStatus: 403, |
| 38 | ExpectedContent: []string{`"data":{}`}, |
| 39 | ExpectedEvents: map[string]int{"*": 0}, |
| 40 | }, |
| 41 | { |
| 42 | Name: "authorized as superuser", |
| 43 | Method: http.MethodGet, |
| 44 | URL: "/api/settings", |
| 45 | Headers: map[string]string{ |
| 46 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY", |
| 47 | }, |
| 48 | ExpectedStatus: 200, |
| 49 | ExpectedContent: []string{ |
| 50 | `"meta":{`, |
| 51 | `"logs":{`, |
| 52 | `"smtp":{`, |
| 53 | `"s3":{`, |
| 54 | `"backups":{`, |
| 55 | `"batch":{`, |
| 56 | }, |
| 57 | ExpectedEvents: map[string]int{ |
| 58 | "*": 0, |
| 59 | "OnSettingsListRequest": 1, |
| 60 | }, |
| 61 | }, |
| 62 | { |
| 63 | Name: "OnSettingsListRequest tx body write check", |
| 64 | Method: http.MethodGet, |
| 65 | URL: "/api/settings", |
| 66 | Headers: map[string]string{ |
| 67 | "Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhdXRoIiwiY29sbGVjdGlvbklkIjoicGJjXzMxNDI2MzU4MjMiLCJleHAiOjI1MjQ2MDQ0NjEsInJlZnJlc2hhYmxlIjp0cnVlfQ.UXgO3j-0BumcugrFjbd7j0M4MQvbrLggLlcu_YNGjoY", |
| 68 | }, |
| 69 | BeforeTestFunc: func(t testing.TB, app *tests.TestApp, e *core.ServeEvent) { |
| 70 | app.OnSettingsListRequest().BindFunc(func(e *core.SettingsListRequestEvent) error { |
| 71 | original := e.App |
| 72 | return e.App.RunInTransaction(func(txApp core.App) error { |
| 73 | e.App = txApp |
| 74 | defer func() { e.App = original }() |
| 75 |
nothing calls this directly
no test coverage detected
searching dependent graphs…