forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_setting_cache_test.go
62 lines (49 loc) · 1.52 KB
/
plugin_setting_cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package models
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/securejsondata"
)
func TestPluginSettingDecryptionCache(t *testing.T) {
t.Run("When plugin settings hasn't been updated, encrypted JSON should be fetched from cache", func(t *testing.T) {
ClearPluginSettingDecryptionCache()
ps := PluginSetting{
Id: 1,
JsonData: map[string]interface{}{},
SecureJsonData: securejsondata.GetEncryptedJsonData(map[string]string{
"password": "password",
}),
}
// Populate cache
password, ok := ps.DecryptedValue("password")
require.Equal(t, "password", password)
require.True(t, ok)
ps.SecureJsonData = securejsondata.GetEncryptedJsonData(map[string]string{
"password": "",
})
require.Equal(t, "password", password)
require.True(t, ok)
})
t.Run("When plugin settings is updated, encrypted JSON should not be fetched from cache", func(t *testing.T) {
ClearPluginSettingDecryptionCache()
ps := PluginSetting{
Id: 1,
JsonData: map[string]interface{}{},
SecureJsonData: securejsondata.GetEncryptedJsonData(map[string]string{
"password": "password",
}),
}
// Populate cache
password, ok := ps.DecryptedValue("password")
require.Equal(t, "password", password)
require.True(t, ok)
ps.SecureJsonData = securejsondata.GetEncryptedJsonData(map[string]string{
"password": "",
})
ps.Updated = time.Now()
password, ok = ps.DecryptedValue("password")
require.Empty(t, password)
require.True(t, ok)
})
}