[MM-30981] Require Plugin name in manifest (#16438)

Этот коммит содержится в:
Ben Schumacher
2020-12-02 11:48:30 +01:00
коммит произвёл GitHub
родитель fc60a1e8dd
Коммит 11248831b8
2 изменённых файлов: 14 добавлений и 9 удалений

Просмотреть файл

@@ -147,7 +147,7 @@ type Manifest struct {
Id string `json:"id" yaml:"id"` Id string `json:"id" yaml:"id"`
// The name to be displayed for the plugin. // The name to be displayed for the plugin.
Name string `json:"name,omitempty" yaml:"name,omitempty"` Name string `json:"name" yaml:"name"`
// A description of what your plugin is and does. // A description of what your plugin is and does.
Description string `json:"description,omitempty" yaml:"description,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"`
@@ -329,6 +329,10 @@ func (m *Manifest) IsValid() error {
return errors.New("invalid plugin ID") return errors.New("invalid plugin ID")
} }
if strings.TrimSpace(m.Name) == "" {
return errors.New("a plugin name is needed")
}
if m.HomepageURL != "" && !IsValidHttpUrl(m.HomepageURL) { if m.HomepageURL != "" && !IsValidHttpUrl(m.HomepageURL) {
return errors.New("invalid HomepageURL") return errors.New("invalid HomepageURL")
} }

Просмотреть файл

@@ -23,16 +23,17 @@ func TestIsValid(t *testing.T) {
manifest *Manifest manifest *Manifest
ExpectError bool ExpectError bool
}{ }{
{"Invalid Id", &Manifest{Id: "some id"}, true}, {"Invalid Id", &Manifest{Id: "some id", Name: "some name"}, true},
{"Invalid homePageURL", &Manifest{Id: "com.company.test", HomepageURL: "some url"}, true}, {"Invalid Name", &Manifest{Id: "com.company.test", Name: " "}, true},
{"Invalid supportURL", &Manifest{Id: "com.company.test", SupportURL: "some url"}, true}, {"Invalid homePageURL", &Manifest{Id: "com.company.test", Name: "some name", HomepageURL: "some url"}, true},
{"Invalid ReleaseNotesURL", &Manifest{Id: "com.company.test", ReleaseNotesURL: "some url"}, true}, {"Invalid supportURL", &Manifest{Id: "com.company.test", Name: "some name", SupportURL: "some url"}, true},
{"Invalid version", &Manifest{Id: "com.company.test", HomepageURL: "http://someurl.com", SupportURL: "http://someotherurl.com", Version: "version"}, true}, {"Invalid ReleaseNotesURL", &Manifest{Id: "com.company.test", Name: "some name", ReleaseNotesURL: "some url"}, true},
{"Invalid min version", &Manifest{Id: "com.company.test", HomepageURL: "http://someurl.com", SupportURL: "http://someotherurl.com", Version: "5.10.0", MinServerVersion: "version"}, true}, {"Invalid version", &Manifest{Id: "com.company.test", Name: "some name", HomepageURL: "http://someurl.com", SupportURL: "http://someotherurl.com", Version: "version"}, true},
{"SettingSchema error", &Manifest{Id: "com.company.test", HomepageURL: "http://someurl.com", SupportURL: "http://someotherurl.com", Version: "5.10.0", MinServerVersion: "5.10.8", SettingsSchema: &PluginSettingsSchema{ {"Invalid min version", &Manifest{Id: "com.company.test", Name: "some name", HomepageURL: "http://someurl.com", SupportURL: "http://someotherurl.com", Version: "5.10.0", MinServerVersion: "version"}, true},
{"SettingSchema error", &Manifest{Id: "com.company.test", Name: "some name", HomepageURL: "http://someurl.com", SupportURL: "http://someotherurl.com", Version: "5.10.0", MinServerVersion: "5.10.8", SettingsSchema: &PluginSettingsSchema{
Settings: []*PluginSetting{{Type: "Invalid"}}, Settings: []*PluginSetting{{Type: "Invalid"}},
}}, true}, }}, true},
{"Minimal valid manifest", &Manifest{Id: "com.company.test"}, false}, {"Minimal valid manifest", &Manifest{Id: "com.company.test", Name: "some name"}, false},
{"Happy case", &Manifest{ {"Happy case", &Manifest{
Id: "com.company.test", Id: "com.company.test",
Name: "thename", Name: "thename",