[MM-39999] Increase key length in plugin KV store to 150 (#19002)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b836edba40
Коммит
34c4e543f9
84
app/plugin_api_tests/test_kv/main.go
Обычный файл
84
app/plugin_api_tests/test_kv/main.go
Обычный файл
@@ -0,0 +1,84 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/app/plugin_api_tests"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MyPlugin struct {
|
||||||
|
plugin.MattermostPlugin
|
||||||
|
configuration plugin_api_tests.BasicConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MyPlugin) OnConfigurationChange() error {
|
||||||
|
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
|
||||||
|
data := []byte("some data")
|
||||||
|
|
||||||
|
appErr := p.API.KVSet("some_key", data)
|
||||||
|
if appErr != nil {
|
||||||
|
return nil, appErr.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
rData, appErr := p.API.KVGet("some_key")
|
||||||
|
if appErr != nil {
|
||||||
|
return nil, appErr.Error()
|
||||||
|
}
|
||||||
|
if !bytes.Equal(data, rData) {
|
||||||
|
return nil, fmt.Sprintf("Data not equal, expected: %s, got: %s", string(data), string(rData))
|
||||||
|
}
|
||||||
|
|
||||||
|
data = []byte("some other data")
|
||||||
|
|
||||||
|
var longKey string
|
||||||
|
for i := 0; i < model.KeyValueKeyMaxRunes; i++ {
|
||||||
|
longKey += "k"
|
||||||
|
}
|
||||||
|
|
||||||
|
appErr = p.API.KVSet(longKey, data)
|
||||||
|
if appErr != nil {
|
||||||
|
return nil, appErr.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
rData, appErr = p.API.KVGet(longKey)
|
||||||
|
if appErr != nil {
|
||||||
|
return nil, appErr.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(data, rData) {
|
||||||
|
return nil, fmt.Sprintf("Data not equal, expected: %s, got: %s", string(data), string(rData))
|
||||||
|
}
|
||||||
|
|
||||||
|
longKey += "extra"
|
||||||
|
|
||||||
|
appErr = p.API.KVSet(longKey, data)
|
||||||
|
if appErr == nil {
|
||||||
|
return nil, "Should have gotten an error for a to long key"
|
||||||
|
}
|
||||||
|
|
||||||
|
rData, appErr = p.API.KVGet(longKey)
|
||||||
|
if appErr != nil {
|
||||||
|
return nil, "Should have gotten an error for a to long key"
|
||||||
|
}
|
||||||
|
if rData != nil {
|
||||||
|
return nil, "Returned data should have been nil"
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
plugin.ClientMain(&MyPlugin{})
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
KeyValuePluginIdMaxRunes = 190
|
KeyValuePluginIdMaxRunes = 190
|
||||||
KeyValueKeyMaxRunes = 50
|
KeyValueKeyMaxRunes = 150
|
||||||
)
|
)
|
||||||
|
|
||||||
type PluginKeyValue struct {
|
type PluginKeyValue struct {
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ func TestPluginKeyIsValid(t *testing.T) {
|
|||||||
kv.Key = ""
|
kv.Key = ""
|
||||||
assert.NotNil(t, kv.IsValid())
|
assert.NotNil(t, kv.IsValid())
|
||||||
|
|
||||||
kv.Key = "this is an extremely long key and should be invalid and this is being verified in this test"
|
kv.Key = "this is an extremely long, long, long, long, long, long, long, long, long, long, long, long, long key and should be invalid and this is being verified in this test"
|
||||||
assert.NotNil(t, kv.IsValid())
|
assert.NotNil(t, kv.IsValid())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func newSqlPluginStore(sqlStore *SqlStore) store.PluginStore {
|
|||||||
for _, db := range sqlStore.GetAllConns() {
|
for _, db := range sqlStore.GetAllConns() {
|
||||||
table := db.AddTableWithName(model.PluginKeyValue{}, "PluginKeyValueStore").SetKeys(false, "PluginId", "Key")
|
table := db.AddTableWithName(model.PluginKeyValue{}, "PluginKeyValueStore").SetKeys(false, "PluginId", "Key")
|
||||||
table.ColMap("PluginId").SetMaxSize(190)
|
table.ColMap("PluginId").SetMaxSize(190)
|
||||||
table.ColMap("Key").SetMaxSize(50)
|
table.ColMap("Key").SetMaxSize(150)
|
||||||
table.ColMap("Value").SetMaxSize(8192)
|
table.ColMap("Value").SetMaxSize(8192)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1426,6 +1426,8 @@ func upgradeDatabaseToVersion630(sqlStore *SqlStore) {
|
|||||||
sqlStore.CreateColumnIfNotExists("Schemes", "DefaultRunAdminRole", "VARCHAR(64)", "VARCHAR(64)", "")
|
sqlStore.CreateColumnIfNotExists("Schemes", "DefaultRunAdminRole", "VARCHAR(64)", "VARCHAR(64)", "")
|
||||||
sqlStore.CreateColumnIfNotExists("Schemes", "DefaultRunMemberRole", "VARCHAR(64)", "VARCHAR(64)", "")
|
sqlStore.CreateColumnIfNotExists("Schemes", "DefaultRunMemberRole", "VARCHAR(64)", "VARCHAR(64)", "")
|
||||||
|
|
||||||
|
sqlStore.AlterColumnTypeIfExists("PluginKeyValueStore", "PKey", "VARCHAR(150)", "VARCHAR(150)")
|
||||||
|
|
||||||
// saveSchemaVersion(sqlStore, Version630)
|
// saveSchemaVersion(sqlStore, Version630)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user