pin= query param for HTTP GET /restful/keyring/add

This commit is contained in:
Andrew Bettison 2015-08-24 17:42:26 +09:30
parent ce7a6ba988
commit 73ced0f93a
2 changed files with 25 additions and 1 deletions

View File

@ -159,7 +159,8 @@ static int restful_keyring_add(httpd_request *r, const char *remainder)
{ {
if (*remainder) if (*remainder)
return 404; return 404;
const keyring_identity *id = keyring_create_identity(keyring, ""); const char *pin = http_request_get_query_param(&r->http, "pin");
const keyring_identity *id = keyring_create_identity(keyring, pin ? pin : "");
if (id == NULL) if (id == NULL)
return http_request_keyring_response(r, 501, "Could not create identity"); return http_request_keyring_response(r, 501, "Could not create identity");
const sid_t *sidp = NULL; const sid_t *sidp = NULL;

View File

@ -112,4 +112,27 @@ test_keyringAdd() {
assertStdoutGrep --stderr --matches=1 "^$SID::\$" assertStdoutGrep --stderr --matches=1 "^$SID::\$"
} }
doc_keyringAddPin="HTTP RESTful add keyring identity with non-empty PIN"
setup_keyringAddPin() {
IDENTITY_COUNT=2
setup
}
test_keyringAddPin() {
executeOk curl \
--silent --fail --show-error \
--output add.json \
--dump-header http.headers \
--basic --user harry:potter \
"http://$addr_localhost:$PORTA/restful/keyring/add?pin=1234"
tfw_cat http.headers add.json
tfw_preserve add.json
SID="$(jq -r '.sid' add.json)"
executeOk_servald keyring list
assert_keyring_list 2
assertStdoutGrep --stderr --matches=0 "^$SID::\$"
executeOk_servald keyring list --entry-pin=1234
assert_keyring_list 3
assertStdoutGrep --stderr --matches=1 "^$SID::\$"
}
runTests "$@" runTests "$@"