Skip to content

Commit 8fa18eb

Browse files
committed
implementation on client side as well, complete with tests
Signed-off-by: avaid96 <[email protected]>
1 parent 887a664 commit 8fa18eb

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

client/client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ func Get(program ProgramFunc, serverURL string) (*credentials.Credentials, error
5555
return resp, nil
5656
}
5757

58-
// Erase executes a program to remove the server credentails from the native store.
58+
// Erase executes a program to remove the server credentials from the native store.
5959
func Erase(program ProgramFunc, serverURL string) error {
6060
cmd := program("erase")
6161
cmd.Input(strings.NewReader(serverURL))
62-
6362
out, err := cmd.Output()
6463
if err != nil {
6564
t := strings.TrimSpace(string(out))
@@ -68,3 +67,15 @@ func Erase(program ProgramFunc, serverURL string) error {
6867

6968
return nil
7069
}
70+
71+
// List executes a program to remove the server credentials from the native store.
72+
func List(program ProgramFunc) error {
73+
cmd := program("list")
74+
cmd.Input(strings.NewReader("garbage"))
75+
out, err := cmd.Output()
76+
if err != nil {
77+
t := strings.TrimSpace(string(out))
78+
return fmt.Errorf("error listing credentials - err: %v, out: `%s`", err, t)
79+
}
80+
return nil
81+
}

client/client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func (m *mockProgram) Output() ([]byte, error) {
7070
default:
7171
return []byte("error storing credentials"), errProgramExited
7272
}
73+
case "list":
74+
return []byte(`{"Path":"e237574ae22fd53ddb9490dc1f72139946fd5372d42ba54d1eeb3ae5068fd22b","Username":"http://example.com/collections\u003cnotary_key\u003eSnapshot"}`), nil
75+
7376
}
7477

7578
return []byte(fmt.Sprintf("unknown argument %q with %q", m.arg, inS)), errProgramExited
@@ -190,3 +193,9 @@ func TestErase(t *testing.T) {
190193
t.Fatalf("Expected error for server %s, got nil", invalidServerAddress)
191194
}
192195
}
196+
197+
func TestList(t *testing.T) {
198+
if err := List(mockProgramFn); err != nil {
199+
t.Fatal(err)
200+
}
201+
}

credentials/credentials.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type KeyData struct {
3030
func Serve(helper Helper) {
3131
var err error
3232
if len(os.Args) != 2 {
33-
err = fmt.Errorf("Usage: %s <store|get|erase>", os.Args[0])
33+
err = fmt.Errorf("Usage: %s <store|get|erase|list>", os.Args[0])
3434
}
3535

3636
if err == nil {
@@ -52,6 +52,8 @@ func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error
5252
return Get(helper, in, out)
5353
case "erase":
5454
return Erase(helper, in)
55+
case "list":
56+
return List(helper, out)
5557
}
5658
return fmt.Errorf("Unknown credential action `%s`", key)
5759
}

0 commit comments

Comments
 (0)