コード例 #1
0
ファイル: strategy.py プロジェクト: strycore/django-mithril
    def test_get_authentication_backend_authenticate(self):
        Expected = object()

        class MyStrategy(CachedStrategy):
            partial_credential_lookup = (
                ('pk', 'pk'),
            )

        def authenticate(*args, **kwargs):
            return Expected

        base_backend = type('Any', (object,), {'authenticate':authenticate})
        new_backend = MyStrategy.get_authentication_backend(base_backend)

        backend = new_backend()

        whitelist = CachedWhitelist.objects.create(name='asdf', slug='asdf')
        whitelist.range_set.create(
            ip='0.0.0.0',
            cidr=32
        )

        # when the key isn't there.
        self.assertEqual(backend.authenticate(), None)

        # when the key is there and it fails.
        mithril.set_current_ip(fmt_ip(random.randint(1, 10)))
        self.assertEqual(backend.authenticate(pk=whitelist.pk), None)

        # when the key is there and it succeeds.
        mithril.set_current_ip(fmt_ip(0))
        self.assertEqual(backend.authenticate(pk=whitelist.pk), Expected)

        # when the key is there, but there are no whitelists
        mithril.set_current_ip(fmt_ip(0))
        self.assertEqual(backend.authenticate(pk=whitelist.pk+1), Expected)
コード例 #2
0
ファイル: strategy.py プロジェクト: strycore/django-mithril
 def tearDown(self):
     mithril.set_current_ip(None)