Skip to content

remove deprecated session auth #904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions gitlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down
63 changes: 1 addition & 62 deletions gitlab/tests/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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

Expand All @@ -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)
Expand Down