suhasdantkale commented on a change in pull request #1107: ZOOKEEPER-2122: add
SSL support for C-client
URL: https://github.com/apache/zookeeper/pull/1107#discussion_r331557576
##########
File path: zookeeper-client/zookeeper-client-c/tests/TestReadOnlyClient.cc
##########
@@ -81,29 +85,68 @@ class Zookeeper_readOnly : public CPPUNIT_NS::TestFixture {
CPPUNIT_ASSERT(system(cmd) == 0);
}
- void testReadOnly() {
- startReadOnly();
- watchctx_t watch;
- zhandle_t* zh = zookeeper_init("localhost:22181",
- watcher,
- 10000,
- NULL,
- &watch,
- ZOO_READONLY);
- watch.zh = zh;
+ zhandle_t* connectReadOnly(const char *address, watchctx_t *watch) {
+ zhandle_t* zh = zookeeper_init(address, watcher, 10000, NULL, watch,
ZOO_READONLY);
+ watch->zh = zh;
CPPUNIT_ASSERT(zh != 0);
sleep(1);
+ return zh;
+ }
+
+ void assertCanRead(zhandle_t* zh, const char *znode_path) {
int len = 1024;
char buf[len];
- int res = zoo_get(zh, "/", 0, buf, &len, 0);
+ int res = zoo_get(zh, znode_path, 0, buf, &len, 0);
CPPUNIT_ASSERT_EQUAL((int)ZOK, res);
+ }
+ void assertCanNotWrite(zhandle_t* zh, const char *znode_path) {
char path[1024];
- res = zoo_create(zh, "/test", buf, 10, &ZOO_OPEN_ACL_UNSAFE, 0, path,
- 512);
+ char buf[1024];
+ int res = zoo_create(zh, znode_path, buf, 10, &ZOO_OPEN_ACL_UNSAFE, 0,
path, 512);
CPPUNIT_ASSERT_EQUAL((int)ZNOTREADONLY, res);
+ }
+
+ void testReadOnly()
+ {
+ startReadOnly();
+
+ watchctx_t watch;
+ zhandle_t* zh = connectReadOnly("localhost:22181", &watch);
+
+ assertCanRead(zh, "/");
+
+ assertCanNotWrite(zh, "/test");
+
+ stopPeer();
+ }
+
+#ifdef HAVE_OPENSSL_H
+
+ zhandle_t* connectReadOnlySSL(const char *address, const char *certs,
watchctx_t *watch) {
+ zhandle_t* zh = zookeeper_init_ssl(address, certs, watcher, 10000,
NULL, watch, ZOO_READONLY);
+ watch->zh = zh;
+ CPPUNIT_ASSERT(zh != 0);
+ sleep(1);
+ return zh;
+ }
+
+ void testReadOnlyWithSSL() {
Review comment:
Good to see this test being added.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services