File: test_parse_fields

package info (click to toggle)
wofi-pass 24.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: sh: 304; makefile: 4
file content (118 lines) | stat: -rw-r--r-- 3,216 bytes parent folder | download
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
verify_parsed_fields() {
    local output_array=()
    local exected_autotype="${1}"
    shift

    coproc cat
    exec {test_channel}>&${COPROC[1]}
    parse_fields "passname" >&${test_channel}

    while IFS= read -t 0.2 -r line || [[ -n "${line}" ]]; do
        output_array+=("${line}")
    done <&${COPROC[0]}
    kill ${COPROC_PID}

    local expected="$(printf "%s\n" "${@}")"
    local output="$(printf "%s\n" "${output_array[@]}")"
    assert_equals "${expected}" "${output}" "parse fields: unexpected output"
    assert_equals ${expected_autotype} ${FLAG_AUTOTYPE} "parse fields: FLAG_AUTOTYPE has unexpected value"
}

test_parse_fields_empty_password() {
    fake _pass echo ""

    FLAG_AUTOTYPE=0
    local expected_autotype=0
    local expected_array=("password")

    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
    FLAG_FILEISUSER=1
    expected_array=("password" "${PASS_FIELD_USERNAME}")
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
}

test_parse_fields_only_password() {
    fake _pass echo "paSSw0rd"

    FLAG_AUTOTYPE=0
    local expected_autotype=0
    local expected_array=("password")

    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
    FLAG_FILEISUSER=1
    expected_array=("password" "${PASS_FIELD_USERNAME}")
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
}


test_parse_fields_username_password() {
    fake _pass <<EOF
paSSw0rd
${PASS_FIELD_USERNAME}: username@e-mail.com
EOF

    FLAG_AUTOTYPE=0
    local expected_autotype=0
    local expected_array=("password" "${PASS_FIELD_USERNAME}")

    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
    FLAG_FILEISUSER=1
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
}

test_parse_fields_otp() {
    fake _pass <<EOF
paSSw0rd
${PASS_FIELD_USERNAME}: username@e-mail.com
otpauth://totp/XYZ:email@example.com?secret=ADFASDGASDF&issuer=XYZ
EOF

    FLAG_AUTOTYPE=0
    local expected_autotype=0
    local expected_array=("password" "${PASS_FIELD_USERNAME}" "<<--OTP-->>")

    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
    FLAG_FILEISUSER=1
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
}

test_parse_fields_autotype() {
    fake _pass <<EOF
paSSw0rd
${PASS_FIELD_USERNAME}: username@e-mail.com
autotype_always
EOF

    FLAG_AUTOTYPE=0
    local expected_autotype=1
    local expected_array=("password" "${PASS_FIELD_USERNAME}")
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"

    FLAG_FILEISUSER=1
    FLAG_AUTOTYPE=0
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
}

test_parse_fields_ignore() {
    fake _pass <<EOF
paSSw0rd
${PASS_FIELD_USERNAME}: username@e-mail.com
ignore this line
url: http://example.com
ignore this line either
this line: is expected
EOF

    FLAG_AUTOTYPE=0
    local expected_autotype=0
    local expected_array=("password" "${PASS_FIELD_USERNAME}" "url" "this line")
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"

    FLAG_FILEISUSER=1
    verify_parsed_fields ${expected_autotype} "${expected_array[@]}"
}

setup_suite() {
    WOFI_PASS_TESTING=1
    source ../wofi-pass
}