Skip to content

Commit

Permalink
fix: updated api key name
Browse files Browse the repository at this point in the history
  • Loading branch information
broomva committed May 13, 2024
1 parent 3115fb6 commit d0b417c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions arcan/api/datamodel/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from jose import JWTError, jwt
from passlib.context import CryptContext
from pydantic import BaseModel
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy import (Boolean, Column, DateTime, ForeignKey, Integer, String,
Text)
from sqlalchemy.orm import Session, relationship

from arcan.api.datamodel import Base, engine
Expand All @@ -23,7 +24,7 @@

# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = os.environ.get("JWT_SECRET_KEY")
SECRET_KEY = os.environ.get("ARCAN_API_KEY")
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30

Expand Down
4 changes: 2 additions & 2 deletions arcan/api/session/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def requires_auth(func):
@wraps(func)
def wrapper(*args, token: HTTPAuthorizationCredentials = security, **kwargs):
if token.credentials != os.environ["ARCAN_AUTH_TOKEN"]:
if token.credentials != os.environ["ARCAN_API_KEY"]:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect bearer token",
Expand All @@ -25,7 +25,7 @@ def wrapper(*args, token: HTTPAuthorizationCredentials = security, **kwargs):
def aio_requires_auth(func):
@wraps(func)
async def wrapper(*args, token: HTTPAuthorizationCredentials = None, **kwargs):
if token is None or token.credentials != os.environ["ARCAN_AUTH_TOKEN"]:
if token is None or token.credentials != os.environ["ARCAN_API_KEY"]:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect bearer token",
Expand Down
5 changes: 4 additions & 1 deletion tests/arcan/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ async def test_chat(mock_get_db):
# with patch('your_module_path.run_agent') as mock_run_agent:
# mock_run_agent.return_value = "Test Response"

mock_token = MagicMock()
mock_token.credentials = os.getenv("ARCAN_API_KEY")

async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.get(
"/api/chat", params={"user_id": "test_user", "query": "testinggggg$#@"}
"/api/chat", params={"user_id": "test_user", "query": "testinggggg$#@"}, headers={"Authorization ": f"Bearer {mock_token.credentials}"}
)
assert response.status_code == 200
assert response.json() == {"response": "test"}
Expand Down

0 comments on commit d0b417c

Please sign in to comment.