#NEWLINE# def test_access_controller( self ) : #NEWLINE# #INDENT# logging . debug ( '' ) #NEWLINE# logging . debug ( 'test_access_controller' ) #NEWLINE# owner = get_credentials ( ) #NEWLINE# controller = AccessController ( ) #NEWLINE# self . assertEqual ( controller . get_role ( None ) , '' ) #NEWLINE# self . assertEqual ( controller . get_role ( owner ) , 'owner' ) #NEWLINE# user = Credentials ( ) #NEWLINE# user . user = 'anyone@hostname' #NEWLINE# self . assertEqual ( controller . get_role ( user ) , 'user' ) #NEWLINE# assert_raises ( self , 'controller.get_role(object())' , globals ( ) , locals ( ) , TypeError , 'credentials is not a Credentials object' ) #NEWLINE# obj = Object ( ) #NEWLINE# assert_raises ( self , 'controller.get_proxy_credentials(obj.no_rbac, user)' , globals ( ) , locals ( ) , RoleError , 'No RBAC for method' ) #NEWLINE# self . assertEqual ( controller . get_proxy_credentials ( obj . single_role , user ) , user ) #NEWLINE# self . assertEqual ( controller . get_proxy_credentials ( obj . proxy_role , user ) , owner ) #NEWLINE# assert_raises ( self , 'controller.get_proxy_credentials(obj.proxy_other, user)' , globals ( ) , locals ( ) , RoleError , 'No credentials for proxy role other' ) #NEWLINE# assert_raises ( self , "controller.set_proxy_credentials('other', object())" , globals ( ) , locals ( ) , TypeError , 'credentials is not a Credentials object' ) #NEWLINE# other = Credentials ( ) #NEWLINE# other . user = 'floyd@nowheresville' #NEWLINE# controller . set_proxy_credentials ( 'other' , other ) #NEWLINE# self . assertEqual ( controller . get_proxy_credentials ( obj . proxy_other , user ) , other ) #NEWLINE# controller . check_access ( 'user' , '__getattr__' , obj , 'dummy' ) #NEWLINE# controller . check_access ( 'owner' , '__setattr__' , obj , 'dummy' ) #NEWLINE# assert_raises ( self , "controller.check_access('user', '__delattr__', obj, 'dummy')" , globals ( ) , locals ( ) , RoleError , "No __delattr__ access to 'dummy' by role 'user'" ) #NEWLINE# assert_raises ( self , "controller.check_access('', '__getattr__', obj, 'dummy')" , globals ( ) , locals ( ) , RoleError , 'No access by null role' ) #NEWLINE# proxy_value = ProxyRequired ( ) #NEWLINE# self . assertFalse ( controller . need_proxy ( obj , 'dummy' , proxy_value ) ) #NEWLINE# controller . attr_proxy_required ( proxy_value , 'dummy' ) #NEWLINE# self . assertTrue ( controller . need_proxy ( obj , 'dummy' , proxy_value ) ) #NEWLINE# controller . attr_proxy_required ( obj , 'dummy' , False ) #NEWLINE# self . assertFalse ( controller . need_proxy ( obj , 'dummy' , proxy_value ) ) #NEWLINE# controller . class_proxy_required ( ProxyRequired ) #NEWLINE# self . assertTrue ( controller . need_proxy ( obj , 'dummy' , proxy_value ) )