mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
cleaned up some of the osx code, added a better test for list
Signed-off-by: avaid96 <avaid1996@gmail.com>
This commit is contained in:
@@ -17,7 +17,7 @@ type Credentials struct {
|
||||
Secret string
|
||||
}
|
||||
|
||||
type KeyData struct{
|
||||
type KeyData struct {
|
||||
Path string
|
||||
Username string
|
||||
}
|
||||
@@ -133,18 +133,18 @@ func Erase(helper Helper, reader io.Reader) error {
|
||||
return helper.Delete(serverURL)
|
||||
}
|
||||
|
||||
//List returns all the serverURLs of keys in
|
||||
//the OS store as a list of strings
|
||||
//List returns all the serverURLs of keys in
|
||||
//the OS store as a list of strings
|
||||
func List(helper Helper, writer io.Writer) error {
|
||||
x, y, err := helper.List()
|
||||
paths, accts, err := helper.List()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
keyDataList := []KeyData{}
|
||||
for index, _ := range(x) {
|
||||
for index := 0; index < len(paths); index++ {
|
||||
keyDataObj := KeyData{
|
||||
Path:x[index],
|
||||
Username:y[index],
|
||||
Path: paths[index],
|
||||
Username: accts[index],
|
||||
}
|
||||
keyDataList = append([]KeyData{keyDataObj}, keyDataList...)
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ func TestList(t *testing.T) {
|
||||
if err := List(h, out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
//testing that there is an output
|
||||
if out.Len() == 0 {
|
||||
t.Fatalf("expected output in the writer, got %d", 0)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ type Helper interface {
|
||||
// Get retrieves credentials from the store.
|
||||
// It returns username and secret as strings.
|
||||
Get(serverURL string) (string, string, error)
|
||||
// List returns all the serverURLs of keys in
|
||||
// the OS store as a list of strings
|
||||
// List returns the serverURLs of keys and their
|
||||
// associated usernames from the OS store as a
|
||||
// list of strings
|
||||
List() ([]string, []string, error)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ char *keychain_list(char *** paths, char *** accts, unsigned int *list_l) {
|
||||
char * path = (char *) malloc(CFStringGetLength(pathTmp)+1);
|
||||
path = CFStringToCharArr(pathTmp);
|
||||
path[strlen(path)] = '\0';
|
||||
char * acct = (char *) malloc(CFStringGetLength(acctTmp)+1); //<- problem line in 38th iteration
|
||||
char * acct = (char *) malloc(CFStringGetLength(acctTmp)+1);
|
||||
acct = CFStringToCharArr(acctTmp);
|
||||
acct[strlen(acct)] = '\0';
|
||||
//We now have all we need, username and servername. Now export this to .go
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package osxkeychain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/docker/docker-credential-helpers/credentials"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOSXKeychainHelper(t *testing.T) {
|
||||
@@ -34,10 +34,16 @@ func TestOSXKeychainHelper(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, _, err = helper.List();
|
||||
if err != nil {
|
||||
paths, accts, err := helper.List()
|
||||
if err != nil || len(paths) == 0 || len(accts) == 0 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
helper.Add(creds)
|
||||
newpaths, newaccts, err := helper.List()
|
||||
if len(newpaths)-len(paths) != 1 || len(newaccts)-len(accts) != 1 {
|
||||
t.Fatal()
|
||||
}
|
||||
helper.Delete(creds.ServerURL)
|
||||
}
|
||||
|
||||
func TestMissingCredentials(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user