Fix a failing keyringrestful test

The recent randomising of keyring slots broke an assumption
about the order of the 'keyring list' output.  Now the test's
assertions do not assume any order.
This commit is contained in:
Andrew Bettison 2016-09-21 12:16:15 +09:30
parent f615a1deca
commit 298b83f97b
2 changed files with 17 additions and 9 deletions

View File

@ -716,6 +716,9 @@ create_single_identity() {
# - set variables SID{I}{1..N} to SIDs of identities, eg, SIDA1, SIDA2... # - set variables SID{I}{1..N} to SIDs of identities, eg, SIDA1, SIDA2...
# - set variables DID{I}{1..N} to DIDs of identities, eg, DIDA1, DIDA2... # - set variables DID{I}{1..N} to DIDs of identities, eg, DIDA1, DIDA2...
# - set variables NAME{I}{1..N} to names of identities, eg, NAMEA1, NAMEA2... # - set variables NAME{I}{1..N} to names of identities, eg, NAMEA1, NAMEA2...
# - set array variable SID{I} to SIDs of identities, eg, SIDA[0], SIDA[1]...
# - set array variable DID{I} to DIDs of identities, eg, DIDA[0], DIDA[1]...
# - set array variable NAME{I} to names of identities, eg, NAMEA[0], NAMEA[1]...
create_identities() { create_identities() {
local servald_options=() local servald_options=()
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
@ -742,6 +745,9 @@ create_identities() {
local idvar=ID$instance_name$i local idvar=ID$instance_name$i
local didvar=DID$instance_name$i local didvar=DID$instance_name$i
local namevar=NAME$instance_name$i local namevar=NAME$instance_name$i
local sidarrayvar=SID$instance_name
local didarrayvar=DID$instance_name
local namearrayvar=NAME$instance_name
local pin="${!pinvar}" local pin="${!pinvar}"
[ -n "$pin" ] && tfw_log "$pinvar=$(shellarg "$pin")" [ -n "$pin" ] && tfw_log "$pinvar=$(shellarg "$pin")"
executeOk_servald keyring add "${servald_options[@]}" "$pin" executeOk_servald keyring add "${servald_options[@]}" "$pin"
@ -762,6 +768,10 @@ create_identities() {
extract_stdout_keyvalue_optional $didvar did "$rexp_did" extract_stdout_keyvalue_optional $didvar did "$rexp_did"
extract_stdout_keyvalue_optional $namevar name ".*" extract_stdout_keyvalue_optional $namevar name ".*"
fi fi
let a=i-1
eval "$sidarrayvar[$a]=\${!sidvar}"
eval "$didarrayvar[$a]=\${!didvar}"
eval "$namearrayvar[$a]=\${!namevar}"
done done
for ((i = 1; i <= N; ++i)); do for ((i = 1; i <= N; ++i)); do
for ((j = 1; j <= N; ++j)); do for ((j = 1; j <= N; ++j)); do

View File

@ -2,7 +2,8 @@
# Tests for Serval DNA HTTP RESTful interface # Tests for Serval DNA HTTP RESTful interface
# #
# Copyright 2013-2014 Serval Project, Inc. # Copyright 2013-2015 Serval Project, Inc.
# Copyright 2016 Flinders Univerity
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
@ -82,13 +83,10 @@ test_keyringList() {
tfw_cat http.headers list.json tfw_cat http.headers list.json
tfw_preserve list.json tfw_preserve list.json
assert [ "$(jq '.rows | length' list.json)" = $IDENTITY_COUNT ] assert [ "$(jq '.rows | length' list.json)" = $IDENTITY_COUNT ]
# TODO: these tests only work because the listed order of identities is the # All SIDs are present in the list.
# order of creation, which makes locked identities easy to attack. When the for SID in ${SIDA[*]}; do
# random search TODO in keyring.c:find_free_slot() is done, then these tests assert [ "$(jq -r '.rows | contains([["'"$SID"'"]])' list.json)" = true ]
# should fail. done
assert [ "$(jq -r '.rows[0][0]' list.json)" = $SIDA1 ]
assert [ "$(jq -r '.rows[4][0]' list.json)" = $SIDA5 ]
assert [ "$(jq -r '.rows[9][0]' list.json)" = $SIDA10 ]
} }
doc_keyringListPin="HTTP RESTful list keyring identities as JSON, with PIN" doc_keyringListPin="HTTP RESTful list keyring identities as JSON, with PIN"