| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,8 +78,6 @@ def __init__( | |||
| 78 | 78 | private_token=None, | |
| 79 | 79 | oauth_token=None, | |
| 80 | 80 | job_token=None, | |
| 81 | - email=None, | ||
| 82 | - password=None, | ||
| 83 | 81 | ssl_verify=True, | |
| 84 | 82 | http_username=None, | |
| 85 | 83 | http_password=None, | |
@@ -98,10 +96,6 @@ def __init__( | |||
| 98 | 96 | #: Headers that will be used in request to GitLab | |
| 99 | 97 | self.headers = {} | |
| 100 | 98 | ||
| 101 | - #: The user email | ||
| 102 | - self.email = email | ||
| 103 | - #: The user password (associated with email) | ||
| 104 | - self.password = password | ||
| 105 | 99 | #: Whether SSL certificates should be validated | |
| 106 | 100 | self.ssl_verify = ssl_verify | |
| 107 | 101 | ||
@@ -215,20 +209,6 @@ def auth(self): | |||
| 215 | 209 | The `user` attribute will hold a `gitlab.objects.CurrentUser` object on | |
| 216 | 210 | success. | |
| 217 | 211 | """ | |
| 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): | ||
| 232 | 212 | self.user = self._objects.CurrentUserManager(self).get() | |
| 233 | 213 | ||
| 234 | 214 | def version(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -451,8 +451,6 @@ def setUp(self): | |||
| 451 | 451 | self.gl = Gitlab( | |
| 452 | 452 | "http://localhost", | |
| 453 | 453 | private_token="private_token", | |
| 454 | - email="testuser@test.com", | ||
| 455 | - password="testpassword", | ||
| 456 | 454 | ssl_verify=True, | |
| 457 | 455 | api_version=4, | |
| 458 | 456 | ) | |
@@ -465,66 +463,7 @@ def test_pickability(self): | |||
| 465 | 463 | self.assertTrue(hasattr(unpickled, "_objects")) | |
| 466 | 464 | self.assertEqual(unpickled._objects, original_gl_objects) | |
| 467 | 465 | ||
| 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 | - | ||
| 525 | 466 | def test_token_auth(self, callback=None): | |
| 526 | - if callback is None: | ||
| 527 | - callback = self.gl._token_auth | ||
| 528 | 467 | name = "username" | |
| 529 | 468 | id_ = 1 | |
| 530 | 469 | ||
@@ -537,7 +476,7 @@ def resp_cont(url, request): | |||
| 537 | 476 | return response(200, content, headers, None, 5, request) | |
| 538 | 477 | ||
| 539 | 478 | with HTTMock(resp_cont): | |
| 540 | - callback() | ||
| 479 | + self.gl.auth() | ||
| 541 | 480 | self.assertEqual(self.gl.user.username, name) | |
| 542 | 481 | self.assertEqual(self.gl.user.id, id_) | |
| 543 | 482 | self.assertEqual(type(self.gl.user), CurrentUser) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments