Skip to content

Commit 67a9c1f

Browse files
authored
Merge pull request #904 from jouve/remove-cred-auth
remove deprecated session auth
2 parents ff808ee + b751cdf commit 67a9c1f

File tree

2 files changed

+1
-82
lines changed

2 files changed

+1
-82
lines changed

gitlab/__init__.py

-20
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ def __init__(
7878
private_token=None,
7979
oauth_token=None,
8080
job_token=None,
81-
email=None,
82-
password=None,
8381
ssl_verify=True,
8482
http_username=None,
8583
http_password=None,
@@ -98,10 +96,6 @@ def __init__(
9896
#: Headers that will be used in request to GitLab
9997
self.headers = {}
10098

101-
#: The user email
102-
self.email = email
103-
#: The user password (associated with email)
104-
self.password = password
10599
#: Whether SSL certificates should be validated
106100
self.ssl_verify = ssl_verify
107101

@@ -215,20 +209,6 @@ def auth(self):
215209
The `user` attribute will hold a `gitlab.objects.CurrentUser` object on
216210
success.
217211
"""
218-
if self.private_token or self.oauth_token or self.job_token:
219-
self._token_auth()
220-
else:
221-
self._credentials_auth()
222-
223-
def _credentials_auth(self):
224-
data = {"email": self.email, "password": self.password}
225-
r = self.http_post("/session", data)
226-
manager = self._objects.CurrentUserManager(self)
227-
self.user = self._objects.CurrentUser(manager, r)
228-
self.private_token = self.user.private_token
229-
self._set_auth_info()
230-
231-
def _token_auth(self):
232212
self.user = self._objects.CurrentUserManager(self).get()
233213

234214
def version(self):

gitlab/tests/test_gitlab.py

+1-62
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,6 @@ def setUp(self):
451451
self.gl = Gitlab(
452452
"http://localhost",
453453
private_token="private_token",
454-
email="testuser@test.com",
455-
password="testpassword",
456454
ssl_verify=True,
457455
api_version=4,
458456
)
@@ -465,66 +463,7 @@ def test_pickability(self):
465463
self.assertTrue(hasattr(unpickled, "_objects"))
466464
self.assertEqual(unpickled._objects, original_gl_objects)
467465

468-
def test_credentials_auth_nopassword(self):
469-
self.gl.email = None
470-
self.gl.password = None
471-
472-
@urlmatch(
473-
scheme="http", netloc="localhost", path="/api/v4/session", method="post"
474-
)
475-
def resp_cont(url, request):
476-
headers = {"content-type": "application/json"}
477-
content = '{"message": "message"}'.encode("utf-8")
478-
return response(404, content, headers, None, 5, request)
479-
480-
with HTTMock(resp_cont):
481-
self.assertRaises(GitlabHttpError, self.gl._credentials_auth)
482-
483-
def test_credentials_auth_notok(self):
484-
@urlmatch(
485-
scheme="http", netloc="localhost", path="/api/v4/session", method="post"
486-
)
487-
def resp_cont(url, request):
488-
headers = {"content-type": "application/json"}
489-
content = '{"message": "message"}'.encode("utf-8")
490-
return response(404, content, headers, None, 5, request)
491-
492-
with HTTMock(resp_cont):
493-
self.assertRaises(GitlabHttpError, self.gl._credentials_auth)
494-
495-
def test_auth_with_credentials(self):
496-
self.gl.private_token = None
497-
self.test_credentials_auth(callback=self.gl.auth)
498-
499-
def test_auth_with_token(self):
500-
self.test_token_auth(callback=self.gl.auth)
501-
502-
def test_credentials_auth(self, callback=None):
503-
if callback is None:
504-
callback = self.gl._credentials_auth
505-
token = "credauthtoken"
506-
id_ = 1
507-
expected = {"PRIVATE-TOKEN": token}
508-
509-
@urlmatch(
510-
scheme="http", netloc="localhost", path="/api/v4/session", method="post"
511-
)
512-
def resp_cont(url, request):
513-
headers = {"content-type": "application/json"}
514-
content = '{{"id": {0:d}, "private_token": "{1:s}"}}'.format(
515-
id_, token
516-
).encode("utf-8")
517-
return response(201, content, headers, None, 5, request)
518-
519-
with HTTMock(resp_cont):
520-
callback()
521-
self.assertEqual(self.gl.private_token, token)
522-
self.assertDictEqual(expected, self.gl.headers)
523-
self.assertEqual(self.gl.user.id, id_)
524-
525466
def test_token_auth(self, callback=None):
526-
if callback is None:
527-
callback = self.gl._token_auth
528467
name = "username"
529468
id_ = 1
530469

@@ -537,7 +476,7 @@ def resp_cont(url, request):
537476
return response(200, content, headers, None, 5, request)
538477

539478
with HTTMock(resp_cont):
540-
callback()
479+
self.gl.auth()
541480
self.assertEqual(self.gl.user.username, name)
542481
self.assertEqual(self.gl.user.id, id_)
543482
self.assertEqual(type(self.gl.user), CurrentUser)

0 commit comments

Comments
 (0)