コード例 #1
0
    def test_no_request(self):

        context = SecurityContext()
        context.token = Token('key', 'user')

        with self.assertRaises(NoRequestFoundException):
            AccessMapListener(AccessMap(), context, RoleHierarchy()).handle(Event())
コード例 #2
0
    def test_token_already_set(self):
        c = SecurityContext()
        c.token = Token('key', 'user')

        e = Event()
        h = AnonymousAuthenticationHandler('provider_name', c)

        h.handle(e)

        self.assertNotIsInstance(c.token, AnonymousToken)
コード例 #3
0
    def test_is_granted(self):
        context = SecurityContext()

        context.token = AnonymousToken('provider', 'ann.')

        self.assertFalse(context.is_granted(''))
        self.assertFalse(context.is_granted('role'))

        context.token.roles.append('role')

        self.assertTrue(context.is_granted('role'))
コード例 #4
0
    def test_no_rule_in_access_map(self):
        r = Request()
        r.path = ""

        context = SecurityContext()
        context.token = Token('key', 'user')

        with self.assertRaises(AccessDeniedException):
           AccessMapListener(AccessMap(), context, RoleHierarchy()).handle(Event({
                'request': r
            }))
コード例 #5
0
    def test_match(self):
        r = Request()
        r.path = "/blog/2012/12/12-myblog.html"

        context = SecurityContext()
        context.token = AnonymousToken('key', 'anon.', 'IS_AUTHENTICATED_ANONYMOUSLY')

        AccessMapListener(AccessMap([(re.compile("/blog.*"), ['IS_AUTHENTICATED_ANONYMOUSLY'])]), context, RoleHierarchy()).handle(Event({
            'request': r
        }))

        # mark the test as valid ...
        self.assertTrue(True)
コード例 #6
0
    def test_is_granted_with_no_token(self):
        context = SecurityContext()

        with self.assertRaises(AuthenticationCredentialsNotFoundException):
            context.is_granted('role')