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

Commit45b8930

Browse files
committed
docs(advanced): document new netrc behavior
BREAKING CHANGE: python-gitlab now explicitly passes auth to requests, meaningit will only read netrc credentials if no token is provided, fixing a bug wherenetrc credentials took precedence over OAuth tokens. This also affects the CLI,where all environment variables now take precedence over netrc files.
1 parent5f46cfd commit45b8930

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

‎docs/api-usage-advanced.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ properly closed when you exit a ``with`` block:
4444
netrc authentication
4545
--------------------
4646

47-
python-gitlab reads credentials from ``.netrc`` files via the ``requests`` backend by default,
48-
which may override authentication headers you set on your client.
47+
python-gitlab reads credentials from ``.netrc`` files via the ``requests`` backend
48+
only if you do not provide any other type of authentication yourself.
4949

50-
For more granular control, you candisable this `Using a custom session`_
51-
and explicitlysetting ``trust_env=False`` as described in the ``requests`` documentation.
50+
If you'd like to disable reading netrc files altogether, you canfollow `Using a custom session`_
51+
and explicitlyset ``trust_env=False`` as described in the ``requests`` documentation.
5252

5353
..code-block::python
5454

‎tests/unit/test_gitlab_auth.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
importpathlib
2+
13
importpytest
24
importrequests
5+
importresponses
36
fromrequestsimportPreparedRequest
47

58
fromgitlabimportGitlab
69
fromgitlab._backendsimportJobTokenAuth,OAuthTokenAuth,PrivateTokenAuth
710
fromgitlab.configimportGitlabConfigParser
811

912

13+
@pytest.fixture
14+
defnetrc(monkeypatch:pytest.MonkeyPatch,tmp_path:pathlib.Path):
15+
netrc_file=tmp_path/".netrc"
16+
netrc_file.write_text("machine localhost login test password test")
17+
monkeypatch.setenv("NETRC",str(netrc_file))
18+
19+
1020
deftest_invalid_auth_args():
1121
withpytest.raises(ValueError):
1222
Gitlab(
@@ -101,6 +111,30 @@ def test_http_auth():
101111
assert"JOB-TOKEN"notinp.headers
102112

103113

114+
@responses.activate
115+
deftest_with_no_auth_uses_netrc_file(netrc):
116+
responses.get(
117+
url="http://localhost/api/v4/test",
118+
match=[
119+
responses.matchers.header_matcher({"Authorization":"Basic dGVzdDp0ZXN0"})
120+
],
121+
)
122+
123+
gl=Gitlab("http://localhost")
124+
gl.http_get("/test")
125+
126+
127+
@responses.activate
128+
deftest_with_auth_ignores_netrc_file(netrc):
129+
responses.get(
130+
url="http://localhost/api/v4/test",
131+
match=[responses.matchers.header_matcher({"Authorization":"Bearer test"})],
132+
)
133+
134+
gl=Gitlab("http://localhost",oauth_token="test")
135+
gl.http_get("/test")
136+
137+
104138
@pytest.mark.parametrize(
105139
"options,config,expected_private_token,expected_oauth_token,expected_job_token",
106140
[

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp