Skip to content

Commit 12b2b3d

Browse files
authored
self signed certificate - ssl disabling support w/ testing (#124)
* added a ssl failure test, ssl disabling path is now correct * moved resources * kill instead of terminate; actually closes the sockets * swapped from process kill to os.kill path to be compliant with 3.6 * separated normal tests from self signed cert tests where it made sense, split fastAPI to support all endpoints as both regular mode and self signed mode
1 parent d3e73cb commit 12b2b3d

22 files changed

+1391
-372
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#Eclipse
22
.project
3-
3+
venv
4+
venv_win
45
TestFiles
56
test.txt
67

Algorithmia/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(self, apiKey=None, apiAddress=None, caCert=None, bearerToken=None):
4141
self.apiAddress = Algorithmia.getApiAddress()
4242
if caCert == False:
4343
self.requestSession.verify = False
44+
self.requestSession.trust_env = False
4445
config = Configuration(use_ssl=False)
4546
elif caCert is None and 'REQUESTS_CA_BUNDLE' in os.environ:
4647
caCert = os.environ.get('REQUESTS_CA_BUNDLE')

Test/api/__init__.py

Lines changed: 2 additions & 347 deletions
Large diffs are not rendered by default.

Test/api/app.py

Lines changed: 355 additions & 0 deletions
Large diffs are not rendered by default.

Test/api/self_signed_app.py

Lines changed: 351 additions & 0 deletions
Large diffs are not rendered by default.

Test/conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import sys
22
from time import sleep
3+
import os, signal
34
if sys.version_info.major >= 3:
4-
from Test.api import start_webserver
5+
from Test.api import start_webserver_reg, start_webserver_self_signed
56
import pytest
67

78
@pytest.fixture(scope='package', autouse=True)
89
def fastapi_start():
9-
p = start_webserver()
10+
p_reg = start_webserver_reg()
11+
p_self_signed = start_webserver_self_signed()
1012
sleep(2)
11-
yield p
12-
p.terminate()
13+
yield p_reg, p_self_signed
14+
os.kill(p_reg.pid, signal.SIGKILL)
15+
os.kill(p_self_signed.pid, signal.SIGKILL)

Test/CLI_test.py renamed to Test/regular/CLI_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def setUp(self):
9393
# create a directory to use in testing the cp command
9494
self.client = Algorithmia.client()
9595
CLI().mkdir("data://.my/moredata", self.client)
96-
if not os.path.exists("./TestFiles/"):
97-
os.mkdir("./TestFiles/")
96+
if not os.path.exists("../TestFiles/"):
97+
os.mkdir("../TestFiles/")
9898

9999
def test_ls(self):
100100
parentDir = "data://.my/"
@@ -132,7 +132,7 @@ def test_rmdir(self):
132132

133133
def test_cat(self):
134134
file = "data://.my/moredata/test.txt"
135-
localfile = "./TestFiles/test.txt"
135+
localfile = "./../TestFiles/test.txt"
136136
fileContents = "some text in test file"
137137

138138
CLI().rm(file, self.client)
@@ -156,7 +156,7 @@ def test_get_build_logs(self):
156156

157157
# local to remote
158158
def test_cp_L2R(self):
159-
localfile = "./TestFiles/test.txt"
159+
localfile = "./../TestFiles/test.txt"
160160
testfile = open(localfile, "w")
161161
testfile.write("some text")
162162
testfile.close()
@@ -199,7 +199,7 @@ def test_auth(self):
199199

200200
def test_auth_cert(self):
201201

202-
localfile = "./TestFiles/fakecert.pem"
202+
localfile = "./../TestFiles/fakecert.pem"
203203

204204
testfile = open(localfile, "w")
205205
testfile.write("")
@@ -244,7 +244,7 @@ def test_list_languages(self):
244244
self.assertTrue(result is not None and "anaconda3" in result[1])
245245

246246
def test_rm(self):
247-
localfile = "./TestFiles/testRM.txt"
247+
localfile = "./../TestFiles/testRM.txt"
248248

249249
testfile = open(localfile, "w")
250250
testfile.write("some text")
@@ -263,7 +263,7 @@ def test_rm(self):
263263
self.assertTrue("testRM.txt" in result1 and "testRM.txt" not in result2)
264264

265265
def test_get_template(self):
266-
filename = "./temptest"
266+
filename = "./../temptest"
267267
envid = "36fd467e-fbfe-4ea6-aa66-df3f403b7132"
268268
response = CLI().get_template(envid, filename, self.client)
269269
print(response)

Test/regular/__init__.py

Whitespace-only changes.
File renamed without changes.

Test/algo_failure_test.py renamed to Test/regular/algo_failure_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# you will load the version installed on the computer.
1212
sys.path = ['../'] + sys.path
1313
from requests import Response
14-
from Test.api import app
15-
1614

1715
class AlgoTest(unittest.TestCase):
1816
error_500 = Response()

0 commit comments

Comments
 (0)