summaryrefslogtreecommitdiff
path: root/test/RpcMethodTest.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2014-02-02 17:34:07 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2014-02-02 17:34:07 +0900
commit7f6987a4b4950e77597fd1a4fd5d8c60e6209f07 (patch)
tree8f7e29ddad65e1bf61abb406f01a4a342536c9f4 /test/RpcMethodTest.cc
parent30e4077440e93a9e78cf55a3a1a4e295ae5e9a72 (diff)
Implement new RPC authorization using --rpc-secret option
Diffstat (limited to 'test/RpcMethodTest.cc')
-rw-r--r--test/RpcMethodTest.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/RpcMethodTest.cc b/test/RpcMethodTest.cc
index 15a94b45..07ccddfa 100644
--- a/test/RpcMethodTest.cc
+++ b/test/RpcMethodTest.cc
@@ -33,6 +33,7 @@ namespace rpc {
class RpcMethodTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RpcMethodTest);
+ CPPUNIT_TEST(testAuthorize);
CPPUNIT_TEST(testAddUri);
CPPUNIT_TEST(testAddUri_withoutUri);
CPPUNIT_TEST(testAddUri_notUri);
@@ -96,6 +97,7 @@ public:
(std::vector<std::shared_ptr<RequestGroup>>{}, 1, option_.get()));
}
+ void testAuthorize();
void testAddUri();
void testAddUri_withoutUri();
void testAddUri_notUri();
@@ -159,6 +161,47 @@ RpcRequest createReq(std::string methodName)
}
} // namespace
+void RpcMethodTest::testAuthorize()
+{
+ // Select RPC method which takes non-string parameter to make sure
+ // that token: prefixed parameter is stripped before the call.
+ TellActiveRpcMethod m;
+ // no secret token set and no token: prefixed parameter is given
+ {
+ auto req = createReq(TellActiveRpcMethod::getMethodName());
+ auto res = m.execute(std::move(req), e_.get());
+ CPPUNIT_ASSERT_EQUAL(0, res.code);
+ }
+ // no secret token set and token: prefixed parameter is given
+ {
+ auto req = createReq(GetVersionRpcMethod::getMethodName());
+ req.params->append("token:foo");
+ auto res = m.execute(std::move(req), e_.get());
+ CPPUNIT_ASSERT_EQUAL(0, res.code);
+ }
+ e_->getOption()->put(PREF_RPC_SECRET, "foo");
+ // secret token set and no token: prefixed parameter is given
+ {
+ auto req = createReq(GetVersionRpcMethod::getMethodName());
+ auto res = m.execute(std::move(req), e_.get());
+ CPPUNIT_ASSERT_EQUAL(1, res.code);
+ }
+ // secret token set and token: prefixed parameter is given
+ {
+ auto req = createReq(GetVersionRpcMethod::getMethodName());
+ req.params->append("token:foo");
+ auto res = m.execute(std::move(req), e_.get());
+ CPPUNIT_ASSERT_EQUAL(0, res.code);
+ }
+ // secret token set and bad token: prefixed parameter is given
+ {
+ auto req = createReq(GetVersionRpcMethod::getMethodName());
+ req.params->append("token:foo2");
+ auto res = m.execute(std::move(req), e_.get());
+ CPPUNIT_ASSERT_EQUAL(1, res.code);
+ }
+}
+
void RpcMethodTest::testAddUri()
{
AddUriRpcMethod m;