mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Fix intermittent slow CLI tests (#797)
* use a port that is porbably not in use Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * template cli test args Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
e474b2f23c
commit
37251f6179
@ -1,6 +1,7 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -201,6 +202,10 @@ func TestPackagesCmdFlags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRegistryAuth(t *testing.T) {
|
func TestRegistryAuth(t *testing.T) {
|
||||||
|
host := "localhost:17"
|
||||||
|
image := fmt.Sprintf("%s/something:latest", host)
|
||||||
|
args := []string{"packages", "-vv", fmt.Sprintf("registry:%s", image)}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
@ -209,55 +214,55 @@ func TestRegistryAuth(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "fallback to keychain",
|
name: "fallback to keychain",
|
||||||
args: []string{"packages", "-vv", "registry:localhost:5000/something:latest"},
|
args: args,
|
||||||
assertions: []traitAssertion{
|
assertions: []traitAssertion{
|
||||||
assertInOutput("source=OciRegistry"),
|
assertInOutput("source=OciRegistry"),
|
||||||
assertInOutput("localhost:5000/something:latest"),
|
assertInOutput(image),
|
||||||
assertInOutput("no registry credentials configured, using the default keychain"),
|
assertInOutput("no registry credentials configured, using the default keychain"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "use creds",
|
name: "use creds",
|
||||||
args: []string{"packages", "-vv", "registry:localhost:5000/something:latest"},
|
args: args,
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"SYFT_REGISTRY_AUTH_AUTHORITY": "localhost:5000",
|
"SYFT_REGISTRY_AUTH_AUTHORITY": host,
|
||||||
"SYFT_REGISTRY_AUTH_USERNAME": "username",
|
"SYFT_REGISTRY_AUTH_USERNAME": "username",
|
||||||
"SYFT_REGISTRY_AUTH_PASSWORD": "password",
|
"SYFT_REGISTRY_AUTH_PASSWORD": "password",
|
||||||
},
|
},
|
||||||
assertions: []traitAssertion{
|
assertions: []traitAssertion{
|
||||||
assertInOutput("source=OciRegistry"),
|
assertInOutput("source=OciRegistry"),
|
||||||
assertInOutput("localhost:5000/something:latest"),
|
assertInOutput(image),
|
||||||
assertInOutput(`using basic auth for registry "localhost:5000"`),
|
assertInOutput(fmt.Sprintf(`using basic auth for registry "%s"`, host)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "use token",
|
name: "use token",
|
||||||
args: []string{"packages", "-vv", "registry:localhost:5000/something:latest"},
|
args: args,
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"SYFT_REGISTRY_AUTH_AUTHORITY": "localhost:5000",
|
"SYFT_REGISTRY_AUTH_AUTHORITY": host,
|
||||||
"SYFT_REGISTRY_AUTH_TOKEN": "token",
|
"SYFT_REGISTRY_AUTH_TOKEN": "token",
|
||||||
},
|
},
|
||||||
assertions: []traitAssertion{
|
assertions: []traitAssertion{
|
||||||
assertInOutput("source=OciRegistry"),
|
assertInOutput("source=OciRegistry"),
|
||||||
assertInOutput("localhost:5000/something:latest"),
|
assertInOutput(image),
|
||||||
assertInOutput(`using token for registry "localhost:5000"`),
|
assertInOutput(fmt.Sprintf(`using token for registry "%s"`, host)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "not enough info fallsback to keychain",
|
name: "not enough info fallsback to keychain",
|
||||||
args: []string{"packages", "-vv", "registry:localhost:5000/something:latest"},
|
args: args,
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"SYFT_REGISTRY_AUTH_AUTHORITY": "localhost:5000",
|
"SYFT_REGISTRY_AUTH_AUTHORITY": host,
|
||||||
},
|
},
|
||||||
assertions: []traitAssertion{
|
assertions: []traitAssertion{
|
||||||
assertInOutput("source=OciRegistry"),
|
assertInOutput("source=OciRegistry"),
|
||||||
assertInOutput("localhost:5000/something:latest"),
|
assertInOutput(image),
|
||||||
assertInOutput(`no registry credentials configured, using the default keychain`),
|
assertInOutput(`no registry credentials configured, using the default keychain`),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "allows insecure http flag",
|
name: "allows insecure http flag",
|
||||||
args: []string{"packages", "-vv", "registry:localhost:5000/something:latest"},
|
args: args,
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"SYFT_REGISTRY_INSECURE_USE_HTTP": "true",
|
"SYFT_REGISTRY_INSECURE_USE_HTTP": "true",
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user