diff options
-rw-r--r-- | libbbot/manifest.cxx | 12 | ||||
-rw-r--r-- | libbbot/manifest.hxx | 4 | ||||
-rw-r--r-- | tests/manifest/result-request.test | 21 |
3 files changed, 26 insertions, 11 deletions
diff --git a/libbbot/manifest.cxx b/libbbot/manifest.cxx index 06399f2..02a5b05 100644 --- a/libbbot/manifest.cxx +++ b/libbbot/manifest.cxx @@ -14,6 +14,7 @@ #include <cstdint> // uint64_t #include <stdexcept> // invalid_argument +#include <libbutl/base64.hxx> #include <libbutl/utility.hxx> // digit() #include <libbutl/tab-parser.hxx> #include <libbutl/string-parser.hxx> @@ -999,7 +1000,14 @@ namespace bbot if (v.empty ()) bad_value ("empty result request challenge"); - challenge = move (v); + try + { + challenge = base64_decode (v); + } + catch (const invalid_argument&) + { + bad_value ("invalid result request challenge"); + } } else if (!iu) bad_name ("unknown name '" + n + "' in result request manifest"); @@ -1034,7 +1042,7 @@ namespace bbot s.next ("session", session); if (challenge) - s.next ("challenge", *challenge); + s.next ("challenge", base64_encode (*challenge)); s.next ("", ""); // End of manifest. diff --git a/libbbot/manifest.hxx b/libbbot/manifest.hxx index 4ae8b26..b981ab4 100644 --- a/libbbot/manifest.hxx +++ b/libbbot/manifest.hxx @@ -296,12 +296,12 @@ namespace bbot // The answer to challenge in the task response. // - butl::optional<std::string> challenge; + butl::optional<std::vector<char>> challenge; result_manifest result; result_request_manifest (std::string s, - butl::optional<std::string> c, + butl::optional<std::vector<char>> c, result_manifest r) : session (std::move (s)), challenge (std::move (c)), diff --git a/tests/manifest/result-request.test b/tests/manifest/result-request.test index 3e1e08c..f4845e6 100644 --- a/tests/manifest/result-request.test +++ b/tests/manifest/result-request.test @@ -14,7 +14,7 @@ test.options += -rq $* <<EOF >>EOF : 1 session: abcd - challenge: xyz + challenge: YQo= : name: libfoo version: 1.0 @@ -49,15 +49,15 @@ test.options += -rq : $* <<EOI 2>'stdin:3:1: error: result request challenge redefinition' == 1 : 1 - challenge: xyz - challenge: xyz + challenge: YQo= + challenge: YQo= EOI } -: empty +: invalid : { - : session + : empty-session : $* <<EOI 2>'stdin:2:9: error: empty result request session' == 1 : 1 @@ -66,6 +66,13 @@ test.options += -rq : challenge : + $* <<EOI 2>'stdin:2:12: error: invalid result request challenge' == 1 + : 1 + challenge: abc + EOI + + : empty-challenge + : $* <<EOI 2>'stdin:2:11: error: empty result request challenge' == 1 : 1 challenge: @@ -86,7 +93,7 @@ EOI : $* <<EOI 2>'stdin:3:1: error: no result request session specified' == 1 : 1 - challenge: xyz + challenge: YQo= EOI : result @@ -94,6 +101,6 @@ EOI $* <<EOI 2>'stdin:4:1: error: result manifest expected' == 1 : 1 session: abc - challenge: xyz + challenge: YQo= EOI } |