Skip to content

Commit 6abd092

Browse files
authored
Merge pull request #32 from crazi-coder/29
Fix for #29
2 parents 4079dc6 + 2ed20d2 commit 6abd092

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pyyaml==5.3.1
33
pycurl==7.43.0.6
44
jsonpath==0.82
55
jmespath==0.10.0
6-
jsonschema==3.2.0
6+
jsonschema==3.2.0
7+
certifi>=2020.11.8

resttest3/testcase.py

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import List, Dict, Optional
1010
from urllib.parse import urljoin
1111

12+
import certifi
1213
import pycurl
1314

1415
from resttest3.binding import Context
@@ -331,6 +332,14 @@ def auth_username(self):
331332
def auth_username(self, username):
332333
self.__auth_username = Parser.coerce_string_to_ascii(username)
333334

335+
@property
336+
def ssl_insecure(self):
337+
return self.__ssl_insecure
338+
339+
@ssl_insecure.setter
340+
def ssl_insecure(self, val):
341+
self.__ssl_insecure = bool(val)
342+
334343
@property
335344
def auth_password(self):
336345
return self.__auth_password
@@ -616,6 +625,8 @@ def run(self, context=None, timeout=None, curl_handler=None):
616625
curl_handler.setopt(curl_handler.COOKIELIST, "ALL")
617626
except pycurl.error:
618627
curl_handler = pycurl.Curl()
628+
curl_handler.setopt(pycurl.CAINFO, certifi.where()) # Fix for #29
629+
curl_handler.setopt(pycurl.FOLLOWLOCATION, 1) # Support for HTTP 301
619630
else:
620631
curl_handler = pycurl.Curl()
621632

tests/test_testcase.py

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from inspect import getframeinfo, currentframe
33
from pathlib import Path
44

5+
import pycurl
56
import yaml
67

78
from resttest3.binding import Context
@@ -140,6 +141,20 @@ def test_include(self):
140141
ts.parse('', [{'import': 'tests/content-test.yaml'}])
141142
self.assertEqual(1, len(ts.test_group_list_dict))
142143

144+
def test_pycurl_run(self):
145+
x = TestCase('https://api.github.com', None, None, None, None)
146+
x.run()
147+
self.assertEqual(True, x.is_passed)
148+
x.ssl_insecure = True
149+
x.run()
150+
self.assertEqual(True, x.is_passed)
151+
curl_handler = pycurl.Curl()
152+
x.run(curl_handler=curl_handler)
153+
self.assertEqual(True, x.is_passed)
154+
curl_handler.close()
155+
x.run(curl_handler=curl_handler)
156+
self.assertEqual(True, x.is_passed)
157+
143158

144159
if __name__ == '__main__':
145160
unittest.main()

0 commit comments

Comments
 (0)