1
0
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:
avaid96
2016-07-11 23:34:20 -07:00
parent 7566a1e399
commit 205e3b3056
5 changed files with 24 additions and 16 deletions
+10 -10
View File
@@ -17,9 +17,9 @@ type Credentials struct {
Secret string Secret string
} }
type KeyData struct{ type KeyData struct {
Path string Path string
Username string Username string
} }
// Serve initializes the credentials helper and parses the action argument. // 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) return helper.Delete(serverURL)
} }
//List returns all the serverURLs of keys in //List returns all the serverURLs of keys in
//the OS store as a list of strings //the OS store as a list of strings
func List(helper Helper, writer io.Writer) error { func List(helper Helper, writer io.Writer) error {
x, y, err := helper.List() paths, accts, err := helper.List()
if err != nil { if err != nil {
return err return err
} }
keyDataList := []KeyData{} keyDataList := []KeyData{}
for index, _ := range(x) { for index := 0; index < len(paths); index++ {
keyDataObj := KeyData{ keyDataObj := KeyData{
Path:x[index], Path: paths[index],
Username:y[index], Username: accts[index],
} }
keyDataList = append([]KeyData{keyDataObj}, keyDataList...) keyDataList = append([]KeyData{keyDataObj}, keyDataList...)
} }
@@ -154,4 +154,4 @@ func List(helper Helper, writer io.Writer) error {
} }
fmt.Fprint(writer, buffer.String()) fmt.Fprint(writer, buffer.String())
return nil return nil
} }
+1
View File
@@ -152,6 +152,7 @@ func TestList(t *testing.T) {
if err := List(h, out); err != nil { if err := List(h, out); err != nil {
t.Fatal(err) t.Fatal(err)
} }
//testing that there is an output
if out.Len() == 0 { if out.Len() == 0 {
t.Fatalf("expected output in the writer, got %d", 0) t.Fatalf("expected output in the writer, got %d", 0)
} }
+3 -2
View File
@@ -9,7 +9,8 @@ type Helper interface {
// Get retrieves credentials from the store. // Get retrieves credentials from the store.
// It returns username and secret as strings. // It returns username and secret as strings.
Get(serverURL string) (string, string, error) Get(serverURL string) (string, string, error)
// List returns all the serverURLs of keys in // List returns the serverURLs of keys and their
// the OS store as a list of strings // associated usernames from the OS store as a
// list of strings
List() ([]string, []string, error) List() ([]string, []string, error)
} }
+1 -1
View File
@@ -145,7 +145,7 @@ char *keychain_list(char *** paths, char *** accts, unsigned int *list_l) {
char * path = (char *) malloc(CFStringGetLength(pathTmp)+1); char * path = (char *) malloc(CFStringGetLength(pathTmp)+1);
path = CFStringToCharArr(pathTmp); path = CFStringToCharArr(pathTmp);
path[strlen(path)] = '\0'; 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 = CFStringToCharArr(acctTmp);
acct[strlen(acct)] = '\0'; acct[strlen(acct)] = '\0';
//We now have all we need, username and servername. Now export this to .go //We now have all we need, username and servername. Now export this to .go
+9 -3
View File
@@ -1,8 +1,8 @@
package osxkeychain package osxkeychain
import ( import (
"testing"
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
"testing"
) )
func TestOSXKeychainHelper(t *testing.T) { func TestOSXKeychainHelper(t *testing.T) {
@@ -34,10 +34,16 @@ func TestOSXKeychainHelper(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
_, _, err = helper.List(); paths, accts, err := helper.List()
if err != nil { if err != nil || len(paths) == 0 || len(accts) == 0 {
t.Fatal(err) 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) { func TestMissingCredentials(t *testing.T) {