File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -364,12 +364,14 @@ def _merge_auth(
364
364
return (None , None , None )
365
365
366
366
def auth (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.
368
369
369
370
The `user` attribute will hold a `gitlab.objects.CurrentUser` object on
370
371
success.
371
372
"""
372
373
self .user = self ._objects .CurrentUserManager (self ).get ()
374
+ self ._check_url (self .user .web_url , path = self .user .username )
373
375
374
376
def version (self ) -> Tuple [str , str ]:
375
377
"""Returns the version and revision of the gitlab server.
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ def test_private_token_overrides_job_token(
100
100
# CLI first calls .auth() when private token is present
101
101
resp_auth_with_token = copy .deepcopy (resp_get_project_with_token )
102
102
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" )
103
104
104
105
responses .add (** resp_get_project_with_token )
105
106
responses .add (** resp_auth_with_token )
Original file line number Diff line number Diff line change @@ -37,7 +37,11 @@ def resp_get_user():
37
37
return {
38
38
"method" : responses .GET ,
39
39
"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
+ },
41
45
"content_type" : "application/json" ,
42
46
"status" : 200 ,
43
47
}
@@ -254,6 +258,24 @@ def test_gitlab_token_auth(gl, resp_get_user):
254
258
assert isinstance (gl .user , gitlab .v4 .objects .CurrentUser )
255
259
256
260
261
+ @responses .activate
262
+ def test_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
+ with pytest .warns (UserWarning ):
276
+ gl .auth ()
277
+
278
+
257
279
def test_gitlab_default_url ():
258
280
gl = gitlab .Gitlab ()
259
281
assert gl .url == gitlab .const .DEFAULT_URL
You can’t perform that action at this time.
0 commit comments