fix: use constant value DNS challenge
This commit is contained in:
parent
f9da115100
commit
944cf7075c
2 changed files with 5 additions and 33 deletions
|
@ -23,10 +23,8 @@ use std::cell::RefCell;
|
||||||
use tera::Context;
|
use tera::Context;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::errors::ServiceResult;
|
|
||||||
use crate::pages::errors::*;
|
use crate::pages::errors::*;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use crate::verify::{Challenge, TXTChallenge};
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub use crate::pages::*;
|
pub use crate::pages::*;
|
||||||
|
@ -47,7 +45,7 @@ impl CtxError for AddChallenge {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct AddChallengePayload {
|
pub struct AddChallengePayload {
|
||||||
pub hostname: String,
|
pub hostname: Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddChallenge {
|
impl AddChallenge {
|
||||||
|
@ -85,33 +83,8 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
#[post(path = "PAGES.auth.add")]
|
#[post(path = "PAGES.auth.add")]
|
||||||
pub async fn add_submit(
|
pub async fn add_submit(
|
||||||
payload: web::Form<AddChallengePayload>,
|
payload: web::Form<AddChallengePayload>,
|
||||||
ctx: WebCtx,
|
|
||||||
) -> PageResult<impl Responder, AddChallenge> {
|
) -> PageResult<impl Responder, AddChallenge> {
|
||||||
async fn _add_submit(
|
let link = PAGES.auth.verify_get(&payload.hostname.to_string());
|
||||||
payload: &AddChallengePayload,
|
|
||||||
ctx: &ArcCtx,
|
|
||||||
) -> ServiceResult<TXTChallenge> {
|
|
||||||
let url_hostname = Url::parse(&payload.hostname).unwrap();
|
|
||||||
let challenge = TXTChallenge::new(ctx, &url_hostname);
|
|
||||||
|
|
||||||
let c = Challenge {
|
|
||||||
key: challenge.key,
|
|
||||||
value: challenge.value,
|
|
||||||
url: url_hostname.to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let challenge = TXTChallenge {
|
|
||||||
key: c.key,
|
|
||||||
value: c.value,
|
|
||||||
};
|
|
||||||
Ok(challenge)
|
|
||||||
}
|
|
||||||
|
|
||||||
let challenge = _add_submit(&payload, &ctx)
|
|
||||||
.await
|
|
||||||
.map_err(|e| PageError::new(AddChallenge::new(&ctx.settings, Some(&payload)), e))?;
|
|
||||||
|
|
||||||
let link = PAGES.auth.verify_get(&challenge.key);
|
|
||||||
|
|
||||||
Ok(HttpResponse::Found()
|
Ok(HttpResponse::Found()
|
||||||
.insert_header((http::header::LOCATION, link))
|
.insert_header((http::header::LOCATION, link))
|
||||||
|
@ -125,7 +98,6 @@ mod tests {
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use super::AddChallengePayload;
|
use super::AddChallengePayload;
|
||||||
use super::TXTChallenge;
|
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -140,7 +112,7 @@ mod tests {
|
||||||
let settings = Settings::new().unwrap();
|
let settings = Settings::new().unwrap();
|
||||||
AddChallenge::page(&settings);
|
AddChallenge::page(&settings);
|
||||||
let payload = AddChallengePayload {
|
let payload = AddChallengePayload {
|
||||||
hostname: "https://example.com".into(),
|
hostname: url::Url::parse("https://example.com").unwrap(),
|
||||||
};
|
};
|
||||||
let page = AddChallenge::new(&settings, Some(&payload));
|
let page = AddChallenge::new(&settings, Some(&payload));
|
||||||
page.with_error(&ReadableError::new(&ServiceError::ClosedForRegistration));
|
page.with_error(&ReadableError::new(&ServiceError::ClosedForRegistration));
|
||||||
|
@ -158,7 +130,7 @@ mod tests {
|
||||||
let app = get_app!(ctx, db, federate).await;
|
let app = get_app!(ctx, db, federate).await;
|
||||||
|
|
||||||
let payload = AddChallengePayload {
|
let payload = AddChallengePayload {
|
||||||
hostname: format!("https://{BASE_DOMAIN}"),
|
hostname: Url::parse(&format!("https://{BASE_DOMAIN}")).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", payload.hostname);
|
println!("{}", payload.hostname);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<li>
|
<li>
|
||||||
<p>Click verify to verify challenge
|
<p>Click verify to verify challenge
|
||||||
<form action="{{ page.auth.verify }}" method="POST">
|
<form action="{{ page.auth.verify }}" method="POST">
|
||||||
<input type="hidden" name="hostname" id="hostname" value="{{ payload.key }}">
|
<input type="hidden" name="hostname" id="hostname" value="{{ payload.url }}">
|
||||||
<button type="submit">Verify</button>
|
<button type="submit">Verify</button>
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Add table
Reference in a new issue