psss / python-nitrate

Python API for the Nitrate test case management system
GNU Lesser General Public License v2.1
9 stars 25 forks source link

username/password auth got broken #17

Closed lukaszachy closed 4 months ago

lukaszachy commented 4 years ago

I have nitrate in VM, using user/pass auth. With python2-nitrate-1.4-1 it works, with 1.5 version it doesn't.

url = http://192.168.122.83/xmlrpc/
username = test_user
password = 123456
from nitrate  import User
>>> User().id
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 393, in do_command
    return getattr(self.server, verb)(*params)
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 125, in single_request_with_cookies
    return self.parse_response(response)
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1342, in parse_response
    return u.close()
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 400: ['login() takes exactly 2 arguments (48 given)\nTraceback (most recent call last):\n  File "/root/Nitrate/tcms/xmlrpc/filters.py", line 97, in _decorator\n    return func(*args, **kwargs)\n  File "/root/Nitrate/tcms/xmlrpc/decorators.py", line 64, in _new_function\n    return function(request, *args, **kwargs)\nTypeError: login() takes exactly 2 arguments (48 given)\n']>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/nitrate/base.py", line 65, in getter
    self._fetch()
  File "/usr/lib/python3.7/site-packages/nitrate/immutable.py", line 873, in _fetch
    inject = self._server.User.get_me()
  File "/usr/lib/python3.7/site-packages/nitrate/base.py", line 202, in _server
    Config().nitrate.url).server
  File "/usr/lib/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 244, in __init__
    password = password,
  File "/usr/lib/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 395, in do_command
    raise NitrateXmlrpcError(verb, params, e)
nitrate.xmlrpc_driver.NitrateXmlrpcError: Error while executing cmd 'Auth.login({'username': 'test_user', 'password': 'redhat'})' --> <Fault 400: ['login() takes exactly 2 arguments (48 given)\nTraceback (most recent call last):\n  File "/root/Nitrate/tcms/xmlrpc/filters.py", line 97, in _decorator\n    return func(*args, **kwargs)\n  File "/root/Nitrate/tcms/xmlrpc/decorators.py", line 64, in _new_function\n    return function(request, *args, **kwargs)\nTypeError: login() takes exactly 2 arguments (48 given)\n']>
lukaszachy commented 4 years ago

After some debugging

(Pdb++) bt
[0]   /home/vagrant/repro.py(6)<module>()
-> u.id
[1]   /usr/lib/python3.7/site-packages/nitrate/base.py(65)getter()
-> self._fetch()
[2]   /usr/lib/python3.7/site-packages/nitrate/immutable.py(873)_fetch()
-> inject = self._server.User.get_me()
[3]   /usr/lib/python3.7/site-packages/nitrate/base.py(202)_server()
-> Config().nitrate.url).server
[4]   /usr/lib/python3.7/site-packages/nitrate/xmlrpc_driver.py(244)__init__()
-> password = password,
[5]   /usr/lib/python3.7/site-packages/nitrate/xmlrpc_driver.py(393)do_command()
-> return getattr(self.server, verb)(*params)
[6] > /usr/lib64/python3.7/xmlrpc/client.py(1111)__call__()
-> def __call__(self, *args):
(Pdb++) p args
('{', "'", 'u', 's', 'e', 'r', 'n', 'a', 'm', 'e', "'", ':', ' ', "'", 't', 'e', 's', 't', '_', 'u', 's', 'e', 'r', "'", ',', ' ', "'", 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', "'", ':', ' ', "'", '1', '2', '3', '4', '5', '6', "'", '}')

The culprit is in do_command() and its

for arg in args:
    params = ("%s" % str(arg), "%s, %s" % (params, str(arg)))[params!='']
psss commented 4 years ago

I believe this should be fixed by #19. @lukaszachy, could you please confirm it works for you with the latest master?

lukaszachy commented 4 years ago

With 76a51d61cfe99863c6 as master I get this traceback. It looks as user/pass authentication wasn't processed correctly

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/base.py", line 65, in getter
    self._fetch()
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/immutable.py", line 873, in _fetch
    inject = self._server.User.get_me()
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 125, in single_request_with_cookies
    return self.parse_response(response)
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 1342, in parse_response
    return u.close()
  File "/usr/lib64/python3.7/xmlrpc/client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 500: ['\'AnonymousUser\' object has no attribute \'_meta\'\nTraceback (most recent call last):\n  File "/root/Nitrate/tcms/xmlrpc/filters.py", line 97, in _decorator\n    return func(*args, **kwargs)\n  File "/root/Nitrate/tcms/xmlrpc/decorators.py", line 64, in _new_function\n    return function(request, *args, **kwargs)\n  File "/root/Nitrate/tcms/xmlrpc/api/user.py", line 87, in get_me\n    return get_user_dict(request.user)\n  File "/root/Nitrate/tcms/xmlrpc/api/user.py", line 24, in get_user_dict\n    u = u.serialize_model()\n  File "/root/Nitrate/tcms/xmlrpc/serializer.py", line 93, in serialize_model\n    opts = self.model._meta\n  File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 205, in inner\n    return func(self._wrapped, *args)\nAttributeError: \'AnonymousUser\' object has no attribute \'_meta\'\n']>

When I use wrong password the traceback is different

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/base.py", line 65, in getter
    self._fetch()
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/immutable.py", line 873, in _fetch
    inject = self._server.User.get_me()
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/base.py", line 202, in _server
    Config().nitrate.url).server
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 247, in __init__
    password = password,
  File "/tmp/aaa/lib64/python3.7/site-packages/nitrate/xmlrpc_driver.py", line 395, in do_command
    raise NitrateXmlrpcError(verb, str(params), e)
nitrate.xmlrpc_driver.NitrateXmlrpcError: Error while executing cmd 'Auth.login([{'username': 'test_user', 'password': '123456XXX'}])' --> <Fault 403: ['Wrong username or password\nTraceback (most recent call last):\n  File "/root/Nitrate/tcms/xmlrpc/filters.py", line 97, in _decorator\n    return func(*args, **kwargs)\n  File "/root/Nitrate/tcms/xmlrpc/decorators.py", line 64, in _new_function\n    return function(request, *args, **kwargs)\n  File "/root/Nitrate/tcms/xmlrpc/api/auth.py", line 59, in login\n    raise PermissionDenied(\'Wrong username or password\')\nPermissionDenied: Wrong username or password\n']>