public void testSaslBadCredentials() { var saslClient = new S22SaslClient() { Password = "******" }; var watcher = new StateWatcher(KeeperState.AuthFailed, true); using (var zk = CreateClientWithSasl(watcher, saslClient)) { Assert.IsTrue(watcher.WaitSignaled(maxWaitMs)); Assert.AreEqual(ZooKeeper.States.AUTH_FAILED, zk.State); Assert.IsFalse(zk.State.IsAlive()); // We must have been connected before failing authentication. Assert.IsTrue(watcher.Observed.Contains(KeeperState.SyncConnected)); } }
public void testSasl() { string name = "/" + Guid.NewGuid() + "sasltest"; var authWatcher = new StateWatcher(KeeperState.SaslAuthenticated); using (var zk = CreateClientWithSasl(authWatcher, new S22SaslClient())) { Assert.IsTrue(authWatcher.WaitSignaled(maxWaitMs)); List <ACL> acl = new List <ACL>(); acl.Add(new ACL(Perms.ALL, new ZKId("sasl", "bob"))); Assert.AreEqual(name, zk.Create(name, new byte[0], acl, CreateMode.Persistent)); } var connWatcher = new StateWatcher(KeeperState.SyncConnected); using (var zk = CreateClient(connWatcher)) { Assert.IsTrue(connWatcher.WaitSignaled(maxWaitMs)); try { zk.GetData(name, false, new Stat()); Assert.Fail("Should have received a permission error"); } catch (KeeperException e) { Assert.AreEqual(KeeperException.Code.NOAUTH, e.ErrorCode); } } var authWatcher2 = new StateWatcher(KeeperState.SaslAuthenticated); using (var zk = CreateClientWithSasl(authWatcher2, new S22SaslClient())) { Assert.IsTrue(authWatcher2.WaitSignaled(maxWaitMs)); zk.GetData(name, false, new Stat()); zk.Delete(name, -1); } }