Skip to content

Commit 6889bb0

Browse files
committed
Verify that JSON OAuth reset actually removes stored logins.
Refs #937
1 parent 07c9809 commit 6889bb0

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎internal/cli/auth_test.go‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,14 @@ func TestRunAuthHelp(t *testing.T) {
204204
}
205205

206206
func TestRunAuthResetJSON(t *testing.T) {
207-
withAuthStore(t)
207+
path := withAuthStore(t)
208+
store, err := oauth.NewStore(oauth.StoreOptions{FilePath: path})
209+
if err != nil {
210+
t.Fatalf("NewStore: %v", err)
211+
}
212+
if err := store.Save(oauth.ProviderKey("demo"), oauth.Token{AccessToken: "synthetic-reset-test-token"}); err != nil {
213+
t.Fatalf("Save: %v", err)
214+
}
208215
var stdout, stderr bytes.Buffer
209216
if code := runWithDeps([]string{"auth", "reset", "--json"}, &stdout, &stderr, appDeps{}); code != exitSuccess {
210217
t.Fatalf("exit = %d stderr=%s", code, stderr.String())
@@ -218,6 +225,14 @@ func TestRunAuthResetJSON(t *testing.T) {
218225
if !payload.Reset {
219226
t.Fatalf("payload = %+v, want reset=true", payload)
220227
}
228+
stdout.Reset()
229+
stderr.Reset()
230+
if code := runWithDeps([]string{"auth", "status"}, &stdout, &stderr, appDeps{}); code != exitSuccess {
231+
t.Fatalf("status exit = %d stderr=%s", code, stderr.String())
232+
}
233+
if !strings.Contains(stdout.String(), "No OAuth provider logins are stored.") {
234+
t.Fatalf("expected empty store after JSON reset, got: %q", stdout.String())
235+
}
221236
}
222237

223238
func TestRunAuthReset(t *testing.T) {

0 commit comments

Comments
 (0)