#NEWLINE# def testQueryAuth( self ) : #NEWLINE# #INDENT# username = 'admin' #NEWLINE# password = '2046920054' #NEWLINE# header_fn = compat . partial ( self . _MakeAuthHeaders , username , password ) #NEWLINE# def _LookupUserNoWrite( name ) : #NEWLINE# #INDENT# if ( name == username ) : #NEWLINE# #INDENT# return users_file . PasswordFileUser ( name , password , [ ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# for access in [ rapi . RAPI_ACCESS_WRITE , rapi . RAPI_ACCESS_READ ] : #NEWLINE# #INDENT# def _LookupUserWithWrite( name ) : #NEWLINE# #INDENT# if ( name == username ) : #NEWLINE# #INDENT# return users_file . PasswordFileUser ( name , password , [ access ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# for qr in constants . QR_VIA_RAPI : #NEWLINE# #INDENT# path = ( '/2/query/%s' % qr ) #NEWLINE# for method in rapi . baserlib . _SUPPORTED_METHODS : #NEWLINE# #INDENT# ( code , _ , _ ) = self . _Test ( method , path , '' , '' , reqauth = True ) #NEWLINE# if ( method in ( http . HTTP_DELETE , http . HTTP_POST ) ) : #NEWLINE# #INDENT# self . assertEqual ( code , http . HttpNotImplemented . code ) #NEWLINE# continue #NEWLINE# #UNINDENT# self . assertEqual ( code , http . HttpUnauthorized . code ) #NEWLINE# ( code , _ , _ ) = self . _Test ( method , path , header_fn ( True ) , '' , user_fn = self . _LookupWrongUser , reqauth = True ) #NEWLINE# self . assertEqual ( code , http . HttpUnauthorized . code ) #NEWLINE# ( code , _ , _ ) = self . _Test ( method , path , header_fn ( True ) , '' , user_fn = _LookupUserNoWrite , reqauth = True ) #NEWLINE# self . assertEqual ( code , http . HttpForbidden . code ) #NEWLINE# ( code , _ , _ ) = self . _Test ( method , path , header_fn ( False ) , '' , user_fn = _LookupUserNoWrite , reqauth = True ) #NEWLINE# self . assertEqual ( code , http . HttpUnauthorized . code ) #NEWLINE# ( code , _ , _ ) = self . _Test ( method , path , header_fn ( False ) , '' , user_fn = _LookupUserWithWrite , reqauth = True ) #NEWLINE# self . assertEqual ( code , http . HttpUnauthorized . code ) #NEWLINE# if ( method == http . HTTP_PUT ) : #NEWLINE# #INDENT# reqpath = path #NEWLINE# body = serializer . DumpJson ( { #NEWLINE# #INDENT# 'fields' : [ 'name' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( method == http . HTTP_GET ) : #NEWLINE# #INDENT# reqpath = ( '%s?fields=name' % path ) #NEWLINE# body = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . fail ( ( "Unknown method '%s'" % method ) ) #NEWLINE# #UNINDENT# #UNINDENT# ( code , _ , data ) = self . _Test ( method , reqpath , header_fn ( True ) , body , user_fn = _LookupUserWithWrite , luxi_client = _FakeLuxiClientForQuery , reqauth = True ) #NEWLINE# self . assertEqual ( code , http . HTTP_OK ) #NEWLINE# self . assertTrue ( objects . QueryResponse . FromDict ( data ) )