Skip to content

Commit ca18bcb

Browse files
author
yuguo.dtpe
committed
fix: clarify console logout hint
1 parent 83738fa commit ca18bcb

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

cmd/consolelogin_logout.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func removeLoginCache(loginSession string) error {
144144
// printPostLogoutHint prints a security reminder after logout.
145145
func printPostLogoutHint() {
146146
fmt.Println()
147-
fmt.Println("Note: Any local tools that have already loaded temporary credentials")
148-
fmt.Println("may continue to use them until they expire (typically within 15 minutes).")
147+
fmt.Println("Note: Local cache has been removed for future CLI sessions.")
148+
fmt.Println("Already-running tools that loaded temporary STS credentials before logout")
149+
fmt.Println("may continue to use them until those credentials expire.")
149150
}

cmd/consolelogin_logout_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package cmd
22

33
import (
4+
"io/ioutil"
5+
"os"
6+
"strings"
47
"testing"
58
)
69

@@ -41,3 +44,48 @@ func TestRemoveLoginCache_NonExistent(t *testing.T) {
4144
t.Fatalf("removeLoginCache should not error on non-existent file, got: %v", err)
4245
}
4346
}
47+
48+
func TestPrintPostLogoutHintClarifiesFutureSessionsAndLoadedCredentials(t *testing.T) {
49+
output := captureStdout(t, printPostLogoutHint)
50+
51+
expectedParts := []string{
52+
"Local cache has been removed for future CLI sessions.",
53+
"Already-running tools that loaded temporary STS credentials before logout",
54+
"may continue to use them until those credentials expire.",
55+
}
56+
for _, part := range expectedParts {
57+
if !strings.Contains(output, part) {
58+
t.Fatalf("printPostLogoutHint output %q does not contain %q", output, part)
59+
}
60+
}
61+
}
62+
63+
func captureStdout(t *testing.T, fn func()) string {
64+
t.Helper()
65+
66+
originalStdout := os.Stdout
67+
reader, writer, err := os.Pipe()
68+
if err != nil {
69+
t.Fatalf("creating stdout pipe: %v", err)
70+
}
71+
72+
os.Stdout = writer
73+
defer func() {
74+
os.Stdout = originalStdout
75+
}()
76+
77+
fn()
78+
79+
if err := writer.Close(); err != nil {
80+
t.Fatalf("closing stdout writer: %v", err)
81+
}
82+
83+
data, err := ioutil.ReadAll(reader)
84+
if err != nil {
85+
t.Fatalf("reading stdout: %v", err)
86+
}
87+
if err := reader.Close(); err != nil {
88+
t.Fatalf("closing stdout reader: %v", err)
89+
}
90+
return string(data)
91+
}

0 commit comments

Comments
 (0)