diff --git a/gitlab/__init__.py b/gitlab/__init__.py index 6842303c6..c73e697f9 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -78,8 +78,6 @@ def __init__( private_token=None, oauth_token=None, job_token=None, - email=None, - password=None, ssl_verify=True, http_username=None, http_password=None, @@ -98,10 +96,6 @@ def __init__( #: Headers that will be used in request to GitLab self.headers = {} - #: The user email - self.email = email - #: The user password (associated with email) - self.password = password #: Whether SSL certificates should be validated self.ssl_verify = ssl_verify @@ -215,20 +209,6 @@ def auth(self): The `user` attribute will hold a `gitlab.objects.CurrentUser` object on success. """ - if self.private_token or self.oauth_token or self.job_token: - self._token_auth() - else: - self._credentials_auth() - - def _credentials_auth(self): - data = {"email": self.email, "password": self.password} - r = self.http_post("/session", data) - manager = self._objects.CurrentUserManager(self) - self.user = self._objects.CurrentUser(manager, r) - self.private_token = self.user.private_token - self._set_auth_info() - - def _token_auth(self): self.user = self._objects.CurrentUserManager(self).get() def version(self): diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index bd968b186..0767178cf 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -451,8 +451,6 @@ def setUp(self): self.gl = Gitlab( "http://localhost", private_token="private_token", - email="testuser@test.com", - password="testpassword", ssl_verify=True, api_version=4, ) @@ -465,66 +463,7 @@ def test_pickability(self): self.assertTrue(hasattr(unpickled, "_objects")) self.assertEqual(unpickled._objects, original_gl_objects) - def test_credentials_auth_nopassword(self): - self.gl.email = None - self.gl.password = None - - @urlmatch( - scheme="http", netloc="localhost", path="/api/v4/session", method="post" - ) - def resp_cont(url, request): - headers = {"content-type": "application/json"} - content = '{"message": "message"}'.encode("utf-8") - return response(404, content, headers, None, 5, request) - - with HTTMock(resp_cont): - self.assertRaises(GitlabHttpError, self.gl._credentials_auth) - - def test_credentials_auth_notok(self): - @urlmatch( - scheme="http", netloc="localhost", path="/api/v4/session", method="post" - ) - def resp_cont(url, request): - headers = {"content-type": "application/json"} - content = '{"message": "message"}'.encode("utf-8") - return response(404, content, headers, None, 5, request) - - with HTTMock(resp_cont): - self.assertRaises(GitlabHttpError, self.gl._credentials_auth) - - def test_auth_with_credentials(self): - self.gl.private_token = None - self.test_credentials_auth(callback=self.gl.auth) - - def test_auth_with_token(self): - self.test_token_auth(callback=self.gl.auth) - - def test_credentials_auth(self, callback=None): - if callback is None: - callback = self.gl._credentials_auth - token = "credauthtoken" - id_ = 1 - expected = {"PRIVATE-TOKEN": token} - - @urlmatch( - scheme="http", netloc="localhost", path="/api/v4/session", method="post" - ) - def resp_cont(url, request): - headers = {"content-type": "application/json"} - content = '{{"id": {0:d}, "private_token": "{1:s}"}}'.format( - id_, token - ).encode("utf-8") - return response(201, content, headers, None, 5, request) - - with HTTMock(resp_cont): - callback() - self.assertEqual(self.gl.private_token, token) - self.assertDictEqual(expected, self.gl.headers) - self.assertEqual(self.gl.user.id, id_) - def test_token_auth(self, callback=None): - if callback is None: - callback = self.gl._token_auth name = "username" id_ = 1 @@ -537,7 +476,7 @@ def resp_cont(url, request): return response(200, content, headers, None, 5, request) with HTTMock(resp_cont): - callback() + self.gl.auth() self.assertEqual(self.gl.user.username, name) self.assertEqual(self.gl.user.id, id_) self.assertEqual(type(self.gl.user), CurrentUser)