}
// Modify request.
+ int extra = 0;
+ ConstElementPtr extra_elem = command->get("extra");
ElementPtr mutable_command = boost::const_pointer_cast<Element>(command);
- if (command->contains("service")) {
- mutable_command->remove("service");
+ if (extra_elem) {
+ if (extra_elem->getType() == Element::integer) {
+ extra = extra_elem->intValue();
+ }
+ mutable_command->remove("extra");
request_json->setBodyAsJson(command);
}
+ handle.setContext("extra", extra);
// Perform authentication.
response = impl->config_->checkAuth(*impl->creator_, request);
return (0);
}
ElementPtr mutable_answer = boost::const_pointer_cast<Element>(answer);
- mutable_answer->set("comment", Element::create(string("got")));
+ try {
+ int extra = 0;
+ handle.getContext("extra", extra);
+ mutable_answer->set("got", Element::create(extra));
+ } catch (const NoSuchCalloutContext&) {
+ std::cerr << "can't find 'extra' context\n";
+ } catch (...) {
+ std::cerr << "getContext('extra') failed\n";
+ }
response->setBodyAsJson(body);
// Set parameters.
#include <agent/ca_command_mgr.h>
#include <agent/ca_response_creator.h>
#include <cc/command_interpreter.h>
+#include <cryptolink/crypto_rng.h>
#include <hooks/hooks_manager.h>
#include <http/basic_auth_config.h>
#include <http/post_request.h>
setBasicContext(request_);
// Body: "list-commands" is natively supported by the command manager.
- request_->context()->body_ = "{ \"command\": \"list-commands\","
- " \"service\": [ ] }";
+ auto r32 = isc::cryptolink::random(4);
+ ASSERT_EQ(4, r32.size());
+ int extra = r32[0];
+ extra = (extra << 8) | r32[1];
+ extra = (extra << 8) | r32[2];
+ extra = (extra << 8) | r32[3];
+ request_->context()->body_ = "{ \"command\": \"list-commands\", ";
+ request_->context()->body_ += "\"extra\": " + std::to_string(extra) + " }";
// All requests must be finalized before they can be processed.
ASSERT_NO_THROW(request_->finalize());
ASSERT_NO_THROW(response = response_creator_.createHttpResponse(request_));
ASSERT_TRUE(response);
- // Request should have no service.
+ // Request should have no extra.
EXPECT_EQ("{ \"command\": \"list-commands\" }",
request_->context()->body_);
setBasicContext(request_);
// Body: "list-commands" is natively supported by the command manager.
- request_->context()->body_ = "{ \"command\": \"list-commands\" }";
+ auto r32 = isc::cryptolink::random(4);
+ ASSERT_EQ(4, r32.size());
+ int extra = r32[0];
+ extra = (extra << 8) | r32[1];
+ extra = (extra << 8) | r32[2];
+ extra = (extra << 8) | r32[3];
+ if (extra == 0) {
+ extra = 1;
+ }
+ std::string extra_str = std::to_string(extra);
+ request_->context()->body_ = "{ \"command\": \"list-commands\", ";
+ request_->context()->body_ += "\"extra\": " + extra_str + " }";
// Add basic HTTP authentication header.
const BasicHttpAuth& basic_auth = BasicHttpAuth("foo", "bar");
ASSERT_NO_THROW(response = response_creator_.createHttpResponse(request_));
ASSERT_TRUE(response);
+ // Request should have no extra.
+ EXPECT_EQ("{ \"command\": \"list-commands\" }",
+ request_->context()->body_);
+
// Response must be convertible to HttpResponseJsonPtr.
HttpResponseJsonPtr response_json = boost::dynamic_pointer_cast<
HttpResponseJson>(response);
EXPECT_TRUE(response_json->toString().find("\"result\": 0") !=
std::string::npos);
// Response must contain JSON body with "comment": "got".
- EXPECT_TRUE(response_json->toString().find("\"comment\": \"got\"") !=
+ std::string expected = "\"got\": " + extra_str + ", ";
+ EXPECT_TRUE(response_json->toString().find(expected) !=
std::string::npos);
}