diff --git a/credentials/credentials.go b/credentials/credentials.go index 23fa569..8fc69c7 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -17,9 +17,9 @@ type Credentials struct { Secret string } -type KeyData struct{ - Path string - Username string +type KeyData struct { + Path string + Username string } // Serve initializes the credentials helper and parses the action argument. @@ -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...) } @@ -154,4 +154,4 @@ func List(helper Helper, writer io.Writer) error { } fmt.Fprint(writer, buffer.String()) return nil -} \ No newline at end of file +} diff --git a/credentials/credentials_test.go b/credentials/credentials_test.go index 0909cb7..6476012 100644 --- a/credentials/credentials_test.go +++ b/credentials/credentials_test.go @@ -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) } diff --git a/credentials/helper.go b/credentials/helper.go index ba1ba34..785fcd7 100644 --- a/credentials/helper.go +++ b/credentials/helper.go @@ -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) } diff --git a/osxkeychain/osxkeychain_darwin.c b/osxkeychain/osxkeychain_darwin.c index 6c0240a..d8105fc 100644 --- a/osxkeychain/osxkeychain_darwin.c +++ b/osxkeychain/osxkeychain_darwin.c @@ -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 diff --git a/osxkeychain/osxkeychain_darwin_test.go b/osxkeychain/osxkeychain_darwin_test.go index 94c47aa..f4b32a0 100644 --- a/osxkeychain/osxkeychain_darwin_test.go +++ b/osxkeychain/osxkeychain_darwin_test.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) {