aboutsummaryrefslogtreecommitdiff
path: root/test/insert.t
blob: b4af4f53a57ec43f04d59313bb748c0431481066 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash

export test_description="Tests pass otp insert commands"

. ./setup.sh

test_expect_success 'Inserts a key URI' '
  uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"

  test_pass_init &&
  "$PASS" otp insert "$uri" passfile &&
  [[ $("$PASS" show passfile) == "$uri" ]]
'

test_expect_success 'Prompts before overwriting key URI' '
  uri1="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo"
  uri2="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Bar"

  test_pass_init
  "$PASS" otp insert "$uri1" passfile
  expect <<EOD
    spawn "$PASS" otp insert "$uri2" passfile
    expect {
      "An entry already exists" {
        send "n\r"
        exp_continue
      }
      eof
    }
EOD
  [[ $("$PASS" show passfile) == "$uri1" ]]
'

test_expect_success 'Force overwrites key URI' '
  uri1="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Foo"
  uri2="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Bar"

  test_pass_init &&
  "$PASS" otp insert "$uri1" passfile &&
  "$PASS" otp insert -f "$uri2" passfile &&
  [[ $("$PASS" show passfile) == "$uri2" ]]
'

test_expect_success 'Reads non-terminal input' '
  uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"

  test_pass_init &&
  "$PASS" otp insert passfile <<< "$uri" &&
  [[ $("$PASS" show passfile) == "$uri" ]]
'

test_expect_success 'Reads terminal input in noecho mode' '
  uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"

  test_pass_init
  expect <<EOD
    spawn "$PASS" otp insert passfile
    expect {
      "Enter" {
        send "$uri\r"
        exp_continue
      }
      "Retype" {
        send "$uri\r"
        exp_continue
      }
      eof
    }
EOD
  [[ $("$PASS" show passfile) == "$uri" ]]
'

test_expect_success 'Reads terminal input in echo mode' '
  uri="otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example"

  test_pass_init
  expect <<EOD
    spawn "$PASS" otp insert -e passfile
    expect {
      "Enter" {
        send "$uri\r"
        exp_continue
      }
      eof
    }
EOD
  [[ $("$PASS" show passfile) == "$uri" ]]
'

test_done