示例#1
0
    def setUp(self):

        self.backend = MockDjangoAuthorizingBackend(
            django_project_path=DJANGO_PROJECT_DIR,
            django_settings_module=DJANGO_SETTINGS_MODULE)
    def setUp(self):

        self.backend = MockDjangoAuthorizingBackend(
            django_project_path=DJANGO_PROJECT_DIR, django_settings_module=DJANGO_SETTINGS_MODULE
        )
示例#3
0
class TestMockDjangoAuthorizingBackend(TestCase):
    def setUp(self):

        self.backend = MockDjangoAuthorizingBackend(
            django_project_path=DJANGO_PROJECT_DIR,
            django_settings_module=DJANGO_SETTINGS_MODULE)

    def test_messages(self):
        msg = "version\n"
        response = self.backend.handle(msg)
        self.assertEqual(response, "%s\n" % opentsdbproxy.__version__)

        # Make sure messages with no username/password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca\n"
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with bad username/password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("joshua", "pencil")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with good username and bad password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("root", "pencil")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with good username and no password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s\n"
        msg = msg % "root"
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with good username and good password get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("root", "root")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        msg_password_stripped = msg.replace(' password=root', '')
        self.assertIn(msg_password_stripped, self.backend.authzed_messages)

        self.backend.reset()

        # Make sure messages with two parts and good username and good password get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg += "put test.my.value 1366155635 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("root", "root", "root", "root")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)

        msg_password_stripped = msg.replace(' password=root', '')
        self.assertIn(msg_password_stripped, self.backend.authzed_messages)

        self.backend.reset()

        # Make sure messages with some auth lines and some not auth lines are
        # handled appropriately
        good_msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n" % (
            "root", "root")
        bad_msg = "put test.my.value 1366155635 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n" % (
            "root", "bad")
        msg = good_msg + bad_msg
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)

        good_msg_password_stripped = good_msg.replace(' password=root', '')
        self.assertIn(good_msg_password_stripped,
                      self.backend.authzed_messages)
class TestMockDjangoAuthorizingBackend(TestCase):
    def setUp(self):

        self.backend = MockDjangoAuthorizingBackend(
            django_project_path=DJANGO_PROJECT_DIR, django_settings_module=DJANGO_SETTINGS_MODULE
        )

    def test_messages(self):
        msg = "version\n"
        response = self.backend.handle(msg)
        self.assertEqual(response, "%s\n" % opentsdbproxy.__version__)

        # Make sure messages with no username/password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca\n"
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with bad username/password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("joshua", "pencil")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with good username and bad password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("root", "pencil")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with good username and no password don't get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s\n"
        msg = msg % "root"
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        self.assertEqual(0, len(self.backend.authzed_messages))

        self.backend.reset()

        # Make sure messages with good username and good password get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("root", "root")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)
        msg_password_stripped = msg.replace(" password=root", "")
        self.assertIn(msg_password_stripped, self.backend.authzed_messages)

        self.backend.reset()

        # Make sure messages with two parts and good username and good password get through
        msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg += "put test.my.value 1366155635 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n"
        msg = msg % ("root", "root", "root", "root")
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)

        msg_password_stripped = msg.replace(" password=root", "")
        self.assertIn(msg_password_stripped, self.backend.authzed_messages)

        self.backend.reset()

        # Make sure messages with some auth lines and some not auth lines are
        # handled appropriately
        good_msg = "put test.my.value 1366155625 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n" % (
            "root",
            "root",
        )
        bad_msg = "put test.my.value 1366155635 42 host=bandersnatch.phys.uvic.ca user=%s password=%s\n" % (
            "root",
            "bad",
        )
        msg = good_msg + bad_msg
        response = self.backend.handle(msg)
        self.assertIsNone(response)
        self.assertIn(msg, self.backend.messages)

        good_msg_password_stripped = good_msg.replace(" password=root", "")
        self.assertIn(good_msg_password_stripped, self.backend.authzed_messages)