mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-16 00:14:31 +00:00
refactor: rename the application package to docsgpt
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
This commit is contained in:
1 parent
3e7f1f91b4
commit
574f96341e
984 files changed
+9847
-9682
No files matched your search
+30
-30
@@ -7,34 +7,34 @@ import pytest
|
||||
class TestHandleAuth:
|
||||
|
||||
def test_returns_local_when_no_auth_type(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
with patch("application.auth.settings") as mock_settings:
|
||||
with patch("docsgpt.auth.settings") as mock_settings:
|
||||
mock_settings.AUTH_TYPE = "none"
|
||||
result = handle_auth(mock_request)
|
||||
|
||||
assert result == {"sub": "local"}
|
||||
|
||||
def test_returns_none_when_no_jwt_header(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = None
|
||||
with patch("application.auth.settings") as mock_settings:
|
||||
with patch("docsgpt.auth.settings") as mock_settings:
|
||||
mock_settings.AUTH_TYPE = "simple_jwt"
|
||||
result = handle_auth(mock_request)
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_decodes_valid_jwt(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = "Bearer valid_token"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings, patch(
|
||||
"application.auth.jwt"
|
||||
with patch("docsgpt.auth.settings") as mock_settings, patch(
|
||||
"docsgpt.auth.jwt"
|
||||
) as mock_jwt:
|
||||
mock_settings.AUTH_TYPE = "simple_jwt"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
@@ -50,13 +50,13 @@ class TestHandleAuth:
|
||||
)
|
||||
|
||||
def test_returns_error_on_invalid_jwt(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = "Bearer bad_token"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings, patch(
|
||||
"application.auth.jwt"
|
||||
with patch("docsgpt.auth.settings") as mock_settings, patch(
|
||||
"docsgpt.auth.jwt"
|
||||
) as mock_jwt:
|
||||
mock_settings.AUTH_TYPE = "session_jwt"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
@@ -66,13 +66,13 @@ class TestHandleAuth:
|
||||
assert result["error"] == "invalid_token"
|
||||
|
||||
def test_strips_bearer_prefix(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = "Bearer my_token"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings, patch(
|
||||
"application.auth.jwt"
|
||||
with patch("docsgpt.auth.settings") as mock_settings, patch(
|
||||
"docsgpt.auth.jwt"
|
||||
) as mock_jwt:
|
||||
mock_settings.AUTH_TYPE = "simple_jwt"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
@@ -88,24 +88,24 @@ class TestHandleAuthOidc:
|
||||
"""AUTH_TYPE=oidc: same local HS256 session tokens, but exp is verified."""
|
||||
|
||||
def test_returns_none_when_no_jwt_header(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = None
|
||||
with patch("application.auth.settings") as mock_settings:
|
||||
with patch("docsgpt.auth.settings") as mock_settings:
|
||||
mock_settings.AUTH_TYPE = "oidc"
|
||||
result = handle_auth(mock_request)
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_decodes_valid_jwt_with_exp_verification(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = "Bearer valid_token"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings, patch(
|
||||
"application.auth.jwt"
|
||||
with patch("docsgpt.auth.settings") as mock_settings, patch(
|
||||
"docsgpt.auth.jwt"
|
||||
) as mock_jwt:
|
||||
mock_settings.AUTH_TYPE = "oidc"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
@@ -123,13 +123,13 @@ class TestHandleAuthOidc:
|
||||
def test_expired_token_returns_token_expired(self):
|
||||
from jose.exceptions import ExpiredSignatureError
|
||||
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = "Bearer stale_token"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings, patch(
|
||||
"application.auth.jwt"
|
||||
with patch("docsgpt.auth.settings") as mock_settings, patch(
|
||||
"docsgpt.auth.jwt"
|
||||
) as mock_jwt:
|
||||
mock_settings.AUTH_TYPE = "oidc"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
@@ -139,13 +139,13 @@ class TestHandleAuthOidc:
|
||||
assert result["error"] == "token_expired"
|
||||
|
||||
def test_invalid_token_returns_invalid_token(self):
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = "Bearer bad_token"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings, patch(
|
||||
"application.auth.jwt"
|
||||
with patch("docsgpt.auth.settings") as mock_settings, patch(
|
||||
"docsgpt.auth.jwt"
|
||||
) as mock_jwt:
|
||||
mock_settings.AUTH_TYPE = "oidc"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
@@ -160,13 +160,13 @@ class TestHandleAuthOidc:
|
||||
# authenticate, or it would be valid forever and unrevocable.
|
||||
from jose import jwt as real_jwt
|
||||
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
token = real_jwt.encode({"sub": "helper_user"}, "secret", algorithm="HS256")
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = f"Bearer {token}"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings:
|
||||
with patch("docsgpt.auth.settings") as mock_settings:
|
||||
mock_settings.AUTH_TYPE = "oidc"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
result = handle_auth(mock_request)
|
||||
@@ -178,7 +178,7 @@ class TestHandleAuthOidc:
|
||||
|
||||
from jose import jwt as real_jwt
|
||||
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
token = real_jwt.encode(
|
||||
{"sub": "helper_user", "exp": int(time.time()) - 3600},
|
||||
@@ -188,7 +188,7 @@ class TestHandleAuthOidc:
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = f"Bearer {token}"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings:
|
||||
with patch("docsgpt.auth.settings") as mock_settings:
|
||||
mock_settings.AUTH_TYPE = "oidc"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
result = handle_auth(mock_request)
|
||||
@@ -200,7 +200,7 @@ class TestHandleAuthOidc:
|
||||
|
||||
from jose import jwt as real_jwt
|
||||
|
||||
from application.auth import handle_auth
|
||||
from docsgpt.auth import handle_auth
|
||||
|
||||
token = real_jwt.encode(
|
||||
{"sub": "local", "exp": int(time.time()) - 3600},
|
||||
@@ -210,7 +210,7 @@ class TestHandleAuthOidc:
|
||||
mock_request = Mock()
|
||||
mock_request.headers.get.return_value = f"Bearer {token}"
|
||||
|
||||
with patch("application.auth.settings") as mock_settings:
|
||||
with patch("docsgpt.auth.settings") as mock_settings:
|
||||
mock_settings.AUTH_TYPE = "simple_jwt"
|
||||
mock_settings.JWT_SECRET_KEY = "secret"
|
||||
result = handle_auth(mock_request)
|
||||
|
||||
Reference in new issue
Block a user