Free chart summaries; password login off by default
- New analysis kind 'summary' (migration 0005): saving a chart queues a
free 3-4 sentence summary written by SUMMARY_MODEL (default Sonnet
5.5, about 1 cent; Haiku was tested too but chose weaker highlights).
POST /v1/charts/{id}/summary returns it and re-queues a failed one.
- The chart page shows it in a "Röviden" card and polls until ready.
- PASSWORD_LOGIN (default false): register, login and password reset
answer 403; only Google (later Apple, Facebook) logins remain.
- Prompt v2: Hungarian names for elements and modalities (an English
"Fire" slipped into a summary); worker compare-models --summary.
- The worker also reads a lower-case openrouter_api_key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -13,20 +13,22 @@ Felhasználók, belépés, mentett születési képletek, szinasztriák és megh
|
||||
| `COOKIE_SECURE` | `true` | csak helyi, sima HTTP-s fejlesztéshez legyen `false` |
|
||||
| `COOKIE_DOMAIN` | – | pl. `.sorsfonalak.hu`, ha a frontend és az API más aldomainen fut |
|
||||
| `SESSION_TTL_DAYS` | `30` | a munkamenet élettartama |
|
||||
| `PASSWORD_LOGIN` | `false` | e-mail + jelszó regisztráció és belépés; élesben ki van kapcsolva (csak Google, Apple, Facebook), a jelszavas végpontok ilyenkor 403-at adnak |
|
||||
| `GOOGLE_CLIENT_IDS` | – | Google OAuth kliens-azonosító(k); üresen a Google-belépés ki van kapcsolva |
|
||||
| `BOOTSTRAP_ADMIN_EMAILS` | – | ezek a címek regisztrációkor vagy belépéskor admin szerepet kapnak (így lesz meg az első admin) |
|
||||
| `SUPPORTED_LOCALES` | `hu,en` | felület- és elemzésnyelvek; az első az alapértelmezett |
|
||||
| `MONTHLY_FREE_CREDITS` | `10` | havi ingyenes kreditkeret |
|
||||
| `ANALYSIS_COST` | `1` | egy új elemzés ára kreditben azoknál a modelleknél, amelyeknél az `LLM_MODELS` nem ad meg árat |
|
||||
| `LLM_MODELS` | lásd lent | választható modellek `modell[=kredit][@szerep]` alakban, vesszővel elválasztva; az első az alapértelmezett, és ahhoz nem kellhet szerep |
|
||||
| `ANALYSIS_PROMPT_VERSION` | `v1` | a prompt verziója (az elemzés-gyorsítótár kulcsának része) |
|
||||
| `SUMMARY_MODEL` | `anthropic/claude-sonnet-5.5` | ez írja minden mentett képlet ingyenes rövid összefoglalóját (kb. 1 cent darabonként) |
|
||||
| `ANALYSIS_PROMPT_VERSION` | `v2` | a prompt verziója (az elemzés-gyorsítótár kulcsának része) |
|
||||
| `MAX_CHARTS_PER_USER` | `50` | ennyi képletet menthet egy felhasználó |
|
||||
| `BIND_ADDR`, `LOG_FORMAT`, `RUST_LOG` | `0.0.0.0:8081`, `text`, `info` | |
|
||||
|
||||
## Belépés és jogosultság
|
||||
|
||||
- **Munkamenet:** véletlen token, HttpOnly + SameSite=Lax sütiben (`sf_session`). A belépési válasz törzsében is ott van, hogy nem böngészős kliens `Authorization: Bearer <token>` fejléccel küldhesse vissza. Az adatbázis csak a token SHA-256 hash-ét tárolja, így a munkamenet visszavonható (kijelentkezés, jelszócsere, fióktörlés).
|
||||
- **E-mail + jelszó:**
|
||||
- **E-mail + jelszó** (csak `PASSWORD_LOGIN=true` mellett; élesben csak közösségi belépés lesz, hogy ne lehessen tömegesen ingyenes fiókokat nyitni):
|
||||
- a jelszó legalább 10 karakter, Argon2id hash-sel tárolva;
|
||||
- címenként 15 percen belül 10 hibás próbálkozás után átmenetileg tiltás jár;
|
||||
- ismeretlen címnél is ugyanannyi ideig tart a válasz.
|
||||
@@ -44,7 +46,7 @@ Felhasználók, belépés, mentett születési képletek, szinasztriák és megh
|
||||
|
||||
| Végpont | Guard | Leírás |
|
||||
|---|---|---|
|
||||
| `GET /v1/config` | – | Google kliens-azonosító, nyelvek, modellek, kreditárak |
|
||||
| `GET /v1/config` | – | Google kliens-azonosító, `password_login`, nyelvek, modellek, kreditárak |
|
||||
| `POST /v1/auth/register` | – | `{email, password, display_name?, locale?}` → munkamenet; megerősítő e-mailt küld |
|
||||
| `POST /v1/auth/login` | – | `{email, password}` |
|
||||
| `POST /v1/auth/google` | – | `{id_token}`; `created: true`, ha most jött létre a fiók |
|
||||
@@ -58,7 +60,8 @@ Felhasználók, belépés, mentett születési képletek, szinasztriák és megh
|
||||
| `GET /v1/me/export` | user | GDPR: minden adat egy JSON-ban |
|
||||
| `GET /v1/credits` | user | egyenleg és kreditmozgások |
|
||||
| `GET`/`POST /v1/charts` | user | képletek listája; új képlet: `{label, is_primary, birth}`, ahol a `birth` a horoscope-api `/v1/natal` kérésformátuma |
|
||||
| `GET`/`PATCH`/`DELETE /v1/charts/{id}` | tulajdonos | a születési adat nem módosítható: a javított képlet új képlet |
|
||||
| `GET`/`PATCH`/`DELETE /v1/charts/{id}` | tulajdonos | a születési adat nem módosítható: a javított képlet új képlet. Ugyanarra a születési adatra a `POST /v1/charts` a meglévő képletet adja vissza (200), nem számol újat |
|
||||
| `POST /v1/charts/{id}/summary` | tulajdonos | az ingyenes rövid összefoglaló (`kind: summary`, `{title, summary}`); mentéskor magától sorba áll, ez visszaadja, és ha elbukott, újra sorba állítja |
|
||||
| `GET`/`POST /v1/synastries` | user | `{chart1_id, chart2_id}`, mindkét képlet a sajátod |
|
||||
| `GET`/`DELETE /v1/synastries/{id}` | résztvevő | |
|
||||
| `GET`/`POST /v1/invites` | user | „Mennyire illünk össze?” link; alapból a saját (primary) képlettel |
|
||||
|
||||
@@ -72,6 +72,9 @@ pub struct Config {
|
||||
pub cookie_domain: Option<String>,
|
||||
/// `SESSION_TTL_DAYS` (default 30).
|
||||
pub session_ttl_days: i64,
|
||||
/// `PASSWORD_LOGIN` (default `false`): e-mail and password registration and
|
||||
/// login. Off in production, where only Google, Apple and Facebook are offered.
|
||||
pub password_login: bool,
|
||||
/// `GOOGLE_CLIENT_IDS`: comma-separated OAuth client ids accepted as the
|
||||
/// ID token audience; empty disables Google login.
|
||||
pub google_client_ids: Vec<String>,
|
||||
@@ -89,7 +92,10 @@ pub struct Config {
|
||||
/// Credits default to `ANALYSIS_COST` (default 1). Default:
|
||||
/// [`DEFAULT_LLM_MODELS`].
|
||||
pub llm_models: Vec<LlmModel>,
|
||||
/// `ANALYSIS_PROMPT_VERSION` (default `v1`); part of the analysis cache key.
|
||||
/// `SUMMARY_MODEL`: writes the free short summary of every saved chart
|
||||
/// (default `anthropic/claude-sonnet-5.5`, about 1 US cent each).
|
||||
pub summary_model: String,
|
||||
/// `ANALYSIS_PROMPT_VERSION` (default `v2`); part of the analysis cache key.
|
||||
pub prompt_version: String,
|
||||
/// `MAX_CHARTS_PER_USER` (default 50).
|
||||
pub max_charts_per_user: i64,
|
||||
@@ -147,6 +153,7 @@ impl Config {
|
||||
cookie_secure: parsed("COOKIE_SECURE", true)?,
|
||||
cookie_domain: var("COOKIE_DOMAIN"),
|
||||
session_ttl_days: parsed("SESSION_TTL_DAYS", 30)?,
|
||||
password_login: parsed("PASSWORD_LOGIN", false)?,
|
||||
google_client_ids: list("GOOGLE_CLIENT_IDS"),
|
||||
google_jwks_url: var("GOOGLE_JWKS_URL")
|
||||
.unwrap_or_else(|| "https://www.googleapis.com/oauth2/v3/certs".into()),
|
||||
@@ -154,7 +161,8 @@ impl Config {
|
||||
supported_locales,
|
||||
monthly_free_credits: parsed("MONTHLY_FREE_CREDITS", 10)?,
|
||||
llm_models,
|
||||
prompt_version: var("ANALYSIS_PROMPT_VERSION").unwrap_or_else(|| "v1".into()),
|
||||
summary_model: var("SUMMARY_MODEL").unwrap_or_else(|| "anthropic/claude-sonnet-5.5".into()),
|
||||
prompt_version: var("ANALYSIS_PROMPT_VERSION").unwrap_or_else(|| "v2".into()),
|
||||
max_charts_per_user: parsed("MAX_CHARTS_PER_USER", 50)?,
|
||||
};
|
||||
if config.session_ttl_days < 1 {
|
||||
@@ -177,6 +185,7 @@ impl Config {
|
||||
cookie_secure: true,
|
||||
cookie_domain: None,
|
||||
session_ttl_days: 30,
|
||||
password_login: true,
|
||||
google_client_ids: vec!["test-client.apps.googleusercontent.com".into()],
|
||||
google_jwks_url,
|
||||
bootstrap_admin_emails: vec!["admin@example.com".into()],
|
||||
@@ -187,6 +196,7 @@ impl Config {
|
||||
1,
|
||||
)
|
||||
.unwrap(),
|
||||
summary_model: "anthropic/claude-summary".into(),
|
||||
prompt_version: "v1".into(),
|
||||
max_charts_per_user: 50,
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ pub async fn change_password(
|
||||
auth: AuthUser,
|
||||
WithRejection(Json(req), _): Body<ChangePassword>,
|
||||
) -> ApiResult<StatusCode> {
|
||||
super::auth::password_login_enabled(&state)?;
|
||||
validate_password(&req.new_password)?;
|
||||
let existing: Option<(String,)> =
|
||||
sqlx::query_as("SELECT password_hash FROM auth_identities WHERE user_id = $1 AND provider = 'password'")
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
//! writes the text later. A finished analysis with the same cache key (same
|
||||
//! chart or synastry hash, prompt version, model and language) is copied
|
||||
//! instead, free of charge, so the same chart is never paid for twice.
|
||||
//!
|
||||
//! Every saved chart also gets a free short summary (`summary` kind, written
|
||||
//! by `SUMMARY_MODEL`); the detailed analyses are paid.
|
||||
|
||||
use axum::Json;
|
||||
use axum::body::Bytes;
|
||||
@@ -17,7 +20,7 @@ use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::auth::validate_locale;
|
||||
use super::charts::{find_chart, owned_chart};
|
||||
use super::charts::{ChartRow, find_chart, owned_chart};
|
||||
use super::synastries::{load_synastry, visible_synastry};
|
||||
use super::{IdPath, St};
|
||||
use crate::AppState;
|
||||
@@ -104,6 +107,7 @@ fn optional_body(body: &[u8]) -> Result<AnalysisRequest, ApiError> {
|
||||
|
||||
enum Target {
|
||||
Natal { chart_id: Uuid, hash: String },
|
||||
Summary { chart_id: Uuid, hash: String },
|
||||
Synastry { synastry_id: Uuid, hash: String },
|
||||
}
|
||||
|
||||
@@ -127,9 +131,25 @@ async fn request(
|
||||
{
|
||||
return Err(ApiError::Forbidden(format!("the model '{}' needs the '{}' role", chosen.id, role.as_str())));
|
||||
}
|
||||
let model = chosen.id.clone();
|
||||
let (kind, hash, chart_id, synastry_id) = match &target {
|
||||
let cost = chosen.credits;
|
||||
let (status, row) = queue(state, auth.id(), &target, &language, &chosen.id, cost).await?;
|
||||
Ok((status, Json(row.view())))
|
||||
}
|
||||
|
||||
/// Returns the existing analysis with the same cache key for this target,
|
||||
/// copies a finished one from another chart with the same data, or queues a
|
||||
/// new one (spending `cost` credits). 200, 201 and 202 respectively.
|
||||
async fn queue(
|
||||
state: &AppState,
|
||||
user: Uuid,
|
||||
target: &Target,
|
||||
language: &str,
|
||||
model: &str,
|
||||
cost: i32,
|
||||
) -> Result<(StatusCode, AnalysisRow), ApiError> {
|
||||
let (kind, hash, chart_id, synastry_id) = match target {
|
||||
Target::Natal { chart_id, hash } => ("natal", hash, Some(*chart_id), None),
|
||||
Target::Summary { chart_id, hash } => ("summary", hash, Some(*chart_id), None),
|
||||
Target::Synastry { synastry_id, hash } => ("synastry", hash, None, Some(*synastry_id)),
|
||||
};
|
||||
let prompt_version = &state.config.prompt_version;
|
||||
@@ -147,7 +167,7 @@ async fn request(
|
||||
.fetch_optional(&state.db)
|
||||
.await?;
|
||||
if let Some(row) = existing {
|
||||
return Ok((StatusCode::OK, Json(row.view())));
|
||||
return Ok((StatusCode::OK, row));
|
||||
}
|
||||
|
||||
let insert = format!(
|
||||
@@ -170,9 +190,9 @@ async fn request(
|
||||
.bind(kind)
|
||||
.bind(chart_id)
|
||||
.bind(synastry_id)
|
||||
.bind(auth.id())
|
||||
.bind(&language)
|
||||
.bind(&model)
|
||||
.bind(user)
|
||||
.bind(language)
|
||||
.bind(model)
|
||||
.bind(prompt_version)
|
||||
.bind(&cache_key)
|
||||
.bind("done")
|
||||
@@ -183,20 +203,19 @@ async fn request(
|
||||
.bind(OffsetDateTime::now_utc())
|
||||
.fetch_one(&state.db)
|
||||
.await?;
|
||||
return Ok((StatusCode::CREATED, Json(row.view())));
|
||||
return Ok((StatusCode::CREATED, row));
|
||||
}
|
||||
|
||||
// New analysis: spend credits and queue it for the worker.
|
||||
let cost = chosen.credits;
|
||||
let mut tx = state.db.begin().await?;
|
||||
let row: AnalysisRow = sqlx::query_as(&insert)
|
||||
.bind(id)
|
||||
.bind(kind)
|
||||
.bind(chart_id)
|
||||
.bind(synastry_id)
|
||||
.bind(auth.id())
|
||||
.bind(&language)
|
||||
.bind(&model)
|
||||
.bind(user)
|
||||
.bind(language)
|
||||
.bind(model)
|
||||
.bind(prompt_version)
|
||||
.bind(&cache_key)
|
||||
.bind("pending")
|
||||
@@ -207,9 +226,28 @@ async fn request(
|
||||
.bind(None::<OffsetDateTime>)
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
credits::spend(&mut tx, auth.id(), cost, state.config.monthly_free_credits, "analysis", Some(id)).await?;
|
||||
if cost > 0 {
|
||||
credits::spend(&mut tx, user, cost, state.config.monthly_free_credits, "analysis", Some(id)).await?;
|
||||
}
|
||||
tx.commit().await?;
|
||||
Ok((StatusCode::ACCEPTED, Json(row.view())))
|
||||
Ok((StatusCode::ACCEPTED, row))
|
||||
}
|
||||
|
||||
/// The free short summary of a chart (in the owner's language): queued if
|
||||
/// it does not exist yet or the last attempt failed.
|
||||
pub async fn ensure_summary(state: &AppState, owner: &AuthUser, chart: &ChartRow) -> Result<AnalysisRow, ApiError> {
|
||||
let target = Target::Summary { chart_id: chart.id, hash: chart.chart_hash.clone() };
|
||||
let model = state.config.summary_model.clone();
|
||||
Ok(queue(state, owner.id(), &target, &owner.user.locale, &model, 0).await?.1)
|
||||
}
|
||||
|
||||
pub async fn summary_for_chart(
|
||||
State(state): St,
|
||||
auth: AuthUser,
|
||||
WithRejection(Path(id), _): IdPath,
|
||||
) -> ApiResult<Json<Value>> {
|
||||
let chart = owned_chart(&state.db, id, auth.id()).await?;
|
||||
Ok(Json(ensure_summary(&state, &auth, &chart).await?.view()))
|
||||
}
|
||||
|
||||
async fn list_where(db: &PgPool, column: &str, id: Uuid) -> Result<Json<Value>, ApiError> {
|
||||
|
||||
@@ -158,12 +158,22 @@ pub struct RegisterRequest {
|
||||
locale: Option<String>,
|
||||
}
|
||||
|
||||
/// Password endpoints answer 403 while `PASSWORD_LOGIN` is off.
|
||||
pub fn password_login_enabled(state: &crate::AppState) -> Result<(), ApiError> {
|
||||
if state.config.password_login {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ApiError::Forbidden("e-mail and password login is disabled; use Google, Apple or Facebook".into()))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register(
|
||||
State(state): St,
|
||||
headers: HeaderMap,
|
||||
jar: CookieJar,
|
||||
WithRejection(Json(req), _): Body<RegisterRequest>,
|
||||
) -> ApiResult<impl IntoResponse> {
|
||||
password_login_enabled(&state)?;
|
||||
let email = normalize_email(&req.email)?;
|
||||
validate_password(&req.password)?;
|
||||
let locale = validate_locale(&state, req.locale.as_deref())?;
|
||||
@@ -213,6 +223,7 @@ pub async fn login(
|
||||
jar: CookieJar,
|
||||
WithRejection(Json(req), _): Body<LoginRequest>,
|
||||
) -> ApiResult<impl IntoResponse> {
|
||||
password_login_enabled(&state)?;
|
||||
let invalid = || ApiError::InvalidCredentials("wrong e-mail address or password".into());
|
||||
let email = normalize_email(&req.email).map_err(|_| invalid())?;
|
||||
state.login_limiter.check(&email)?;
|
||||
@@ -394,6 +405,7 @@ pub async fn request_password_reset(
|
||||
State(state): St,
|
||||
WithRejection(Json(req), _): Body<ResetRequest>,
|
||||
) -> ApiResult<StatusCode> {
|
||||
password_login_enabled(&state)?;
|
||||
let Ok(email) = normalize_email(&req.email) else { return Ok(StatusCode::ACCEPTED) };
|
||||
let mut tx = state.db.begin().await?;
|
||||
let user: Option<User> = sqlx::query_as(&format!("SELECT {USER_COLUMNS} FROM users WHERE email = $1"))
|
||||
@@ -422,6 +434,7 @@ pub async fn confirm_password_reset(
|
||||
State(state): St,
|
||||
WithRejection(Json(req), _): Body<ResetConfirmRequest>,
|
||||
) -> ApiResult<StatusCode> {
|
||||
password_login_enabled(&state)?;
|
||||
validate_password(&req.password)?;
|
||||
let hash = hash_password(req.password).await?;
|
||||
let mut tx = state.db.begin().await?;
|
||||
|
||||
@@ -112,6 +112,14 @@ pub async fn calculate(state: &AppState, birth: Value) -> Result<(Value, Value,
|
||||
Ok((birth, result, hash))
|
||||
}
|
||||
|
||||
/// Queues the free short summary; a failure here does not fail the save
|
||||
/// (the chart page asks for the summary again).
|
||||
async fn queue_summary(state: &AppState, auth: &AuthUser, chart: &ChartRow) {
|
||||
if let Err(e) = super::analyses::ensure_summary(state, auth, chart).await {
|
||||
tracing::warn!(chart = %chart.id, error = %e, "queueing the chart summary failed");
|
||||
}
|
||||
}
|
||||
|
||||
fn clean_birth(birth: Value) -> Result<Value, ApiError> {
|
||||
let Value::Object(mut birth) = birth else {
|
||||
return Err(ApiError::BadRequest("birth must be an object".into()));
|
||||
@@ -150,8 +158,10 @@ pub async fn create(
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
queue_summary(&state, &auth, &row).await;
|
||||
return Ok((StatusCode::OK, Json(row.owner_view())));
|
||||
}
|
||||
queue_summary(&state, &auth, &chart).await;
|
||||
return Ok((StatusCode::OK, Json(chart.owner_view())));
|
||||
}
|
||||
let (count,): (i64,) =
|
||||
@@ -185,6 +195,7 @@ pub async fn create(
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
queue_summary(&state, &auth, &row).await;
|
||||
Ok((StatusCode::CREATED, Json(row.owner_view())))
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/v1/charts", get(charts::list).post(charts::create))
|
||||
.route("/v1/charts/{id}", get(charts::get_one).patch(charts::update).delete(charts::remove))
|
||||
.route("/v1/charts/{id}/analyses", get(analyses::list_for_chart).post(analyses::request_for_chart))
|
||||
.route("/v1/charts/{id}/summary", post(analyses::summary_for_chart))
|
||||
// synastries and invitations
|
||||
.route("/v1/synastries", get(synastries::list).post(synastries::create))
|
||||
.route("/v1/synastries/{id}", get(synastries::get_one).delete(synastries::remove))
|
||||
@@ -118,6 +119,7 @@ async fn public_config(State(state): St) -> Json<Value> {
|
||||
"llm_models": c.llm_models,
|
||||
"default_model": c.llm_models[0].id,
|
||||
"monthly_free_credits": c.monthly_free_credits,
|
||||
"password_login": c.password_login,
|
||||
"password_min_length": crate::auth::MIN_PASSWORD_LEN,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -115,8 +115,13 @@ struct Response {
|
||||
|
||||
impl TestApp {
|
||||
async fn new(pool: PgPool) -> Self {
|
||||
Self::with_config(pool, |_| {}).await
|
||||
}
|
||||
|
||||
async fn with_config(pool: PgPool, change: impl FnOnce(&mut Config)) -> Self {
|
||||
let fake = fake_services().await;
|
||||
let config = Config::for_tests(String::new(), fake.clone(), format!("{fake}/jwks"));
|
||||
let mut config = Config::for_tests(String::new(), fake.clone(), format!("{fake}/jwks"));
|
||||
change(&mut config);
|
||||
Self { router: routes::router(Arc::new(AppState::new(pool.clone(), config))), pool }
|
||||
}
|
||||
|
||||
@@ -458,6 +463,17 @@ async fn analyses_spend_credits_and_reuse_results(pool: PgPool) {
|
||||
let chart = app.chart(&anna, "Saját", true, "1990-03-15").await;
|
||||
let uri = format!("/v1/charts/{}/analyses", chart["id"].as_str().unwrap());
|
||||
|
||||
// saving the chart queued the free short summary
|
||||
let list = app.get(&uri, Some(&anna)).await.body;
|
||||
let summary = &list["analyses"][0];
|
||||
assert_eq!(
|
||||
(summary["kind"].as_str(), summary["status"].as_str(), summary["model"].as_str(), &summary["credits_charged"]),
|
||||
(Some("summary"), Some("pending"), Some("anthropic/claude-summary"), &json!(0))
|
||||
);
|
||||
let r = app.call("POST", &format!("/v1/charts/{}/summary", chart["id"].as_str().unwrap()), Some(&anna), None).await;
|
||||
assert_eq!((r.status, &r.body["id"]), (StatusCode::OK, &summary["id"]));
|
||||
assert_eq!(app.get("/v1/credits", Some(&anna)).await.body["balance"], 2);
|
||||
|
||||
let r = app.call("POST", &uri, Some(&anna), None).await;
|
||||
assert_eq!(r.status, StatusCode::ACCEPTED, "{}", r.body);
|
||||
assert_eq!((r.body["status"].as_str(), r.body["language"].as_str()), (Some("pending"), Some("hu")));
|
||||
@@ -493,7 +509,22 @@ async fn analyses_spend_credits_and_reuse_results(pool: PgPool) {
|
||||
assert_eq!(app.get("/v1/credits", Some(&bela)).await.body["balance"], 2);
|
||||
|
||||
assert_eq!(app.get(&format!("/v1/analyses/{first}"), Some(&bela)).await.status, StatusCode::NOT_FOUND);
|
||||
assert_eq!(app.get(&uri, Some(&anna)).await.body["analyses"].as_array().unwrap().len(), 2);
|
||||
assert_eq!(app.get(&uri, Some(&anna)).await.body["analyses"].as_array().unwrap().len(), 3); // 2 + summary
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn password_login_can_be_disabled(pool: PgPool) {
|
||||
let app = TestApp::with_config(pool, |c| c.password_login = false).await;
|
||||
assert_eq!(app.get("/v1/config", None).await.body["password_login"], false);
|
||||
let r = app
|
||||
.post("/v1/auth/register", None, json!({"email": "anna@example.com", "password": "titkos-jelszo-123"}))
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::FORBIDDEN);
|
||||
let r =
|
||||
app.post("/v1/auth/login", None, json!({"email": "anna@example.com", "password": "titkos-jelszo-123"})).await;
|
||||
assert_eq!(r.status, StatusCode::FORBIDDEN);
|
||||
let r = app.post("/v1/auth/password-reset", None, json!({"email": "anna@example.com"})).await;
|
||||
assert_eq!(r.status, StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
|
||||
Reference in New Issue
Block a user