Exemple #1
0
        public void GetAccess_WithAccessControlExcptionFromAccessControlListFinder()
        {
            AccessControlException expectedException = new AccessControlException();

            using (_clientTransaction.EnterNonDiscardingScope())
            {
                Expect.Call(_mockAclFinder.Find(_context)).Throw(expectedException);
            }
            _mocks.ReplayAll();

            AccessType[] accessTypes = _service.GetAccess(_context, _principalStub);

            _mocks.VerifyAll();
            Assert.That(accessTypes.Length, Is.EqualTo(0));
            LoggingEvent[] events = _memoryAppender.GetEvents();
            Assert.That(events.Length, Is.EqualTo(1));
            Assert.That(events[0].ExceptionObject, Is.SameAs(expectedException));
            Assert.That(events[0].Level, Is.EqualTo(Level.Error));
        }
        public virtual void TestAuditLogWithAclFailure()
        {
            Configuration conf = new HdfsConfiguration();

            conf.SetBoolean(DFSConfigKeys.DfsNamenodeAclsEnabledKey, true);
            conf.Set(DFSConfigKeys.DfsNamenodeAuditLoggersKey, typeof(TestAuditLogger.DummyAuditLogger
                                                                      ).FullName);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build();

            try
            {
                cluster.WaitClusterUp();
                FSDirectory            dir       = cluster.GetNamesystem().GetFSDirectory();
                FSDirectory            mockedDir = Org.Mockito.Mockito.Spy(dir);
                AccessControlException ex        = new AccessControlException();
                Org.Mockito.Mockito.DoThrow(ex).When(mockedDir).GetPermissionChecker();
                cluster.GetNamesystem().SetFSDirectory(mockedDir);
                NUnit.Framework.Assert.IsTrue(TestAuditLogger.DummyAuditLogger.initialized);
                TestAuditLogger.DummyAuditLogger.ResetLogCount();
                FileSystem       fs   = cluster.GetFileSystem();
                Path             p    = new Path("/");
                IList <AclEntry> acls = Lists.NewArrayList();
                try
                {
                    fs.GetAclStatus(p);
                }
                catch (AccessControlException)
                {
                }
                try
                {
                    fs.SetAcl(p, acls);
                }
                catch (AccessControlException)
                {
                }
                try
                {
                    fs.RemoveAcl(p);
                }
                catch (AccessControlException)
                {
                }
                try
                {
                    fs.RemoveDefaultAcl(p);
                }
                catch (AccessControlException)
                {
                }
                try
                {
                    fs.RemoveAclEntries(p, acls);
                }
                catch (AccessControlException)
                {
                }
                try
                {
                    fs.ModifyAclEntries(p, acls);
                }
                catch (AccessControlException)
                {
                }
                NUnit.Framework.Assert.AreEqual(6, TestAuditLogger.DummyAuditLogger.logCount);
                NUnit.Framework.Assert.AreEqual(6, TestAuditLogger.DummyAuditLogger.unsuccessfulCount
                                                );
            }
            finally
            {
                cluster.Shutdown();
            }
        }