Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7387f9a78d | ||
|
|
894f5d137a |
+2
-5
@@ -28,9 +28,7 @@ PRONOTE_AUTH_MODE=password
|
||||
# PRONOTE_ACCOUNT_PIN=
|
||||
|
||||
# --- CalDAV ---
|
||||
# Endpoint commun (URL potentiellement sensible, masquée dans les journaux)
|
||||
CALDAV_ENDPOINT__URL=https://caldav.example.com/calendars/user/pronote/
|
||||
# Ancien nom temporairement supporté avec un avertissement de dépréciation : CALDAV_URL
|
||||
CALDAV_URL=https://caldav.example.com/calendars/user/pronote/
|
||||
CALDAV_USERNAME=user@example.com
|
||||
CALDAV_PASSWORD=your_caldav_password
|
||||
CALDAV_CALENDAR_PATH=/pronote-sync/
|
||||
@@ -94,8 +92,7 @@ AI_BASE_URL=https://api.openai.com/v1
|
||||
|
||||
# --- Blog ---
|
||||
BLOG_ENABLED=false
|
||||
BLOG_ENDPOINT__URL=https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2
|
||||
# Ancien nom temporairement supporté avec un avertissement de dépréciation : BLOG_RSS_URL
|
||||
BLOG_RSS_URL=https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2
|
||||
|
||||
# --- Divers ---
|
||||
DRY_RUN=false
|
||||
|
||||
+2
-2
@@ -140,7 +140,7 @@
|
||||
"filename": "GUIDE_DEV_PYTHON.md",
|
||||
"hashed_secret": "90bd1b48e958257948487b90bee080ba5ed00caa",
|
||||
"is_verified": false,
|
||||
"line_number": 5183
|
||||
"line_number": 5186
|
||||
}
|
||||
],
|
||||
"tests/unit/test_caldav_gateway.py": [
|
||||
@@ -185,5 +185,5 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"generated_at": "2026-09-13T09:52:29Z"
|
||||
"generated_at": "2026-09-12T22:12:56Z"
|
||||
}
|
||||
|
||||
+3
-2
@@ -40,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [0.1.0] - 2026-09-08
|
||||
|
||||
Initial release covering milestones M1 through M15, except the optional Gitea Actions workflow.
|
||||
Initial release covering milestones M1 through M15.
|
||||
|
||||
### Added
|
||||
- **M1 (Scaffolding)**: Python project structure with `pyproject.toml`, and tooling configuration for `ruff`, `mypy`, `bandit`, and `pre-commit`.
|
||||
@@ -57,4 +57,5 @@ Initial release covering milestones M1 through M15, except the optional Gitea Ac
|
||||
- **M12 (CLI entry point)**: `pronote-sync` command with `--dry-run` and `--log-level` options, redacted error display, and safe traceback in DEBUG mode.
|
||||
- **M13 (Tests & coverage)**: 636 tests with 95.67% coverage, test fixtures (`pronote-4e.ics`, `pronote-6e.ics`), shared `conftest.py`, and secret non-leak tests.
|
||||
- **M14 (Deployment)**: systemd service and timer (daily at 18:00), logrotate configuration (daily, rotate 7, compress), `check_secrets.py` pre-deployment scanner, and exploitation guide.
|
||||
- **M15 (Documentation)**: README, README.LLM.md (AI agent setup guide), MIT LICENSE, CHANGELOG, and local validation procedures. Gitea Actions CI/CD remains optional and is not delivered in this release.
|
||||
- **M15 (Documentation)**: README, README.LLM.md (AI agent setup guide), MIT LICENSE, CHANGELOG, and Gitea Actions CI/CD reference for LXC/VPS (Debian/CentOS).
|
||||
- **Other**: MIT License. Gitea Actions CI/CD reference for LXC/VPS (Debian/CentOS) is planned and optional, not delivered in this release.
|
||||
|
||||
+8
-5
@@ -264,7 +264,7 @@ Le projet utilise **`pydantic-settings`** pour valider et charger la configurati
|
||||
| `PRONOTE_USERNAME` | Identifiant Pronote (si `pronotepy` utilisé). | `parent.dupont` | `str` |
|
||||
| `PRONOTE_PASSWORD` | Mot de passe Pronote (si `pronotepy` utilisé). | `SecretStr` (masqué) | `SecretStr` |
|
||||
| `PRONOTE_ENT` | Slug ENT supporté, résolu vers une fonction de `pronotepy.ent`. | `monbureaunumerique` | `str` |
|
||||
| `CALDAV_ENDPOINT__URL` | URL du serveur CalDAV, via l'endpoint commun (masquée en `SecretStr`). | `https://caldav.example.com/calendars/...` | `ExternalEndpoint` |
|
||||
| `CALDAV_URL` | URL du serveur CalDAV (masquée en `SecretStr`). | `https://caldav.example.com/calendars/...` | `SecretStr` |
|
||||
| `CALDAV_USERNAME` | Identifiant CalDAV. | `user@example.com` | `str` |
|
||||
| `CALDAV_PASSWORD` | Mot de passe CalDAV. | `SecretStr` (masqué) | `SecretStr` |
|
||||
| `CALDAV_CALENDAR_PATH` | Chemin du calendrier CalDAV de destination. | `/pronote-sync/` | `str` |
|
||||
@@ -1113,7 +1113,7 @@ La déduplication des articles du blog repose sur leur **GUID** (ou leur URL si
|
||||
|
||||
Aucun fichier d'état local n'est utilisé : l'état est géré en mémoire par run.
|
||||
# Initialisation
|
||||
rss_client = BlogRSSClient(rss_url=settings.blog.endpoint.url.get_secret_value())
|
||||
rss_client = BlogRSSClient(rss_url=settings.blog.rss_url)
|
||||
blog_state = ## (section obsolète supprimée)()
|
||||
|
||||
# Récupération des nouveaux articles
|
||||
@@ -1218,7 +1218,7 @@ Ajouter les variables suivantes dans la configuration :
|
||||
| **Variable** | **Description** | **Valeur par défaut** | **Type** |
|
||||
|----------------------------|-------------------------------------------------------------------------------|-----------------------|-------------------|
|
||||
| `BLOG_ENABLED` | Activer la récupération du blog. | `False` | `bool` |
|
||||
| `BLOG_ENDPOINT__URL` | URL du flux RSS via l'endpoint commun (masquée en `SecretStr`). | `https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2` | `ExternalEndpoint` |
|
||||
| `BLOG_RSS_URL` | URL du flux RSS du blog. | `https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2` | `str` |
|
||||
|
||||
#### 5 bis.9.2 Modèle Pydantic pour la configuration du blog
|
||||
|
||||
@@ -1230,7 +1230,10 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
class BlogSettings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_prefix="BLOG_", env_file=".env", extra="ignore")
|
||||
enabled: bool = Field(False, description="Activer la récupération du blog")
|
||||
endpoint: ExternalEndpoint
|
||||
rss_url: str = Field(
|
||||
"https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2",
|
||||
description="URL du flux RSS du blog",
|
||||
)
|
||||
```
|
||||
|
||||
**Intégration dans `Settings`** :
|
||||
@@ -1250,7 +1253,7 @@ class Settings(BaseSettings):
|
||||
```ini
|
||||
# --- Blog du collège ---
|
||||
BLOG_ENABLED=true
|
||||
BLOG_ENDPOINT__URL=https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2
|
||||
BLOG_RSS_URL=https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -12,8 +12,8 @@ Synchronise l'agenda et les devoirs de **Pronote** vers un calendrier **CalDAV**
|
||||
|
||||
```bash
|
||||
# Cloner le dépôt
|
||||
git clone https://git.antoineve.me/AntoineVe/college-infos
|
||||
cd college-infos
|
||||
git clone <repo-url>
|
||||
cd pronote-sync
|
||||
|
||||
# Créer l'environnement virtuel
|
||||
python3.13 -m venv .venv
|
||||
@@ -48,23 +48,6 @@ pas garantir un état persistant cohérent pendant une simulation.
|
||||
|
||||
---
|
||||
|
||||
## Validation et CI
|
||||
|
||||
Aucun workflow Gitea Actions n'est livré actuellement. Les validations du projet sont donc
|
||||
exécutées localement avec les commandes suivantes :
|
||||
|
||||
```bash
|
||||
pytest
|
||||
ruff check .
|
||||
mypy .
|
||||
bandit -r pronote_sync/
|
||||
```
|
||||
|
||||
`pre-commit run --all-files` regroupe également les contrôles de formatage, typage, sécurité et
|
||||
détection de secrets.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Déploiement
|
||||
|
||||
Les artefacts pour **systemd/timer** et **logrotate** sont fournis dans `deploy/`. Voir [docs/exploitation.md](docs/exploitation.md) pour plus de détails.
|
||||
|
||||
@@ -308,5 +308,5 @@ Rédiger la documentation utilisateur et finaliser le projet.
|
||||
|
||||
### Critères d'acceptation
|
||||
- `README.md` permet d'installer et de lancer le projet sans le guide.
|
||||
- Les procédures locales de test, lint et sécurité sont documentées et exécutables.
|
||||
- Gitea Actions exécute tests + lint + sécurité.
|
||||
- Aucun secret dans la documentation.
|
||||
|
||||
+39
-160
@@ -10,76 +10,21 @@ from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
from datetime import date
|
||||
from typing import Annotated, Literal
|
||||
from typing import Literal
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from pydantic import (
|
||||
AfterValidator,
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
SecretStr,
|
||||
ValidationInfo,
|
||||
field_serializer,
|
||||
field_validator,
|
||||
model_validator,
|
||||
)
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
from pronote_sync.utils.redaction import redact_url
|
||||
|
||||
_EXTERNAL_ENDPOINT_SCHEMES: frozenset[str] = frozenset({"file", "http", "https"})
|
||||
_LOOPBACK_HOSTS: frozenset[str] = frozenset({"localhost", "127.0.0.1", "::1"})
|
||||
|
||||
|
||||
def _validate_external_endpoint_url(value: SecretStr) -> SecretStr:
|
||||
"""Valide la structure et le schéma d'une URL d'endpoint externe.
|
||||
|
||||
:param value: URL potentiellement sensible à valider.
|
||||
:return: URL validée, toujours encapsulée dans ``SecretStr``.
|
||||
:rtype: SecretStr
|
||||
:raises ValueError: Si l'URL est malformée ou utilise un schéma inconnu.
|
||||
"""
|
||||
is_valid = False
|
||||
try:
|
||||
parsed = urlparse(value.get_secret_value())
|
||||
_ = parsed.port
|
||||
is_valid = (
|
||||
parsed.scheme in _EXTERNAL_ENDPOINT_SCHEMES
|
||||
and (parsed.scheme not in {"http", "https"} or parsed.hostname is not None)
|
||||
and (parsed.scheme != "file" or bool(parsed.path))
|
||||
)
|
||||
except ValueError:
|
||||
pass
|
||||
if not is_valid:
|
||||
raise ValueError("Endpoint externe invalide : URL ou schéma non supporté") from None
|
||||
return value
|
||||
|
||||
|
||||
EndpointUrl = Annotated[SecretStr, AfterValidator(_validate_external_endpoint_url)]
|
||||
|
||||
|
||||
class ExternalEndpoint(BaseModel):
|
||||
"""Représente un endpoint externe potentiellement sensible.
|
||||
|
||||
Le socle accepte les transports ``https``, ``http`` et ``file``. Chaque
|
||||
connecteur restreint ensuite cette liste selon sa propre politique de
|
||||
sécurité. L'URL reste encapsulée dans :class:`pydantic.SecretStr` et sa
|
||||
sérialisation conserve uniquement une représentation expurgée.
|
||||
"""
|
||||
|
||||
model_config = ConfigDict(extra="forbid", frozen=True, hide_input_in_errors=True)
|
||||
|
||||
url: EndpointUrl
|
||||
|
||||
@field_serializer("url")
|
||||
def _serialize_url(self, value: SecretStr) -> str:
|
||||
"""Expurge l'URL lors de la sérialisation.
|
||||
|
||||
:param value: URL encapsulée à sérialiser.
|
||||
:return: URL expurgée.
|
||||
:rtype: str
|
||||
"""
|
||||
return redact_url(value.get_secret_value())
|
||||
|
||||
|
||||
class PronoteSettings(BaseSettings):
|
||||
"""Paramètres d'accès à Pronote (flux iCal et API ``pronotepy``).
|
||||
@@ -146,88 +91,73 @@ class CalDAVSettings(BaseSettings):
|
||||
|
||||
Les variables d'environnement correspondantes sont préfixées par
|
||||
``CALDAV_``. L'URL est traitée comme potentiellement sensible (au même
|
||||
titre que ``PRONOTE_ICAL_ENDPOINT__URL``) : elle est de type ``SecretStr`` et
|
||||
titre que ``PRONOTE_ICAL_URL``) : elle est de type ``SecretStr`` et
|
||||
masquée lors de la sérialisation. Par défaut, seul HTTPS est accepté ;
|
||||
HTTP n'est toléré que pour un hôte de boucle locale (``localhost``,
|
||||
``127.0.0.1``, ``::1``) lorsque ``allow_insecure_http`` vaut ``True``.
|
||||
Le nouvel endpoint se configure avec ``CALDAV_ENDPOINT__URL`` ;
|
||||
``CALDAV_URL`` reste temporairement pris en charge avec un avertissement
|
||||
de dépréciation.
|
||||
"""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_nested_delimiter="__",
|
||||
extra="ignore",
|
||||
env_prefix="CALDAV_",
|
||||
)
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore", env_prefix="CALDAV_")
|
||||
|
||||
allow_insecure_http: bool = False
|
||||
endpoint: ExternalEndpoint | None = None
|
||||
url: SecretStr | None = Field(
|
||||
default=None,
|
||||
exclude=True,
|
||||
deprecated="Utiliser endpoint.url à la place (CALDAV_URL obsolète).",
|
||||
)
|
||||
url: SecretStr | None = None
|
||||
username: str | None = None
|
||||
password: SecretStr | None = None
|
||||
calendar_path: str = "/pronote-sync/"
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def _migrate_legacy_url(cls, data: object) -> object:
|
||||
"""Migre ``url`` vers l'endpoint commun avec un avertissement.
|
||||
@field_serializer("url")
|
||||
def _serialize_url(self, value: SecretStr | None) -> str | None:
|
||||
"""Masque l'URL CalDAV lors de la sérialisation (repr, str, JSON).
|
||||
|
||||
:param data: Données brutes du modèle.
|
||||
:return: Données complétées avec ``endpoint`` si nécessaire.
|
||||
:rtype: object
|
||||
:param value: Valeur du champ ``url`` (secret potentiel).
|
||||
:return: URL avec les éléments sensibles remplacés par ``REDACTED``,
|
||||
ou ``None`` si la valeur est absente.
|
||||
:rtype: str | None
|
||||
"""
|
||||
if not isinstance(data, dict) or data.get("url") is None:
|
||||
return data
|
||||
migrated_data = data.copy()
|
||||
warnings.warn(
|
||||
"CALDAV_URL est obsolète : utiliser CALDAV_ENDPOINT__URL.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
if migrated_data.get("endpoint") is None:
|
||||
migrated_data["endpoint"] = {"url": migrated_data["url"]}
|
||||
return migrated_data
|
||||
if value is None:
|
||||
return None
|
||||
return redact_url(value.get_secret_value())
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _validate_endpoint_policy(self) -> CalDAVSettings:
|
||||
"""Applique la politique HTTPS/HTTP loopback propre à CalDAV.
|
||||
@field_validator("url")
|
||||
@classmethod
|
||||
def _validate_url_https(cls, v: SecretStr | None, info: ValidationInfo) -> SecretStr | None:
|
||||
"""Valide le schéma de l'URL CalDAV (HTTPS obligatoire par défaut).
|
||||
|
||||
HTTPS est toujours accepté. HTTP n'est accepté que pour un hôte de
|
||||
boucle locale (``localhost``, ``127.0.0.1``, ``::1``) et uniquement
|
||||
lorsque ``allow_insecure_http`` vaut ``True``. Les autres schémas du
|
||||
socle commun sont refusés pour ce connecteur.
|
||||
lorsque ``allow_insecure_http`` vaut ``True``. Les messages d'erreur
|
||||
ne contiennent jamais l'URL brute (susceptible de contenir des
|
||||
identifiants).
|
||||
|
||||
:return: Instance validée inchangée.
|
||||
:rtype: CalDAVSettings
|
||||
:param v: Valeur du champ ``url`` à valider.
|
||||
:param info: Contexte de validation (accès aux autres champs).
|
||||
:return: La valeur validée inchangée.
|
||||
:rtype: SecretStr | None
|
||||
:raises ValueError: Si le schéma n'est pas supporté ou si l'URL HTTP
|
||||
n'est pas autorisée.
|
||||
"""
|
||||
if self.endpoint is None:
|
||||
return self
|
||||
raw_url = self.endpoint.url.get_secret_value()
|
||||
if v is None:
|
||||
return v
|
||||
raw_url = v.get_secret_value()
|
||||
parsed = urlparse(raw_url)
|
||||
if parsed.scheme not in ("http", "https"):
|
||||
raise ValueError("URL CalDAV invalide : schéma non supporté") from None
|
||||
if parsed.scheme == "https":
|
||||
return self
|
||||
return v
|
||||
# HTTP — check allow_insecure_http flag and loopback
|
||||
if not self.allow_insecure_http:
|
||||
allow_insecure = info.data.get("allow_insecure_http", False)
|
||||
if not allow_insecure:
|
||||
raise ValueError(
|
||||
"URL CalDAV non sécurisée : HTTPS requis (ou activer "
|
||||
"CALDAV_ALLOW_INSECURE_HTTP pour localhost)"
|
||||
) from None
|
||||
hostname = parsed.hostname or ""
|
||||
if hostname not in _LOOPBACK_HOSTS:
|
||||
loopback_hosts = {"localhost", "127.0.0.1", "::1"}
|
||||
if hostname not in loopback_hosts:
|
||||
raise ValueError(
|
||||
"URL CalDAV non sécurisée : HTTP autorisé uniquement pour localhost"
|
||||
) from None
|
||||
return self
|
||||
return v
|
||||
|
||||
|
||||
_XMPP_LOOPBACK_HOSTS: frozenset[str] = frozenset({"localhost", "127.0.0.1", "::1"})
|
||||
@@ -352,60 +282,10 @@ class BlogSettings(BaseSettings):
|
||||
``BLOG_``.
|
||||
"""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_nested_delimiter="__",
|
||||
extra="ignore",
|
||||
env_prefix="BLOG_",
|
||||
)
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore", env_prefix="BLOG_")
|
||||
|
||||
enabled: bool = False
|
||||
endpoint: ExternalEndpoint = Field(
|
||||
default_factory=lambda: ExternalEndpoint(
|
||||
url=SecretStr("https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2")
|
||||
)
|
||||
)
|
||||
rss_url: str | None = Field(
|
||||
default=None,
|
||||
exclude=True,
|
||||
deprecated="Utiliser endpoint.url à la place (BLOG_RSS_URL obsolète).",
|
||||
)
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def _migrate_legacy_rss_url(cls, data: object) -> object:
|
||||
"""Migre ``rss_url`` vers l'endpoint commun avec un avertissement.
|
||||
|
||||
:param data: Données brutes du modèle.
|
||||
:return: Données complétées avec ``endpoint`` si nécessaire.
|
||||
:rtype: object
|
||||
"""
|
||||
if not isinstance(data, dict) or data.get("rss_url") is None:
|
||||
return data
|
||||
migrated_data = data.copy()
|
||||
warnings.warn(
|
||||
"BLOG_RSS_URL est obsolète : utiliser BLOG_ENDPOINT__URL.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
if migrated_data.get("endpoint") is None:
|
||||
migrated_data["endpoint"] = {"url": migrated_data["rss_url"]}
|
||||
return migrated_data
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _validate_endpoint_policy(self) -> BlogSettings:
|
||||
"""Refuse les transports non sûrs pour le flux RSS de production.
|
||||
|
||||
Le transport ``file`` reste autorisé pour les fixtures locales.
|
||||
|
||||
:return: Instance validée inchangée.
|
||||
:rtype: BlogSettings
|
||||
:raises ValueError: Si le schéma n'est ni ``https`` ni ``file``.
|
||||
"""
|
||||
scheme = urlparse(self.endpoint.url.get_secret_value()).scheme
|
||||
if scheme not in {"https", "file"}:
|
||||
raise ValueError("URL RSS invalide : HTTPS ou file requis") from None
|
||||
return self
|
||||
rss_url: str = "https://blogpeda.ac-bordeaux.fr/cjeliote/?feed=rss2"
|
||||
|
||||
|
||||
class AppSettings(BaseSettings):
|
||||
@@ -462,10 +342,9 @@ class Settings(BaseSettings):
|
||||
self.pronote.password,
|
||||
self.pronote.qr_pin,
|
||||
self.pronote.account_pin,
|
||||
self.caldav.endpoint.url if self.caldav.endpoint is not None else None,
|
||||
self.caldav.url,
|
||||
self.caldav.password,
|
||||
self.xmpp.password,
|
||||
self.ai.api_key,
|
||||
self.blog.endpoint.url,
|
||||
]
|
||||
return tuple(dict.fromkeys(secret for secret in secrets if secret is not None))
|
||||
|
||||
@@ -138,11 +138,7 @@ class PipelineRunner:
|
||||
comparator = (
|
||||
AgendaComparator(theoretical_provider) if theoretical_provider is not None else None
|
||||
)
|
||||
blog_client = (
|
||||
BlogRSSClient(settings.blog.endpoint.url.get_secret_value())
|
||||
if settings.blog.enabled
|
||||
else None
|
||||
)
|
||||
blog_client = BlogRSSClient(settings.blog.rss_url) if settings.blog.enabled else None
|
||||
blog_state = (
|
||||
BlogRSSState(persistence_enabled=persistence_enabled) if settings.blog.enabled else None
|
||||
)
|
||||
|
||||
@@ -79,12 +79,11 @@ class CalDAVGateway:
|
||||
else cast(Callable[..., Any], caldav.DAVClient)
|
||||
)
|
||||
self._calendar_path: str = settings.calendar_path
|
||||
url_secret = settings.endpoint.url if settings.endpoint is not None else None
|
||||
self._redacted_url: str | None = (
|
||||
redact_url(url_secret.get_secret_value()) if url_secret else None
|
||||
redact_url(settings.url.get_secret_value()) if settings.url else None
|
||||
)
|
||||
self._username: str | None = settings.username
|
||||
self._url_secret: SecretStr | None = url_secret
|
||||
self._url_secret: SecretStr | None = settings.url
|
||||
self._password_secret: SecretStr | None = settings.password
|
||||
self._client: Any = None
|
||||
self._calendar: Any = None
|
||||
|
||||
@@ -96,7 +96,7 @@ def synchronize(
|
||||
)
|
||||
|
||||
if (
|
||||
settings.caldav.endpoint is None
|
||||
settings.caldav.url is None
|
||||
or settings.caldav.username is None
|
||||
or settings.caldav.password is None
|
||||
):
|
||||
|
||||
+5
-6
@@ -7,10 +7,9 @@ name = "pronote-sync"
|
||||
version = "0.1.2"
|
||||
description = "Synchronisation Pronote → CalDAV + XMPP"
|
||||
license = {text = "MIT"}
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13.5"
|
||||
authors = [
|
||||
{name = "Antoine Van Elstraete", email = "antoine@van-elstraete.net"}
|
||||
{name = "Votre Nom", email = "votre@email.com"}
|
||||
]
|
||||
keywords = ["pronote", "caldav", "xmpp", "sync", "school"]
|
||||
classifiers = [
|
||||
@@ -58,10 +57,10 @@ dev = [
|
||||
pronote-sync = "pronote_sync.cli.main:main"
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://git.antoineve.me/AntoineVe/college-infos"
|
||||
Documentation = "https://git.antoineve.me/AntoineVe/college-infos/wiki"
|
||||
Repository = "https://git.antoineve.me/AntoineVe/college-infos"
|
||||
Issues = "https://git.antoineve.me/AntoineVe/college-infos/issues"
|
||||
Homepage = "https://github.com/votre-utilisateur/pronote-sync"
|
||||
Documentation = "https://github.com/votre-utilisateur/pronote-sync#readme"
|
||||
Repository = "https://github.com/votre-utilisateur/pronote-sync"
|
||||
Issues = "https://github.com/votre-utilisateur/pronote-sync/issues"
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["."]
|
||||
|
||||
@@ -26,12 +26,12 @@ _TEXT_SUFFIXES = frozenset(
|
||||
{".conf", ".ini", ".json", ".md", ".py", ".service", ".timer", ".toml", ".txt", ".yaml", ".yml"}
|
||||
)
|
||||
_LITERAL_SECRET_RE = re.compile(
|
||||
r"(?ix)\b[a-z0-9_]*(?:api[_-]?key|access[_-]?token|auth(?:orization)?|icalsecurise|password|secret|token)"
|
||||
r"\s*[:=]\s*['\"][^'\"\r\n]{3,}['\"]"
|
||||
r"(?ix)\b[a-z0-9_]*(?:api[_-]?key|access[_-]?token|auth(?:orization)?|icalsecurise|password|pin|secret|token)"
|
||||
r"\s*[:=]\s*['\"](?P<value>[^'\"\r\n]{3,})['\"]"
|
||||
)
|
||||
_UNQUOTED_SECRET_RE = re.compile(
|
||||
r"(?ix)\b[a-z0-9_]*(?:api[_-]?key|access[_-]?token|auth(?:orization)?|icalsecurise|password|secret|token)"
|
||||
r"\s*[:=]\s*[a-z0-9][a-z0-9._~+/-]{2,}"
|
||||
r"(?ix)\b[a-z0-9_]*(?:api[_-]?key|access[_-]?token|auth(?:orization)?|icalsecurise|password|pin|secret|token)"
|
||||
r"\s*[:=]\s*(?P<value>[a-z0-9][a-z0-9._~+/-]{2,})"
|
||||
)
|
||||
_URL_SECRET_RE = re.compile(
|
||||
r"(?ix)[?&](?:api[_-]?key|access[_-]?token|auth(?:orization)?|icalsecurise|password|secret|token)"
|
||||
@@ -47,6 +47,13 @@ _URL_PLACEHOLDER_RE = re.compile(
|
||||
r")$"
|
||||
)
|
||||
_EXTRA_NAMES = frozenset({"pronote_sync"})
|
||||
_ASSIGNMENT_PLACEHOLDER_RE = re.compile(
|
||||
r"(?ix)^(?:"
|
||||
r"<(?:pin|secret|valeur|value|token|jeton)>|"
|
||||
r"(?:change|replace|your)[_-]?(?:me|here|value|valeur|pin|password|secret)|"
|
||||
r"(?:placeholder|example|local-not-required)"
|
||||
r")$"
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -68,6 +75,16 @@ CommandRunner = Callable[..., subprocess.CompletedProcess[str]]
|
||||
ContentProvider = Callable[[Path], str | None]
|
||||
|
||||
|
||||
def _is_assignment_placeholder(value: str) -> bool:
|
||||
"""Indique si une valeur d'affectation est un placeholder documentaire.
|
||||
|
||||
:param value: Valeur extraite d'une affectation sensible.
|
||||
:return: ``True`` si la valeur ne représente pas un secret réel.
|
||||
:rtype: bool
|
||||
"""
|
||||
return _ASSIGNMENT_PLACEHOLDER_RE.fullmatch(value.strip()) is not None
|
||||
|
||||
|
||||
def _is_candidate(path: Path) -> bool:
|
||||
"""Indique si un chemin peut être analysé comme fichier texte.
|
||||
|
||||
@@ -188,9 +205,15 @@ def find_secrets(
|
||||
for number, line in enumerate(content.splitlines(), start=1):
|
||||
if _ALLOWLIST_MARKER in line:
|
||||
continue
|
||||
is_literal_secret = _LITERAL_SECRET_RE.search(line) or (
|
||||
relative_path.suffix in _UNQUOTED_CONFIG_SUFFIXES
|
||||
and _UNQUOTED_SECRET_RE.search(line)
|
||||
literal_match = _LITERAL_SECRET_RE.search(line)
|
||||
unquoted_match = (
|
||||
_UNQUOTED_SECRET_RE.search(line)
|
||||
if relative_path.suffix in _UNQUOTED_CONFIG_SUFFIXES
|
||||
else None
|
||||
)
|
||||
is_literal_secret = any(
|
||||
match is not None and not _is_assignment_placeholder(match.group("value"))
|
||||
for match in (literal_match, unquoted_match)
|
||||
)
|
||||
if is_literal_secret:
|
||||
findings.append(SecretFinding(relative_path, number, "affectation-litterale"))
|
||||
|
||||
@@ -236,6 +236,58 @@ def test_main_detects_prefixed_secret_assignment(
|
||||
assert sentinel not in output
|
||||
|
||||
|
||||
def test_main_detects_pronote_pin_assignments_without_disclosing_value(
|
||||
secret_checker: ModuleType, tmp_path: Path, capsys: CaptureFixture[str]
|
||||
) -> None:
|
||||
"""Détecte les PIN Pronote littéraux et non quotés sans afficher leur valeur.
|
||||
|
||||
:param secret_checker: Module du script sous test.
|
||||
:param tmp_path: Répertoire temporaire représentant un dépôt.
|
||||
:param capsys: Fixture de capture de sortie.
|
||||
:return: None
|
||||
"""
|
||||
literal_pin = "pin-literal-sentinel"
|
||||
unquoted_pin = "pin-unquoted-sentinel"
|
||||
(tmp_path / "settings.py").write_text(f'PRONOTE_QR_PIN = "{literal_pin}"\n', encoding="utf-8")
|
||||
(tmp_path / "settings.yaml").write_text(
|
||||
f"PRONOTE_ACCOUNT_PIN: {unquoted_pin}\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
assert secret_checker.main([], root=tmp_path) == 1
|
||||
output = capsys.readouterr().out
|
||||
assert "settings.py:1" in output
|
||||
assert "settings.yaml:1" in output
|
||||
assert literal_pin not in output
|
||||
assert unquoted_pin not in output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"line",
|
||||
[
|
||||
'PRONOTE_QR_PIN = "<valeur>"',
|
||||
"# PRONOTE_ACCOUNT_PIN doit rester dans le fichier d'environnement local",
|
||||
],
|
||||
)
|
||||
def test_main_ignores_pronote_pin_placeholders_and_descriptions(
|
||||
secret_checker: ModuleType,
|
||||
tmp_path: Path,
|
||||
capsys: CaptureFixture[str],
|
||||
line: str,
|
||||
) -> None:
|
||||
"""Ignore les placeholders et descriptions de PIN sans affectation réelle.
|
||||
|
||||
:param secret_checker: Module du script sous test.
|
||||
:param tmp_path: Répertoire temporaire représentant un dépôt.
|
||||
:param capsys: Fixture de capture de sortie.
|
||||
:param line: Ligne documentaire à analyser.
|
||||
:return: None
|
||||
"""
|
||||
(tmp_path / "guide.py").write_text(line + "\n", encoding="utf-8")
|
||||
|
||||
assert secret_checker.main([], root=tmp_path) == 0
|
||||
assert "OK:" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_main_detects_short_secret_assignment(
|
||||
secret_checker: ModuleType, tmp_path: Path, capsys: CaptureFixture[str]
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user