MCPcopy
hub / github.com/pocketbase/pocketbase / TestReloadSettingsWithEncryption

Function TestReloadSettingsWithEncryption

core/settings_query_test.go:79–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestReloadSettingsWithEncryption(t *testing.T) {
80 app, _ := tests.NewTestApp()
81 defer app.Cleanup()
82
83 os.Setenv("pb_test_env", strings.Repeat("a", 32))
84
85 // cleanup all stored settings
86 // ---
87 if _, err := app.DB().NewQuery("DELETE from _params;").Execute(); err != nil {
88 t.Fatalf("Failed to delete all test settings: %v", err)
89 }
90
91 // check if the new settings are saved in the db
92 // ---
93 app.Settings().Meta.AppName = "test_name_after_delete"
94
95 app.ResetEventCalls()
96 if err := app.ReloadSettings(); err != nil {
97 t.Fatalf("Failed to reload the settings after delete: %v", err)
98 }
99 testEventCalls(t, app, map[string]int{
100 "OnModelCreate": 1,
101 "OnModelCreateExecute": 1,
102 "OnModelAfterCreateSuccess": 1,
103 "OnModelValidate": 1,
104 "OnSettingsReload": 1,
105 })
106
107 param := &core.Param{}
108 err := app.ModelQuery(param).Model("settings", param)
109 if err != nil {
110 t.Fatalf("Expected new settings to be persisted, got %v", err)
111 }
112 rawValue := param.Value.String()
113 if rawValue == "" || strings.Contains(rawValue, "test_name") {
114 t.Fatalf("Expected inserted settings to be encrypted, found\n%s", rawValue)
115 }
116
117 // change and reload the app settings (ensure that there was no db update)
118 // ---
119 app.Settings().Meta.AppName = "test_name_after_update"
120 if err := app.Save(app.Settings()); err != nil {
121 t.Fatalf("Failed to update app settings: %v", err)
122 }
123
124 // try to reload again without doing any changes
125 // ---
126 app.ResetEventCalls()
127 if err := app.ReloadSettings(); err != nil {
128 t.Fatalf("Failed to reload app settings: %v", err)
129 }
130 testEventCalls(t, app, map[string]int{
131 "OnSettingsReload": 1,
132 })
133
134 // refetch the settings param to ensure that the new value was stored encrypted
135 err = app.ModelQuery(param).Model("settings", param)
136 if err != nil {

Callers

nothing calls this directly

Calls 13

CleanupMethod · 0.95
ResetEventCallsMethod · 0.95
NewTestAppFunction · 0.92
testEventCallsFunction · 0.85
ExecuteMethod · 0.80
NewQueryMethod · 0.80
ModelMethod · 0.80
DBMethod · 0.65
SettingsMethod · 0.65
ReloadSettingsMethod · 0.65
ModelQueryMethod · 0.65
SaveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…