Commit f52ae82 1 parent ce1b688 commit f52ae82 Copy full SHA for f52ae82
File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package login
2
2
3
3
import (
4
4
"github.com/stretchr/testify/assert"
5
+ "os"
5
6
"testing"
6
7
)
7
8
@@ -23,10 +24,35 @@ func Test_setSensibleDefaults_profileAndDurationSpecified(t *testing.T) {
23
24
}
24
25
25
26
func Test_getMfaCodeUnlessSpecified_returnsSameCodeAsProvided (t * testing.T ) {
26
- inputMfaCode := "DogCow "
27
+ inputMfaCode := "266226 "
27
28
28
29
outputMfaCode , err := getMfaCodeUnlessSpecified (inputMfaCode )
29
30
30
31
assert .NoError (t , err )
31
32
assert .Equal (t , inputMfaCode , outputMfaCode )
32
33
}
34
+
35
+ func Test_getMfaCodeUnlessSpecified_returnsCodeFromStdin (t * testing.T ) {
36
+ stdinMfaCode := "266226"
37
+
38
+ readPipe , writePipe , err := os .Pipe ()
39
+ assert .NoError (t , err )
40
+
41
+ defer readPipe .Close ()
42
+ defer writePipe .Close ()
43
+
44
+ originalStdin := os .Stdin
45
+ defer func () {
46
+ // reset STDIN back to real STDIN
47
+ os .Stdin = originalStdin
48
+ }()
49
+ os .Stdin = readPipe
50
+
51
+ _ , err = writePipe .WriteString (stdinMfaCode + "\n " )
52
+ assert .NoError (t , err )
53
+
54
+ outputMfaCode , err := getMfaCodeUnlessSpecified ("" )
55
+
56
+ assert .NoError (t , err )
57
+ assert .Equal (t , stdinMfaCode , outputMfaCode )
58
+ }
You can’t perform that action at this time.
0 commit comments