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 @@ -363,12 +363,14 @@ def _merge_auth(
363363 return (None , None , None )
364364
365365 def auth (self ) -> None :
366- """Performs an authentication using private token.
366+ """Performs an authentication using private token. Warns the user if a
367+ potentially misconfigured URL is detected on the client or server side.
367368
368369 The `user` attribute will hold a `gitlab.objects.CurrentUser` object on
369370 success.
370371 """
371372 self .user = self ._objects .CurrentUserManager (self ).get ()
373+ self ._check_url (self .user .web_url , path = self .user .username )
372374
373375 def version (self ) -> Tuple [str , str ]:
374376 """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(
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 )
Original file line number Diff line number Diff 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 assert isinstance (gl .user , gitlab .v4 .objects .CurrentUser )
255259
256260
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+
257279def test_gitlab_default_url ():
258280 gl = gitlab .Gitlab ()
259281 assert gl .url == gitlab .const .DEFAULT_URL
You can’t perform that action at this time.
0 commit comments