summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Wittig <max.wittig95@gmail.com>2019-10-13 19:00:33 +0200
committerGitHub <noreply@github.com>2019-10-13 19:00:33 +0200
commit67a9c1f1c62393b02919d25bcc98c3683d92576a (patch)
tree9de201782c96b9d3b1932721109a9d54234e72d0
parentff808ee94a73d65802a21ff1350090885d4befd5 (diff)
parentb751cdf424454d3859f3f038b58212e441faafaf (diff)
downloadgitlab-67a9c1f1c62393b02919d25bcc98c3683d92576a.tar.gz
Merge pull request #904 from jouve/remove-cred-auth
remove deprecated session auth
-rw-r--r--gitlab/__init__.py20
-rw-r--r--gitlab/tests/test_gitlab.py63
2 files changed, 1 insertions, 82 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 6842303..c73e697 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -78,8 +78,6 @@ class Gitlab(object):
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 @@ class Gitlab(object):
#: 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 @@ class Gitlab(object):
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 835e035..5688cd2 100644
--- a/gitlab/tests/test_gitlab.py
+++ b/gitlab/tests/test_gitlab.py
@@ -451,8 +451,6 @@ class TestGitlab(unittest.TestCase):
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 @@ class TestGitlab(unittest.TestCase):
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 @@ class TestGitlab(unittest.TestCase):
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)