Wire account registration to the ircd's ENCAP SWACCTREG/SWACCTRES relay
All checks were successful
CI / check (push) Successful in 3m53s
All checks were successful
CI / check (push) Successful in 3m53s
Echo is the authority the ircd account module forwards to: parse ENCAP <us> SWACCTREG <reqid> <origin> <kind> <account> <p2> :<p3> into an account request, and answer the origin server with ENCAP <origin> SWACCTRES <reqid> <kind> <account> <status> <code> :<message>. Thread the origin through the reply so responses route back to the requesting server. Replaces the placeholder ACCTREGISTER/ACCTREGRESULT names that nothing on the wire actually spoke.
This commit is contained in:
parent
994e8c7347
commit
54ad013e49
5 changed files with 72 additions and 36 deletions
|
|
@ -809,8 +809,8 @@ impl Engine {
|
|||
Vec::new()
|
||||
}
|
||||
NetEvent::Privmsg { from, to, text } => self.dispatch(&from, &to, &text),
|
||||
NetEvent::AccountRequest { reqid, kind, account, p2, p3, .. } => {
|
||||
self.account_request(reqid, kind, account, p2, p3)
|
||||
NetEvent::AccountRequest { reqid, origin, kind, account, p2, p3 } => {
|
||||
self.account_request(reqid, origin, kind, account, p2, p3)
|
||||
}
|
||||
NetEvent::Sasl { client, mode, data, .. } => self.sasl(client, mode, data),
|
||||
_ => Vec::new(),
|
||||
|
|
@ -1146,7 +1146,7 @@ enum RegOutcome {
|
|||
// so both the pre-check rejection and the post-derivation result share one place.
|
||||
fn reg_reply(reply: &RegReply, outcome: RegOutcome, account: &str) -> Vec<NetAction> {
|
||||
match reply {
|
||||
RegReply::Relay { reqid, kind } => {
|
||||
RegReply::Relay { reqid, kind, origin } => {
|
||||
let (status, code, message) = match outcome {
|
||||
RegOutcome::Ok => ("success", "*", "Account registered."),
|
||||
RegOutcome::VerifyRequired => ("verification_required", "VERIFICATION_REQUIRED", "Registered — check your email for a code, then VERIFY."),
|
||||
|
|
@ -1158,6 +1158,7 @@ fn reg_reply(reply: &RegReply, outcome: RegOutcome, account: &str) -> Vec<NetAct
|
|||
};
|
||||
vec![NetAction::AccountResponse {
|
||||
reqid: reqid.clone(),
|
||||
origin: origin.clone(),
|
||||
kind: kind.clone(),
|
||||
account: account.to_string(),
|
||||
status: status.to_string(),
|
||||
|
|
|
|||
|
|
@ -134,16 +134,17 @@ impl Engine {
|
|||
// registration). REGISTER hands off to the link layer (which derives the
|
||||
// password off-thread) via DeferRegister; VERIFY/RESEND/STATUS are answered
|
||||
// here directly against the emailed-code flow.
|
||||
pub(crate) fn account_request(&mut self, reqid: String, kind: String, account: String, p2: String, p3: String) -> Vec<NetAction> {
|
||||
pub(crate) fn account_request(&mut self, reqid: String, origin: String, kind: String, account: String, p2: String, p3: String) -> Vec<NetAction> {
|
||||
if kind.eq_ignore_ascii_case("REGISTER") {
|
||||
let email = if p2.is_empty() || p2 == "*" { None } else { Some(p2) };
|
||||
return vec![NetAction::DeferRegister { account, password: p3, email, reply: RegReply::Relay { reqid, kind } }];
|
||||
return vec![NetAction::DeferRegister { account, password: p3, email, reply: RegReply::Relay { reqid, kind, origin } }];
|
||||
}
|
||||
|
||||
// Relay-only replies, built directly (REGISTER goes through complete_register).
|
||||
let resp = |status: &str, code: &str, message: &str| {
|
||||
vec![NetAction::AccountResponse {
|
||||
reqid: reqid.clone(),
|
||||
origin: origin.clone(),
|
||||
kind: kind.clone(),
|
||||
account: account.clone(),
|
||||
status: status.to_string(),
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@
|
|||
let mut e = Engine::new(vec![Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 })], db);
|
||||
|
||||
// REGISTER <account> <email> :<password> relayed from the ircd.
|
||||
let reg = e.account_request("r1".into(), "REGISTER".into(), "neo".into(), "neo@example.org".into(), "trinity".into());
|
||||
let reg = e.account_request("r1".into(), "leaf".into(), "REGISTER".into(), "neo".into(), "neo@example.org".into(), "trinity".into());
|
||||
let (account, password, email, reply) = reg.iter().find_map(|a| match a {
|
||||
NetAction::DeferRegister { account, password, email, reply } => Some((account.clone(), password.clone(), email.clone(), reply.clone())),
|
||||
_ => None,
|
||||
|
|
@ -623,16 +623,16 @@
|
|||
let code = body.split("CONFIRM ").nth(1).unwrap().split_whitespace().next().unwrap().to_string();
|
||||
|
||||
// VERIFY with the code succeeds; a stale/duplicate VERIFY then fails.
|
||||
let ok = e.account_request("r2".into(), "VERIFY".into(), "neo".into(), code, String::new());
|
||||
let ok = e.account_request("r2".into(), "leaf".into(), "VERIFY".into(), "neo".into(), code, String::new());
|
||||
assert!(ok.iter().any(|a| matches!(a, NetAction::AccountResponse { status, .. } if status == "success")), "{ok:?}");
|
||||
assert!(e.db.is_verified("neo"), "verified after VERIFY");
|
||||
let again = e.account_request("r3".into(), "VERIFY".into(), "neo".into(), "000000".into(), String::new());
|
||||
let again = e.account_request("r3".into(), "leaf".into(), "VERIFY".into(), "neo".into(), "000000".into(), String::new());
|
||||
assert!(again.iter().any(|a| matches!(a, NetAction::AccountResponse { code, .. } if code == "INVALID_CODE")), "{again:?}");
|
||||
|
||||
// STATUS reports verified; VERIFY on an unknown account is a clean error.
|
||||
let st = e.account_request("r4".into(), "STATUS".into(), "neo".into(), String::new(), String::new());
|
||||
let st = e.account_request("r4".into(), "leaf".into(), "STATUS".into(), "neo".into(), String::new(), String::new());
|
||||
assert!(st.iter().any(|a| matches!(a, NetAction::AccountResponse { code, .. } if code == "VERIFIED")), "{st:?}");
|
||||
let unknown = e.account_request("r5".into(), "VERIFY".into(), "ghost".into(), "x".into(), String::new());
|
||||
let unknown = e.account_request("r5".into(), "leaf".into(), "VERIFY".into(), "ghost".into(), "x".into(), String::new());
|
||||
assert!(unknown.iter().any(|a| matches!(a, NetAction::AccountResponse { code, .. } if code == "ACCOUNT_UNKNOWN")), "{unknown:?}");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue