2021-04-14 14:28:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-17 16:52:51 +00:00
|
|
|
"github.com/anchore/stereoscope/pkg/image"
|
2021-04-14 14:28:21 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHasNonEmptyCredentials(t *testing.T) {
|
|
|
|
tests := []struct {
|
2021-05-24 20:05:56 +00:00
|
|
|
username, password, token string
|
|
|
|
expected bool
|
2021-04-14 14:28:21 +00:00
|
|
|
}{
|
2021-05-24 20:05:56 +00:00
|
|
|
|
2021-04-14 14:28:21 +00:00
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"", "", "",
|
2021-04-14 14:28:21 +00:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"user", "", "",
|
2021-04-14 14:28:21 +00:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"", "pass", "",
|
2021-04-14 14:28:21 +00:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"", "pass", "tok",
|
2021-04-14 14:28:21 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"user", "", "tok",
|
2021-04-14 14:28:21 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"", "", "tok",
|
2021-04-14 14:28:21 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"user", "pass", "tok",
|
2021-04-14 14:28:21 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2021-05-24 20:05:56 +00:00
|
|
|
"user", "pass", "",
|
2021-04-14 14:28:21 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
|
2021-05-24 20:05:56 +00:00
|
|
|
assert.Equal(t, test.expected, hasNonEmptyCredentials(test.username, test.password, test.token))
|
2021-04-14 14:28:21 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 16:52:51 +00:00
|
|
|
|
|
|
|
func Test_registry_ToOptions(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
input registry
|
|
|
|
expected image.RegistryOptions
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no registry options",
|
|
|
|
input: registry{},
|
|
|
|
expected: image.RegistryOptions{
|
|
|
|
Credentials: []image.RegistryCredentials{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set InsecureSkipTLSVerify",
|
|
|
|
input: registry{
|
|
|
|
InsecureSkipTLSVerify: true,
|
|
|
|
},
|
|
|
|
expected: image.RegistryOptions{
|
|
|
|
InsecureSkipTLSVerify: true,
|
|
|
|
Credentials: []image.RegistryCredentials{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set InsecureUseHTTP",
|
|
|
|
input: registry{
|
|
|
|
InsecureUseHTTP: true,
|
|
|
|
},
|
|
|
|
expected: image.RegistryOptions{
|
|
|
|
InsecureUseHTTP: true,
|
|
|
|
Credentials: []image.RegistryCredentials{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set all bool options",
|
|
|
|
input: registry{
|
|
|
|
InsecureSkipTLSVerify: true,
|
|
|
|
InsecureUseHTTP: true,
|
|
|
|
},
|
|
|
|
expected: image.RegistryOptions{
|
|
|
|
InsecureSkipTLSVerify: true,
|
|
|
|
InsecureUseHTTP: true,
|
|
|
|
Credentials: []image.RegistryCredentials{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
assert.Equal(t, &test.expected, test.input.ToOptions())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|