From 380a72113c2763a86fff90b420af1627b0f16eb5 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 24 Aug 2015 22:37:23 +0930 Subject: [PATCH] pin= query param for HTTP GET /restful/keyring/identities.json --- keyring_restful.c | 3 +++ tests/keyringrestful | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/keyring_restful.c b/keyring_restful.c index c4ae1047..81af3f36 100644 --- a/keyring_restful.c +++ b/keyring_restful.c @@ -76,6 +76,9 @@ static int restful_keyring_identitylist_json(httpd_request *r, const char *remai { if (*remainder) return 404; + const char *pin = http_request_get_query_param(&r->http, "pin"); + if (pin) + keyring_enter_pin(keyring, pin); r->u.sidlist.phase = LIST_HEADER; keyring_iterator_start(keyring, &r->u.sidlist.it); http_request_response_generated(&r->http, 200, CONTENT_TYPE_JSON, restful_keyring_identitylist_json_content); diff --git a/tests/keyringrestful b/tests/keyringrestful index 189e721d..c20b0731 100755 --- a/tests/keyringrestful +++ b/tests/keyringrestful @@ -94,7 +94,44 @@ test_keyringList() { assert [ "$(jq -r '.rows[9][0]' list.json)" = $SIDA10 ] } -doc_keyringAdd="HTTP RESTful add keyring identity with empty PIN" +doc_keyringListPin="HTTP RESTful list keyring identities as JSON, with PIN" +setup_keyringListPin() { + IDENTITY_COUNT=3 + PINA1='wif waf' + setup +} +test_keyringListPin() { + # First, list without supplying the PIN + executeOk curl \ + --silent --fail --show-error \ + --output list1.json \ + --dump-header http.headers \ + --basic --user harry:potter \ + "http://$addr_localhost:$PORTA/restful/keyring/identities.json" + tfw_cat http.headers list1.json + tfw_preserve list1.json + transform_list_json list1.json ids1.json + assert [ "$(jq 'length' ids1.json)" = $((IDENTITY_COUNT-1)) ] + assertJq ids1.json 'contains([{"sid": "'$SIDA1'"}]) | not' + assertJq ids1.json 'contains([{"sid": "'$SIDA2'"}])' + assertJq ids1.json 'contains([{"sid": "'$SIDA3'"}])' + # Then, list supplying the PIN + executeOk curl \ + --silent --fail --show-error \ + --output list2.json \ + --dump-header http.headers \ + --basic --user harry:potter \ + "http://$addr_localhost:$PORTA/restful/keyring/identities.json?pin=wif+waf" + tfw_cat http.headers list2.json + tfw_preserve list2.json + transform_list_json list2.json ids2.json + assert [ "$(jq 'length' ids2.json)" = $IDENTITY_COUNT ] + assertJq ids2.json 'contains([{"sid": "'$SIDA1'"}])' + assertJq ids2.json 'contains([{"sid": "'$SIDA2'"}])' + assertJq ids2.json 'contains([{"sid": "'$SIDA3'"}])' +} + +doc_keyringAdd="HTTP RESTful add keyring identity" setup_keyringAdd() { IDENTITY_COUNT=2 setup