mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Backend Plugins: Provide proper plugin config to plugins (#21985)
Properly provides plugin configs to backend plugins. Uses v0.16.0 of grafana-plugin-sdk-go- Ref #21512 Ref #19667
This commit is contained in:
committed by
GitHub
parent
f82a6aa0d0
commit
9d7c74ef91
62
pkg/models/plugin_setting_cache_test.go
Normal file
62
pkg/models/plugin_setting_cache_test.go
Normal file
@@ -0,0 +1,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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user