54
54
oauth_token = STUV
55
55
"""
56
56
57
+ ssl_verify_str_config = """[global]
58
+ default = one
59
+ ssl_verify = /etc/ssl/certs/ca-certificates.crt
60
+
61
+ [one]
62
+ url = http://one.url
63
+ private_token = ABCDEF
64
+ """
65
+
57
66
custom_user_agent_config = f"""[global]
58
67
default = one
59
68
user_agent = { custom_user_agent }
69
78
private_token = ABCDEF
70
79
"""
71
80
72
- missing_attr_config = """[global]
81
+ invalid_data_config = """[global]
73
82
[one]
74
83
url = http://one.url
75
84
83
92
url = http://four.url
84
93
private_token = ABCDEF
85
94
per_page = 200
95
+
96
+ [invalid-api-version]
97
+ url = http://invalid-api-version.url
98
+ private_token = ABCDEF
99
+ api_version = 1
86
100
"""
87
101
88
102
@@ -173,7 +187,7 @@ def test_invalid_id(m_open, mock_clean_env, monkeypatch):
173
187
174
188
@mock .patch ("builtins.open" )
175
189
def test_invalid_data (m_open , monkeypatch ):
176
- fd = io .StringIO (missing_attr_config )
190
+ fd = io .StringIO (invalid_data_config )
177
191
fd .close = mock .Mock (return_value = None , side_effect = lambda : fd .seek (0 ))
178
192
m_open .return_value = fd
179
193
@@ -185,9 +199,14 @@ def test_invalid_data(m_open, monkeypatch):
185
199
config .GitlabConfigParser (gitlab_id = "two" )
186
200
with pytest .raises (config .GitlabDataError ):
187
201
config .GitlabConfigParser (gitlab_id = "three" )
188
- with pytest .raises (config .GitlabDataError ) as emgr :
202
+
203
+ with pytest .raises (config .GitlabDataError ) as e :
189
204
config .GitlabConfigParser ("four" )
190
- assert "Unsupported per_page number: 200" == emgr .value .args [0 ]
205
+ assert str (e .value ) == "Unsupported per_page number: 200"
206
+
207
+ with pytest .raises (config .GitlabDataError ) as e :
208
+ config .GitlabConfigParser ("invalid-api-version" )
209
+ assert str (e .value ) == "Unsupported API version: 1"
191
210
192
211
193
212
@mock .patch ("builtins.open" )
@@ -248,6 +267,18 @@ def test_valid_data(m_open, monkeypatch):
248
267
assert cp .ssl_verify is True
249
268
250
269
270
+ @mock .patch ("builtins.open" )
271
+ def test_ssl_verify_as_str (m_open , monkeypatch ):
272
+ fd = io .StringIO (ssl_verify_str_config )
273
+ fd .close = mock .Mock (return_value = None )
274
+ m_open .return_value = fd
275
+
276
+ with monkeypatch .context () as m :
277
+ m .setattr (Path , "resolve" , _mock_existent_file )
278
+ cp = config .GitlabConfigParser ()
279
+ assert cp .ssl_verify == "/etc/ssl/certs/ca-certificates.crt"
280
+
281
+
251
282
@mock .patch ("builtins.open" )
252
283
@pytest .mark .skipif (sys .platform .startswith ("win" ), reason = "Not supported on Windows" )
253
284
def test_data_from_helper (m_open , monkeypatch , tmp_path ):
@@ -286,6 +317,33 @@ def test_data_from_helper(m_open, monkeypatch, tmp_path):
286
317
assert "secret" == cp .oauth_token
287
318
288
319
320
+ @mock .patch ("builtins.open" )
321
+ @pytest .mark .skipif (sys .platform .startswith ("win" ), reason = "Not supported on Windows" )
322
+ def test_from_helper_subprocess_error_raises_error (m_open , monkeypatch ):
323
+ # using /usr/bin/false here to force a non-zero return code
324
+ fd = io .StringIO (
325
+ dedent (
326
+ """\
327
+ [global]
328
+ default = helper
329
+
330
+ [helper]
331
+ url = https://helper.url
332
+ oauth_token = helper: /usr/bin/false
333
+ """
334
+ )
335
+ )
336
+
337
+ fd .close = mock .Mock (return_value = None )
338
+ m_open .return_value = fd
339
+ with monkeypatch .context () as m :
340
+ m .setattr (Path , "resolve" , _mock_existent_file )
341
+ with pytest .raises (config .GitlabConfigHelperError ) as e :
342
+ config .GitlabConfigParser (gitlab_id = "helper" )
343
+
344
+ assert "Failed to read oauth_token value from helper" in str (e .value )
345
+
346
+
289
347
@mock .patch ("builtins.open" )
290
348
@pytest .mark .parametrize (
291
349
"config_string,expected_agent" ,
0 commit comments