-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathtoken_tty_unix_test.go
More file actions
38 lines (32 loc) · 992 Bytes
/
token_tty_unix_test.go
File metadata and controls
38 lines (32 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build !windows
package auth_test
import (
"errors"
"testing"
"github.com/creack/pty"
fsterr "github.com/fastly/cli/pkg/errors"
)
func TestToken_TTY_Refused(t *testing.T) {
// Create a PTY pair so we have a writable *os.File that
// term.IsTerminal recognises as a terminal. This runs reliably
// on Unix CI (no /dev/tty required) and, unlike os.Stdout, never
// risks leaking a token to the developer's real terminal.
ptm, pts, err := pty.Open()
if err != nil {
t.Fatalf("failed to open pty: %v", err)
}
defer ptm.Close()
defer pts.Close()
cmd := newTokenCommand(globalDataWithToken("secret-token"))
err = cmd.Exec(nil, pts)
if err == nil {
t.Fatal("expected error when stdout is a terminal")
}
var re fsterr.RemediationError
if !errors.As(err, &re) {
t.Fatalf("expected RemediationError, got %T: %v", err, err)
}
if re.Inner == nil || re.Inner.Error() != "refusing to print token to a terminal" {
t.Errorf("unexpected inner error: %v", re.Inner)
}
}