2018-02-05 16:05:59 -05:00
|
|
|
package plugin // import "github.com/docker/docker/plugin"
|
2016-12-27 22:38:13 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidatePrivileges(t *testing.T) {
|
|
|
|
testData := map[string]struct {
|
|
|
|
requiredPrivileges types.PluginPrivileges
|
|
|
|
privileges types.PluginPrivileges
|
|
|
|
result bool
|
|
|
|
}{
|
|
|
|
"diff-len": {
|
|
|
|
requiredPrivileges: []types.PluginPrivilege{
|
2017-03-20 04:27:51 -04:00
|
|
|
{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "ghi"}},
|
2016-12-27 22:38:13 -05:00
|
|
|
},
|
|
|
|
privileges: []types.PluginPrivilege{
|
2017-03-20 04:27:51 -04:00
|
|
|
{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "ghi"}},
|
|
|
|
{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
|
2016-12-27 22:38:13 -05:00
|
|
|
},
|
|
|
|
result: false,
|
|
|
|
},
|
|
|
|
"diff-value": {
|
|
|
|
requiredPrivileges: []types.PluginPrivilege{
|
2017-03-20 04:27:51 -04:00
|
|
|
{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "GHI"}},
|
|
|
|
{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "***"}},
|
2016-12-27 22:38:13 -05:00
|
|
|
},
|
|
|
|
privileges: []types.PluginPrivilege{
|
2017-03-20 04:27:51 -04:00
|
|
|
{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "ghi"}},
|
|
|
|
{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
|
2016-12-27 22:38:13 -05:00
|
|
|
},
|
|
|
|
result: false,
|
|
|
|
},
|
|
|
|
"diff-order-but-same-value": {
|
|
|
|
requiredPrivileges: []types.PluginPrivilege{
|
2017-03-20 04:27:51 -04:00
|
|
|
{Name: "Privilege1", Description: "Description", Value: []string{"abc", "def", "GHI"}},
|
|
|
|
{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
|
2016-12-27 22:38:13 -05:00
|
|
|
},
|
|
|
|
privileges: []types.PluginPrivilege{
|
2017-03-20 04:27:51 -04:00
|
|
|
{Name: "Privilege2", Description: "Description", Value: []string{"123", "456", "789"}},
|
|
|
|
{Name: "Privilege1", Description: "Description", Value: []string{"GHI", "abc", "def"}},
|
2016-12-27 22:38:13 -05:00
|
|
|
},
|
|
|
|
result: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for key, data := range testData {
|
|
|
|
err := validatePrivileges(data.requiredPrivileges, data.privileges)
|
|
|
|
if (err == nil) != data.result {
|
|
|
|
t.Fatalf("Test item %s expected result to be %t, got %t", key, data.result, (err == nil))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|