1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-14 00:11:28 +05:30
Files
docker-credential-helpers/pass/pass_test.go
T
Sebastiaan van Stijn ffb3232f6c pass: use designated domains in tests (RFC2606)
Update domains used in tests to used domains that are designated for this
purpose as described in [RFC2606, section 3][1]

[1]: https://www.rfc-editor.org/rfc/rfc2606.html#section-3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-26 13:59:01 +02:00

125 lines
2.6 KiB
Go

//go:build !windows
package pass
import (
"strings"
"testing"
"github.com/docker/docker-credential-helpers/credentials"
)
func TestPassHelper(t *testing.T) {
creds := &credentials.Credentials{
ServerURL: "https://foobar.example.com:2376/v1",
Username: "nothing",
Secret: "isthebestmeshuggahalbum",
}
helper := Pass{}
if err := helper.checkInitialized(); err != nil {
t.Error(err)
}
if err := helper.Add(creds); err != nil {
t.Error(err)
}
u, s, err := helper.Get(creds.ServerURL)
if err != nil {
t.Error(err)
}
if u != creds.Username {
t.Errorf("invalid username %s", u)
}
if s != creds.Secret {
t.Errorf("invalid secret: %s", s)
}
if err := helper.Delete(creds.ServerURL); err != nil {
t.Error(err)
}
if _, _, err := helper.Get(creds.ServerURL); !credentials.IsErrCredentialsNotFound(err) {
t.Errorf("expected credentials not found, actual: %v", err)
}
}
func TestPassHelperCheckInit(t *testing.T) {
helper := Pass{}
if v := helper.CheckInitialized(); !v {
t.Errorf("expected true, actual: %v", v)
}
}
func TestPassHelperList(t *testing.T) {
creds := []*credentials.Credentials{
{
ServerURL: "https://foobar.example.com:2376/v1",
Username: "foo",
Secret: "isthebestmeshuggahalbum",
},
{
ServerURL: "https://foobar.example.com:2375/v1",
Username: "bar",
Secret: "isthebestmeshuggahalbum",
},
}
helper := Pass{}
if err := helper.checkInitialized(); err != nil {
t.Error(err)
}
for _, cred := range creds {
if err := helper.Add(cred); err != nil {
t.Error(err)
}
}
credsList, err := helper.List()
if err != nil {
t.Error(err)
}
for server, username := range credsList {
if !(strings.HasSuffix(server, "2376/v1") || strings.HasSuffix(server, "2375/v1")) {
t.Errorf("invalid url: %s", server)
}
if !(username == "foo" || username == "bar") {
t.Errorf("invalid username: %v", username)
}
u, s, err := helper.Get(server)
if err != nil {
t.Error(err)
}
if u != username {
t.Errorf("invalid username %s", u)
}
if s != "isthebestmeshuggahalbum" {
t.Errorf("invalid secret: %s", s)
}
if err := helper.Delete(server); err != nil {
t.Error(err)
}
if _, _, err := helper.Get(server); !credentials.IsErrCredentialsNotFound(err) {
t.Errorf("expected credentials not found, actual: %v", err)
}
}
credsList, err = helper.List()
if err != nil {
t.Error(err)
}
if len(credsList) != 0 {
t.Error("didn't delete all creds?")
}
}
func TestMissingCred(t *testing.T) {
helper := Pass{}
if _, _, err := helper.Get("garbage"); !credentials.IsErrCredentialsNotFound(err) {
t.Errorf("expected credentials not found, actual: %v", err)
}
}