Пример #1
0
    def test_redaction(self):

        all_tags = r'|'.join(
            re.escape(v) for k, v in _LCB.__dict__.items()
            if re.match(r'.*LCB_LOG_(SD|MD|UD)_[OC]TAG.*', k))

        enable_logging()
        try:
            contains_no_tags = r'^(.(?!<' + all_tags + r'))*$'
            contains_tags = r'^.*(' + all_tags + r').*$'
            expected = {
                0: {
                    logging.DEBUG: {
                        'text': 'off',
                        'pattern': contains_no_tags
                    }
                },
                1: {
                    logging.DEBUG: {
                        'text': 'on',
                        'pattern': contains_tags
                    }
                }
            }

            for num, entry in reversed(list(expected.items())):
                for level, val in entry.items():

                    optype = 'connstr'
                    with self.assertLogs(level=level,
                                         recursive_check=True) as cm:
                        curbc = self.make_connection(log_redaction=val['text'])
                        self.assertEqual(num != 0, curbc.redaction != 0)
                    result_str = ''.join(cm.output)
                    logging.info(
                        'checking {pattern} matches {optype} addition {text} result:{result_str}'
                        .format(optype=optype, result_str=result_str, **val))
                    self.assertRegex(result_str, val['pattern'])

                    opposite = 1 - num
                    opposite_val = expected[opposite][level]

                    optype = 'cntl'
                    with self.assertLogs(level=level) as cm:
                        curbc.redaction = opposite
                        curbc.upsert(key='test', value='value')
                        self.assertEqual(opposite != 0, curbc.redaction != 0)

                    result_str = ''.join(cm.output)
                    logging.info(
                        'checking {pattern} matches {optype} addition {text} result:{result_str}'
                        .format(optype=optype, result_str=result_str, **val))
                    self.assertRegex(''.join(cm.output),
                                     opposite_val['pattern'])
        finally:
            couchbase.disable_logging()
Пример #2
0
 def tearDown(self):
     if self.trace_all and not self.using_jaeger:
         self.flush_tracer()
     super(TracedCase,self).tearDown()
     couchbase.disable_logging()
     if self.tracer and getattr(self.tracer,"close", None):
         try:
             time.sleep(2)   # yield to IOLoop to flush the spans - https://github.com/jaegertracing/jaeger-client-python/issues/50
             self.tracer.close()  # flush any buffered spans
         except:
             pass
Пример #3
0
 def tearDown(self):
     if self.trace_all and not self.using_jaeger:
         self.flush_tracer()
     super(TracedCase,self).tearDown()
     couchbase.disable_logging()
     if self.tracer and getattr(self.tracer,"close", None):
         try:
             time.sleep(2)   # yield to IOLoop to flush the spans - https://github.com/jaegertracing/jaeger-client-python/issues/50
             self.tracer.close()  # flush any buffered spans
         except:
             pass
Пример #4
0
    def test_logging(self):
        # Assume we don't have logging here..
        import couchbase._libcouchbase as lcb

        self.assertFalse(lcb.lcb_logging())

        logfn = lambda x: x
        lcb.lcb_logging(logfn)
        self.assertEqual(logfn, lcb.lcb_logging())

        couchbase.enable_logging()
        self.assertTrue(lcb.lcb_logging())
        couchbase.disable_logging()
        self.assertFalse(lcb.lcb_logging())
Пример #5
0
    def test_logging(self):
        # Assume we don't have logging here..
        import couchbase._libcouchbase as lcb

        self.assertFalse(lcb.lcb_logging())

        logfn = lambda x: x
        lcb.lcb_logging(logfn)
        self.assertEqual(logfn, lcb.lcb_logging())

        couchbase.enable_logging()
        self.assertTrue(lcb.lcb_logging())
        couchbase.disable_logging()
        self.assertFalse(lcb.lcb_logging())
Пример #6
0
    def test_redaction(self):

        all_tags = r'|'.join(re.escape(v) for k, v in _LCB.__dict__.items() if
                             re.match(r'.*LCB_LOG_(SD|MD|UD)_[OC]TAG.*', k))

        enable_logging()
        try:
            contains_no_tags = r'^(.(?!<' + all_tags + r'))*$'
            contains_tags = r'^.*(' + all_tags + r').*$'
            expected = {0: {logging.DEBUG: {'text': 'off', 'pattern': contains_no_tags}},
                        1: {logging.DEBUG: {'text': 'on', 'pattern': contains_tags}}}

            for num, entry in reversed(list(expected.items())):
                for level, val in entry.items():

                    optype='connstr'
                    with self.assertLogs(level=level, recursive_check=True) as cm:
                        curbc = self.make_connection(log_redaction=val['text'])
                        self.assertEqual(num != 0, curbc.redaction != 0)
                    result_str=''.join(cm.output)
                    logging.info(
                        'checking {pattern} matches {optype} addition {text} result:{result_str}'.format(optype=optype,
                                                                                                         result_str=result_str,
                                                                                                         **val))
                    self.assertRegex(result_str, val['pattern'])

                    opposite = 1 - num
                    opposite_val = expected[opposite][level]

                    optype='cntl'
                    with self.assertLogs(level=level) as cm:
                        curbc.redaction = opposite
                        curbc.upsert(key='test', value='value')
                        self.assertEqual(opposite != 0, curbc.redaction != 0)

                    result_str=''.join(cm.output)
                    logging.info(
                        'checking {pattern} matches {optype} addition {text} result:{result_str}'.format(optype=optype,
                                                                                                         result_str=result_str,
                                                                                                         **val))
                    self.assertRegex(''.join(cm.output), opposite_val['pattern'])
        finally:
            couchbase.disable_logging()
Пример #7
0
 def tearDown(self):
     super(TimeoutTest, self).tearDown()
     couchbase.disable_logging()
 def tearDown(self):
     super(TimeoutTest, self).tearDown()
     couchbase.disable_logging()