def test_actionAllowed_AuthCallable(self):
     myargs = []
     def myAuthzFn(*args):
         myargs.extend(args)
     z = Authz(auth=StubAuth('uu'),
               stopBuild=myAuthzFn)
     z.actionAllowed('stopBuild', StubRequest('uu', 'shh'), 'arg', 'arg2')
     self.assertEqual(myargs, ['uu', 'arg', 'arg2'])
    def test_actionAllowed_AuthCallable(self):
        myargs = []

        def myAuthzFn(*args):
            myargs.extend(args)

        z = Authz(auth=StubAuth('uu'), stopBuild=myAuthzFn)
        z.actionAllowed('stopBuild', StubRequest('uu', 'shh'), 'arg', 'arg2')
        self.assertEqual(myargs, ['uu', 'arg', 'arg2'])
    def test_actionAllowed_Defaults(self):
        "by default, nothing is allowed"
        z = Authz()
        self.failedActions = []
        self.dl = []
        for a in Authz.knownActions:
            md = z.actionAllowed(a, StubRequest('foo', 'bar'))

            def check(res):
                if res:
                    self.failedActions.append(a)
                return

            md.addCallback(check)
            self.dl.append(md)
        d = defer.DeferredList(self.dl)

        def check_failed(_):
            if self.failedActions:
                raise unittest.FailTest(
                    "action(s) %s do not default to False" %
                    (self.failedActions, ))

        d.addCallback(check_failed)
        return d
    def test_actionAllowed_Defaults(self):
        "by default, nothing is allowed"
        z = Authz()
        self.failedActions = []
        self.dl = []
        for a in Authz.knownActions:
            md = z.actionAllowed(a, StubRequest('foo', 'bar'))

            def check(res, expected):
                if res != expected:
                    self.failedActions.append((a, expected))
                return

            md.addCallback(check, a == 'view')
            self.dl.append(md)
        d = defer.DeferredList(self.dl)

        def check_failed(_):
            if self.failedActions:
                msgs = '; '.join('%s action authz did not default to %s' % f
                                 for f in self.failedActions)
                raise unittest.FailTest(msgs)

        d.addCallback(check_failed)
        return d
    def test_actionAllowed_AuthCallableFalse(self):
        def myAuthzFn(*args):
            return False

        z = Authz(auth=StubAuth('uu'), stopBuild=myAuthzFn)
        self.assertFalse(z.actionAllowed('stopBuild', StubRequest('uu',
                                                                  'shh')))
 def test_actionAllowed_AuthCallableFalse(self):
     def myAuthzFn(*args):
         return False
     z = Authz(auth=StubAuth('uu'),
               stopBuild=myAuthzFn)
     self.assertFalse(z.actionAllowed('stopBuild',
                         StubRequest('uu', 'shh')))
 def test_actionAllowed_Positive(self):
     "'True' should always permit access"
     z = Authz(forceBuild=True)
     d = z.actionAllowed('forceBuild', StubRequest('foo', 'bar'))
     def check(res):
         self.assertEqual(res, True)
     d.addCallback(check)
     return d
 def test_actionAllowed_AuthNegative(self):
     z = Authz(auth=StubAuth('jrobinson'),
               stopBuild='auth')
     d = z.actionAllowed('stopBuild', StubRequest('apeterson', 'bar'))
     def check(res):
         self.assertEqual(res, False)
     d.addCallback(check)
     return d
 def test_actionAllowed_Positive(self):
     "'True' should always permit access"
     z = Authz(forceBuild=True)
     d = z.actionAllowed('forceBuild', StubRequest('foo', 'bar'))
     def check(res):
         self.assertEqual(res, True)
     d.addCallback(check)
     return d
 def test_actionAllowed_AuthPositive(self):
     z = Authz(auth=StubAuth('jrobinson'),
               stopBuild='auth')
     d = z.actionAllowed('stopBuild', StubRequest('jrobinson', 'bar'))
     def check(res):
         self.assertEqual(res, True)
     d.addCallback(check)
     return d
    def test_actionAllowed_AuthPositive(self):
        z = Authz(auth=StubAuth("jrobinson"), stopBuild="auth")
        d = z.actionAllowed("stopBuild", StubRequest("jrobinson", "bar"))

        def check(res):
            self.assertEqual(res, True)

        d.addCallback(check)
        return d
 def test_actionAllowed_Defaults(self):
     "by default, nothing is allowed"
     z = Authz()
     failedActions = []
     for a in Authz.knownActions:
         if z.actionAllowed(a, StubRequest('foo', 'bar')):
             failedActions.append(a)
     if failedActions:
         raise unittest.FailTest("action(s) %s do not default to False" %
                                 (failedActions, ))
 def test_actionAllowed_Defaults(self):
     "by default, nothing is allowed"
     z = Authz()
     failedActions = []
     for a in Authz.knownActions:
         if z.actionAllowed(a, StubRequest('foo', 'bar')):
             failedActions.append(a)
     if failedActions:
         raise unittest.FailTest("action(s) %s do not default to False"
                     % (failedActions,))
 def test_actionAllowed_AuthCallableFalse(self):
     def myAuthzFn(*args):
         return False
     z = Authz(auth=StubAuth('uu'),
               stopBuild=myAuthzFn)
     d = z.actionAllowed('stopBuild', StubRequest('uu', 'shh'))
     def check(res):
         self.assertEqual(res, False)
     d.addCallback(check)
     return d
 def test_actionAllowed_AuthCallableFalse(self):
     def myAuthzFn(*args):
         return False
     z = Authz(auth=StubAuth('uu'),
               stopBuild=myAuthzFn)
     d = z.actionAllowed('stopBuild', StubRequest('uu', 'shh'))
     def check(res):
         self.assertEqual(res, False)
     d.addCallback(check)
     return d
 def test_actionAllowed_AuthCallable(self):
     myargs = []
     def myAuthzFn(*args):
         myargs.extend(args)
     z = Authz(auth=StubAuth('uu'),
               stopBuild=myAuthzFn)
     d = z.actionAllowed('stopBuild', StubRequest('uu', 'shh'), 'arg', 'arg2')
     def check(res):
         self.assertEqual(myargs, ['uu', 'arg', 'arg2'])
     d.addCallback(check)
     return d
 def test_actionAllowed_AuthCallable(self):
     myargs = []
     def myAuthzFn(*args):
         myargs.extend(args)
     z = Authz(auth=StubAuth('uu'),
               stopBuild=myAuthzFn)
     d = z.actionAllowed('stopBuild', StubRequest('uu', 'shh'), 'arg', 'arg2')
     def check(res):
         self.assertEqual(myargs, ['uu', 'arg', 'arg2'])
     d.addCallback(check)
     return d
    def test_actionAllowed_AuthCallableTrue(self):
        def myAuthzFn(*args):
            return True

        z = Authz(auth=StubAuth("uu"), stopBuild=myAuthzFn)
        d = z.actionAllowed("stopBuild", StubRequest("uu", "shh"))

        def check(res):
            self.assertEqual(res, True)

        d.addCallback(check)
        return d
    def test_actionAllowed_AuthCallable(self):
        myargs = []

        def myAuthzFn(*args):
            myargs.extend(args)

        z = Authz(auth=StubAuth("uu"), stopBuild=myAuthzFn)
        d = z.actionAllowed("stopBuild", StubRequest("uu", "shh"), "arg", "arg2")

        def check(res):
            self.assertEqual(myargs, ["uu", "arg", "arg2"])

        d.addCallback(check)
        return d
 def test_actionAllowed_Defaults(self):
     "by default, nothing is allowed"
     z = Authz()
     self.failedActions = []
     self.dl = []
     for a in Authz.knownActions:
         md = z.actionAllowed(a, StubRequest('foo', 'bar'))
         def check(res):
             if res:
                 self.failedActions.append(a)
             return
         md.addCallback(check)
         self.dl.append(md)
     d = defer.DeferredList(self.dl)
     def check_failed(_):
         if self.failedActions:
             raise unittest.FailTest("action(s) %s do not default to False"
                                     % (self.failedActions,))
     d.addCallback(check_failed)
     return d
 def test_actionAllowed_AuthNegative(self):
     z = Authz(auth=StubAuth('jrobinson'),
               stopBuild='auth')
     assert not z.actionAllowed('stopBuild',
                         StubRequest('apeterson', 'bar'))
 def test_actionAllowed_Positive(self):
     "'True' should always permit access"
     z = Authz(forceBuild=True)
     assert z.actionAllowed('forceBuild', StubRequest('foo', 'bar'))
 def test_actionAllowed_AuthNegative(self):
     z = Authz(auth=StubAuth('jrobinson'), stopBuild='auth')
     assert not z.actionAllowed('stopBuild', StubRequest(
         'apeterson', 'bar'))
 def test_actionAllowed_Positive(self):
     "'True' should always permit access"
     z = Authz(forceBuild=True)
     assert z.actionAllowed('forceBuild',
                         StubRequest('foo', 'bar'))