blob: 4507d38721271705a8b7b30376246769aec1fa9a (
plain) (
tree)
|
|
#!/usr/bin/env bats
setup() {
DIR="$( cd "$(dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# shellcheck source=pinentry-rofi.sh
source "$(readlink -f "${DIR}/../pinentry-rofi.sh")"
mapfile -d '' instr <<- EOF
Please enter the passphrase to unlock the OpenPGP secret key:
"Matěj Cepl <mcepl@cepl.eu>"
4096-bit RSA key, ID 77D15A36BD4211B2,
created 2016-04-27 (main key ID 79205802880BC9D8).
EOF
}
log_debug() {
echo "$@" >> /dev/stderr
}
@test "split line" {
line_arr=($(split_line "GETINFO version"))
[ "${line_arr[0]}" = "version" ]
}
@test "split line rmfirst" {
line_arr=($(split_line "GETINFO version" 0))
[ "${line_arr[0]}" = "version" ]
}
@test "split line no-rmfirst" {
IFS=" " line_arr=($(split_line "GETINFO version" 1))
[[ "$(declare -p line_arr)" == 'declare -'[aA]* ]]
[[ "${line_arr[0]}" == "GETINFO" ]]
[[ ${#line_arr[@]} -eq 2 ]]
[[ "${line_arr[1]}" == "version" ]]
}
@test "decode example RFC-3986 encoded string" {
local instr="Please enter the passphrase to unlock the OpenPGP secret key:%0A%22Matěj Cepl <mcepl@cepl.eu>%22%0A4096-bit RSA key, ID 77D15A36BD4211B2,%0Acreated 2016-04-27 (main key ID 79205802880BC9D8).%0A"
local expected="Please enter the passphrase to unlock the OpenPGP secret key:\n\
\"Matěj Cepl <mcepl@cepl.eu>\"\n\
4096-bit RSA key, ID 77D15A36BD4211B2,\n\
created 2016-04-27 (main key ID 79205802880BC9D8)."
log_debug "expected: ${expected}"
log_debug "instr: ${instr}"
observed=$(rawurldecode "${instr}")
log_debug "observed: ${observed}"
[[ "$observed" == "$expected" ]] || diff -u <(echo -e "$observed") <(echo -e "$expected")
}
@test "decode bastardized URL encoded string" {
local expected
mapfile -d '' expected <<- EOF
Please enter the passphrase to unlock the OpenPGP secret key:
"Matěj Cepl <mcepl@cepl.eu>"
4096-bit RSA key, ID 77D15A36BD4211B2,
created 2016-04-27 (main key ID 79205802880BC9D8).
EOF
log_debug "expected: ${expected}"
log_debug "instr: ${instr}"
observed=$(basturlencode "${instr}")
log_debug "observed: ${observed}"
[[ "$observed" == "$expected" ]] || diff -u <(echo "$observed") <(printf "%s" "$expected")
}
@test "encode into RFC-3986 encoded string" {
local expected
expected="Please%20enter%20the%20passphrase%20to%20unlock%20the%20OpenPGP%20secret%20key%3a%0a%22Matěj%20Cepl%20%3cmcepl%40cepl.eu%3e%22%0a4096-bit%20RSA%20key%2c%20ID%2077D15A36BD4211B2%2c%0acreated%202016-04-27%20%28main%20key%20ID%2079205802880BC9D8%29.%0a"
log_debug "expected: ${expected}"
log_debug "instr: ${instr}"
observed=$(rawurlencode "${instr}")
log_debug "observed: ${observed}"
[[ "$observed" == "$expected" ]] || diff -u <(echo -e "$observed") <(echo -e "$expected")
}
@test "encode/decode forth and back with RFC-3986 encoded string" {
local workstr observed
log_debug "instr: ${instr}"
workstr=$(rawurlencode "${instr}")
log_debug "workstr: ${workstr}"
observed="$(rawurldecode "${workstr}")"
log_debug "observed: ${observed}"
# There is some mockery with trailing newlines
[[ "$observed" == "$instr" ]] || diff -u <(echo "$observed") <(printf "%s" "$instr")
}
|