]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test_msgr: add auth enabled basic test
authorHaomai Wang <haomaiwang@gmail.com>
Tue, 27 Jan 2015 15:13:07 +0000 (23:13 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Tue, 27 Jan 2015 16:24:57 +0000 (00:24 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/test/msgr/test_msgr.cc

index 85ad067978a90c7874b3bfb3f8b95f95aceaa2f4..7238b6aceefa905e475066464c9bae1b0e0effa9 100644 (file)
@@ -573,6 +573,57 @@ TEST_P(MessengerTest, ClientStandbyTest) {
   client_msgr->wait();
 }
 
+TEST_P(MessengerTest, AuthTest) {
+  g_ceph_context->_conf->set_val("auth_cluster_required", "cephx");
+  g_ceph_context->_conf->set_val("auth_service_required", "cephx");
+  g_ceph_context->_conf->set_val("auth_client_required", "cephx");
+  FakeDispatcher cli_dispatcher(false), srv_dispatcher(true);
+  entity_addr_t bind_addr;
+  bind_addr.parse("127.0.0.1");
+  server_msgr->bind(bind_addr);
+  server_msgr->add_dispatcher_head(&srv_dispatcher);
+  server_msgr->start();
+
+  client_msgr->add_dispatcher_head(&cli_dispatcher);
+  client_msgr->start();
+
+  // 1. simple auth round trip
+  MPing *m = new MPing();
+  ConnectionRef conn = client_msgr->get_connection(server_msgr->get_myinst());
+  {
+    ASSERT_EQ(conn->send_message(m), 0);
+    Mutex::Locker l(cli_dispatcher.lock);
+    while (!cli_dispatcher.got_new)
+      cli_dispatcher.cond.Wait(cli_dispatcher.lock);
+    cli_dispatcher.got_new = false;
+  }
+  ASSERT_TRUE(conn->is_connected());
+  ASSERT_TRUE((static_cast<Session*>(conn->get_priv()))->get_count() == 1);
+
+  // 2. mix auth
+  g_ceph_context->_conf->set_val("auth_cluster_required", "none");
+  g_ceph_context->_conf->set_val("auth_service_required", "none");
+  g_ceph_context->_conf->set_val("auth_client_required", "none");
+  conn->mark_down();
+  ASSERT_FALSE(conn->is_connected());
+  conn = client_msgr->get_connection(server_msgr->get_myinst());
+  {
+    MPing *m = new MPing();
+    ASSERT_EQ(conn->send_message(m), 0);
+    Mutex::Locker l(cli_dispatcher.lock);
+    while (!cli_dispatcher.got_new)
+      cli_dispatcher.cond.Wait(cli_dispatcher.lock);
+    cli_dispatcher.got_new = false;
+  }
+  ASSERT_TRUE(conn->is_connected());
+  ASSERT_TRUE((static_cast<Session*>(conn->get_priv()))->get_count() == 1);
+
+  server_msgr->shutdown();
+  client_msgr->shutdown();
+  server_msgr->wait();
+  client_msgr->wait();
+}
+
 class SyntheticDispatcher : public Dispatcher {
  public:
   Mutex lock;