Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyuan committed Apr 30, 2023
1 parent 8291899 commit 67af3e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions openai_forward/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ class OpenaiBase:
IP_BLACKLIST = os.environ.get("IP_BLACKLIST", "").strip()
if IP_BLACKLIST:
IP_BLACKLIST = [i.strip() for i in IP_BLACKLIST.split(' ')]

Check warning on line 18 in openai_forward/_base.py

View check run for this annotation

Codecov / codecov/patch

openai_forward/_base.py#L18

Added line #L18 was not covered by tests
else:
IP_BLACKLIST = []
if IP_WHITELIST:
IP_WHITELIST = [i.strip() for i in IP_WHITELIST.split(' ')]

Check warning on line 22 in openai_forward/_base.py

View check run for this annotation

Codecov / codecov/patch

openai_forward/_base.py#L22

Added line #L22 was not covered by tests
else:
IP_WHITELIST = []
if _ROUTE_PREFIX:
if _ROUTE_PREFIX.endswith('/'):
_ROUTE_PREFIX = _ROUTE_PREFIX[:-1]
Expand Down
13 changes: 8 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from openai_forward.openai import OpenaiBase
from fastapi import HTTPException
import pytest


Expand All @@ -14,11 +15,13 @@ def test_env(self, openai: OpenaiBase):
def test_validate_ip(self, openai: OpenaiBase):
ip1 = "1.1.1.1"
ip2 = "2.2.2.2"
assert openai.validate_request_host("*")
assert openai.validate_request_host("*") is None
openai.IP_WHITELIST.append(ip1)
assert openai.validate_request_host(ip1)
assert openai.validate_request_host(ip2) is False
assert openai.validate_request_host(ip1) is None
with pytest.raises(HTTPException):
openai.validate_request_host(ip2)
openai.IP_WHITELIST = []
openai.IP_BLACKLIST.append(ip1)
assert openai.validate_request_host(ip1) is False
assert openai.validate_request_host(ip2)
assert openai.validate_request_host(ip2) is None
with pytest.raises(HTTPException):
openai.validate_request_host(ip1)

0 comments on commit 67af3e7

Please sign in to comment.