Skip to content

Commit bd7235d

Browse files
committed
Updated to get PWs from env, use JWTs for all APIs
1 parent f735d2f commit bd7235d

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

src/server/test_api.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import pytest, socket, requests, os
22

3-
from secrets import BASEUSER_PW, BASEADMIN_PW
3+
4+
try:
5+
from secrets import BASEUSER_PW, BASEADMIN_PW
6+
except KeyError:
7+
BASEUSER_PW = os.environ['BASEUSER_PW']
8+
BASEADMIN_PW = os.environ['BASEADMIN_PW']
9+
410

511
jwt_token = ''
612

713
#
8-
# Run 'pytest' from the command line
14+
# Run 'pytest' from the command line (-v gives helpful details)
915
#
1016
# Running pytest can result in six different exit codes:
1117
# 0 - All tests were collected and passed successfully
@@ -68,20 +74,6 @@ def test_client_dns():
6874
assert len(gai) > 0
6975

7076
# Simple API tests ################################################
71-
72-
73-
def test_currentFiles():
74-
"""360 view Current Files list"""
75-
response = requests.get(SERVER_URL + "/api/listCurrentFiles")
76-
assert response.status_code == 200
77-
78-
79-
def test_statistics():
80-
"""360 view Statistics"""
81-
response = requests.get(SERVER_URL + "/api/statistics")
82-
assert response.status_code == 200
83-
84-
8577
def test_usertest():
8678
"""Verify liveness test works"""
8779
response = requests.get(SERVER_URL + "/api/user/test")
@@ -147,6 +139,10 @@ def test_inact_userblocked(state: State):
147139
assert response.status_code == 401
148140

149141

142+
143+
144+
145+
150146
### Admin-level tests ######################################
151147

152148
def test_adminlogin(state: State):
@@ -182,6 +178,28 @@ def test_admingetusers(state: State):
182178
assert len(userlist) > 1
183179

184180

181+
def test_admin_currentFiles(state: State):
182+
"""Verify admin user can get Current Files list"""
183+
184+
b_string = 'Bearer ' + state.state['base_admin']
185+
assert len(b_string) > 24
186+
auth_hdr = {'Authorization' : b_string}
187+
188+
response = requests.get(SERVER_URL + "/api/listCurrentFiles", headers=auth_hdr)
189+
assert response.status_code == 200
190+
191+
192+
def test_admin_statistics(state: State):
193+
"""360 view Statistics"""
194+
195+
b_string = 'Bearer ' + state.state['base_admin']
196+
assert len(b_string) > 24
197+
auth_hdr = {'Authorization' : b_string}
198+
199+
response = requests.get(SERVER_URL + "/api/statistics", headers=auth_hdr)
200+
assert response.status_code == 200
201+
202+
185203
def test_usergetusers(state: State):
186204
"""Verify logged-in base_user *cannot* use JWT to get user list """
187205
# Build auth string value including token from state

0 commit comments

Comments
 (0)