Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0040b43

Browse files
nejchJohnVillalovos
authored andcommitted
feat(client): warn user on misconfigured URL inauth()
1 parentaf21a18 commit0040b43

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎gitlab/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,14 @@ def _merge_auth(
364364
return (None,None,None)
365365

366366
defauth(self)->None:
367-
"""Performs an authentication using private token.
367+
"""Performs an authentication using private token. Warns the user if a
368+
potentially misconfigured URL is detected on the client or server side.
368369
369370
The `user` attribute will hold a `gitlab.objects.CurrentUser` object on
370371
success.
371372
"""
372373
self.user=self._objects.CurrentUserManager(self).get()
374+
self._check_url(self.user.web_url,path=self.user.username)
373375

374376
defversion(self)->Tuple[str,str]:
375377
"""Returns the version and revision of the gitlab server.

‎tests/functional/cli/test_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_private_token_overrides_job_token(
100100
# CLI first calls .auth() when private token is present
101101
resp_auth_with_token=copy.deepcopy(resp_get_project_with_token)
102102
resp_auth_with_token.update(url=f"{DEFAULT_URL}/api/v4/user")
103+
resp_auth_with_token["json"].update(username="user",web_url=f"{DEFAULT_URL}/user")
103104

104105
responses.add(**resp_get_project_with_token)
105106
responses.add(**resp_auth_with_token)

‎tests/unit/test_gitlab.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def resp_get_user():
3737
return {
3838
"method":responses.GET,
3939
"url":"http://localhost/api/v4/user",
40-
"json": {"id":1,"username":"username"},
40+
"json": {
41+
"id":1,
42+
"username":"username",
43+
"web_url":"http://localhost/username",
44+
},
4145
"content_type":"application/json",
4246
"status":200,
4347
}
@@ -254,6 +258,24 @@ def test_gitlab_token_auth(gl, resp_get_user):
254258
assertisinstance(gl.user,gitlab.v4.objects.CurrentUser)
255259

256260

261+
@responses.activate
262+
deftest_gitlab_auth_with_mismatching_url_warns():
263+
responses.add(
264+
method=responses.GET,
265+
url="http://first.example.com/api/v4/user",
266+
json={
267+
"username":"test-user",
268+
"web_url":"http://second.example.com/test-user",
269+
},
270+
content_type="application/json",
271+
status=200,
272+
)
273+
gl=gitlab.Gitlab("http://first.example.com")
274+
275+
withpytest.warns(UserWarning):
276+
gl.auth()
277+
278+
257279
deftest_gitlab_default_url():
258280
gl=gitlab.Gitlab()
259281
assertgl.url==gitlab.const.DEFAULT_URL

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp