a464e550c9
Full-stack implementation of the Cyberyan full-stack trial task. Backend (Django 5 / DRF) - Normalised PostgreSQL model (Profile, Company, School, Skill, Experience, Education) as the source of truth, with GIN + trigram indexes. - Self-healing CSV reader: the supplied export carries an injected watermark column, missing columns, rows split by broken quoting and a duplicated header. A signature-scored Needleman-Wunsch alignment reconstructs 284 clean records out of 336 physical rows; only 10 rows parse correctly without it. - Pluggable search layer (Strategy): Elasticsearch by default, PostgreSQL full-text search as a fallback selected by a single environment variable. - Keyword search with per-field boosts, fuzziness and phrase boosting, six faceted filters (OR within a filter, AND across filters), an experience range, four sort orders, highlighting and facet aggregations. - JWT auth with rotation + blacklist, three roles, PII masking, scoped rate limits, a single error envelope, OpenAPI schema and health probes. Frontend (React 18 / TypeScript / Vite) - Debounced search with type-ahead, faceted filter panel, result cards, profile drawer, URL-synced search state, automatic token refresh. - Highlight snippets rendered without dangerouslySetInnerHTML. Infrastructure - Hardened multi-stage images (non-root, read-only rootfs, healthchecks). - docker-compose for the full stack plus dev and production overlays. - ELK: structured JSON logs shipped asynchronously to Logstash, routed per event type, with a composable index template and a Kibana setup script. Quality - 61 backend tests (85% coverage), ruff/black/bandit/mypy, ESLint + tsc, GitHub Actions running lint, tests and both image builds. - Persian documentation: README plus architecture, search, API, data, security and operations guides. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GnFo6fNaHCTAkJbfcdkqtG
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Masking helpers must never leak the original value."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from apps.profiles.privacy import mask_email, mask_emails, mask_phone, mask_phones
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("raw", "expected"),
|
|
[
|
|
("joseph.holland@garverusa.com", "jo************@garverusa.com"),
|
|
# A single character local part is hidden completely - keeping it would
|
|
# reveal the whole address.
|
|
("a@b.com", "*@b.com"),
|
|
],
|
|
)
|
|
def test_mask_email_keeps_domain_and_hides_local_part(raw: str, expected: str) -> None:
|
|
masked = mask_email(raw)
|
|
assert masked == expected
|
|
assert masked.endswith("@" + raw.split("@")[1])
|
|
|
|
|
|
def test_mask_email_handles_garbage() -> None:
|
|
assert mask_email("not-an-email") == "***"
|
|
assert mask_email("") == "***"
|
|
|
|
|
|
def test_mask_phone_hides_the_middle() -> None:
|
|
masked = mask_phone("+19402058928")
|
|
assert masked.startswith("+1940")
|
|
assert masked.endswith("28")
|
|
assert "*" in masked
|
|
assert "20589" not in masked
|
|
|
|
|
|
def test_mask_phone_rejects_short_input() -> None:
|
|
assert mask_phone("+123") == "***"
|
|
|
|
|
|
def test_list_helpers_preserve_structure() -> None:
|
|
emails = [{"address": "a.person@corp.com", "type": "professional"}]
|
|
masked = mask_emails(emails)
|
|
assert masked[0]["type"] == "professional"
|
|
assert masked[0]["address"] != emails[0]["address"]
|
|
assert mask_phones(["+19402058928"])[0] != "+19402058928"
|