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,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...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user