Skip to content

Commit

Permalink
Merge pull request #121 from individual-it/login_bug
Browse files Browse the repository at this point in the history
fix login bug #118
  • Loading branch information
Vincent Petry committed Sep 15, 2015
2 parents 3dce21e + 2967799 commit ce4f8fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 9 additions & 5 deletions owncloud/owncloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,16 @@ def login(self, user_id, password):
self.__session.verify = self.__verify_certs
self.__session.auth = (user_id, password)
# TODO: use another path to prevent that the server renders the file list page
res = self.__session.get(self.url + 'index.php')
res = self.__session.get(self.url + 'status.php')
if res.status_code == 200:
if self.__single_session:
# Keep the same session, no need to re-auth every call
self.__session.auth = None
return
res = self.__make_ocs_request(
'GET',
self.OCS_SERVICE_CLOUD,
'capabilities'
)
if res.status_code == 200:
return
raise HTTPResponseError(res)
self.__session.close()
self.__session = None
raise HTTPResponseError(res)
Expand Down
13 changes: 13 additions & 0 deletions owncloud/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,19 @@ def test_get_config(self):
"""Test get_config() function"""
self.assertIsNotNone(self.client.get_config())

def tearDown(self):
self.client.logout()

class TestLogin(unittest.TestCase):
def setUp(self):
self.client = owncloud.Client(Config['owncloud_url'])

def test_login(self):
with self.assertRaises(owncloud.HTTPResponseError) as e:
self.client.login("iGuessThisUserNameDoesNotExistInTheSystem","iGuessThisUserNameDoesNotExistInTheSystem")
self.assertEquals(e.exception.status_code, 401)
self.client.login(Config['owncloud_login'], Config['owncloud_password'])

def tearDown(self):
self.client.logout()

Expand Down

0 comments on commit ce4f8fc

Please sign in to comment.