Make plugin IDs case insensitive (#9117)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
275731578e
Коммит
f2c1803905
@@ -114,6 +114,10 @@ func TestPlugin(t *testing.T) {
|
|||||||
CheckBadRequestStatus(t, resp)
|
CheckBadRequestStatus(t, resp)
|
||||||
assert.False(t, ok)
|
assert.False(t, ok)
|
||||||
|
|
||||||
|
ok, resp = th.SystemAdminClient.EnablePlugin("JUNK")
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
assert.False(t, ok)
|
||||||
|
|
||||||
// Successful deactivate
|
// Successful deactivate
|
||||||
ok, resp = th.SystemAdminClient.DisablePlugin(manifest.Id)
|
ok, resp = th.SystemAdminClient.DisablePlugin(manifest.Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/mlog"
|
"github.com/mattermost/mattermost-server/mlog"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
@@ -154,6 +155,8 @@ func (a *App) EnablePlugin(id string) *model.AppError {
|
|||||||
return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("EnablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id = strings.ToLower(id)
|
||||||
|
|
||||||
var manifest *model.Manifest
|
var manifest *model.Manifest
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
if p.Manifest.Id == id {
|
if p.Manifest.Id == id {
|
||||||
@@ -198,6 +201,8 @@ func (a *App) DisablePlugin(id string) *model.AppError {
|
|||||||
return model.NewAppError("DisablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return model.NewAppError("DisablePlugin", "app.plugin.config.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id = strings.ToLower(id)
|
||||||
|
|
||||||
var manifest *model.Manifest
|
var manifest *model.Manifest
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
if p.Manifest.Id == id {
|
if p.Manifest.Id == id {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
@@ -201,6 +202,7 @@ func FindManifest(dir string) (manifest *Manifest, path string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
manifest = &parsed
|
manifest = &parsed
|
||||||
|
manifest.Id = strings.ToLower(manifest.Id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,5 +222,6 @@ func FindManifest(dir string) (manifest *Manifest, path string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
manifest = &parsed
|
manifest = &parsed
|
||||||
|
manifest.Id = strings.ToLower(manifest.Id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ func TestFindManifest(t *testing.T) {
|
|||||||
{"foo", "bar", true, true},
|
{"foo", "bar", true, true},
|
||||||
{"plugin.json", "bar", true, false},
|
{"plugin.json", "bar", true, false},
|
||||||
{"plugin.json", `{"id": "foo"}`, false, false},
|
{"plugin.json", `{"id": "foo"}`, false, false},
|
||||||
|
{"plugin.json", `{"id": "FOO"}`, false, false},
|
||||||
{"plugin.yaml", `id: foo`, false, false},
|
{"plugin.yaml", `id: foo`, false, false},
|
||||||
{"plugin.yaml", "bar", true, false},
|
{"plugin.yaml", "bar", true, false},
|
||||||
{"plugin.yml", `id: foo`, false, false},
|
{"plugin.yml", `id: foo`, false, false},
|
||||||
|
{"plugin.yml", `id: FOO`, false, false},
|
||||||
{"plugin.yml", "bar", true, false},
|
{"plugin.yml", "bar", true, false},
|
||||||
} {
|
} {
|
||||||
dir, err := ioutil.TempDir("", "mm-plugin-test")
|
dir, err := ioutil.TempDir("", "mm-plugin-test")
|
||||||
@@ -54,6 +56,7 @@ func TestFindManifest(t *testing.T) {
|
|||||||
if !tc.ExpectError {
|
if !tc.ExpectError {
|
||||||
require.NotNil(t, m, tc.Filename)
|
require.NotNil(t, m, tc.Filename)
|
||||||
assert.NotEmpty(t, m.Id, tc.Filename)
|
assert.NotEmpty(t, m.Id, tc.Filename)
|
||||||
|
assert.Equal(t, strings.ToLower(m.Id), m.Id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user