@@ -7,10 +7,16 @@ use crate::{
77 AdminError , AdminService , Operator , Reason ,
88 admin:: tests:: { Account , Harness , cli, operator} ,
99 passkey:: PasskeyError ,
10+ security:: ApiError ,
1011 security:: CONFIRMATION_MAX_AGE ,
1112 tests:: { Browser , Replicas , sign_out, until_blocked} ,
1213} ;
13- use axum:: http:: Method ;
14+ use axum:: {
15+ Router ,
16+ extract:: { Path , State } ,
17+ http:: Method ,
18+ routing:: delete,
19+ } ;
1420use chrono:: { Duration , Utc } ;
1521use piquel_common:: {
1622 AuthenticationMethod , EmailId , Provider , TokenId , UserId ,
@@ -444,9 +450,9 @@ async fn the_last_passkey_stays_whoever_removes_it() {
444450}
445451
446452/// The shared changes that could cut the owner off need their recent passkey
447- /// confirmation, checked under the account lock before anything is looked up: a
448- /// session that never confirmed one is refused, whichever passkey, identity or
449- /// address it names.
453+ /// confirmation, checked before anything else, and again under the account lock:
454+ /// a session that never confirmed one is refused, whichever passkey, identity or
455+ /// address it names, even a malformed one .
450456#[ tokio:: test]
451457#[ ignore = "requires TEST_DATABASE_URL" ]
452458async fn owners_confirm_the_changes_that_need_it ( ) {
@@ -455,15 +461,20 @@ async fn owners_confirm_the_changes_that_need_it() {
455461 let social =
456462 Browser :: sign_in_with ( & database, owner. user_id , AuthenticationMethod :: Federation ) . await ;
457463 let routes = AccountApplication :: new ( database) . routes ( ) ;
458- let item = |template : & str | template. replace ( "{id}" , & EmailId :: new ( ) . to_string ( ) ) ;
464+ let item = |template : & str , id : & str | template. replace ( "{id}" , id) ;
465+ let id = EmailId :: new ( ) . to_string ( ) ;
466+ let identity = |provider| federation:: IDENTITY . replace ( "{provider}" , provider) ;
467+ // Before anything else: malformed IDs and unknown providers too, so the
468+ // browser confirms first.
459469 for ( method, path) in [
460- ( Method :: DELETE , item ( passkey:: ITEM ) ) ,
461- (
462- Method :: DELETE ,
463- federation:: IDENTITY . replace ( "{provider}" , "github" ) ,
464- ) ,
465- ( Method :: POST , item ( emails:: PRIMARY ) ) ,
466- ( Method :: DELETE , item ( emails:: ITEM ) ) ,
470+ ( Method :: DELETE , item ( passkey:: ITEM , & id) ) ,
471+ ( Method :: DELETE , item ( passkey:: ITEM , "not-an-id" ) ) ,
472+ ( Method :: DELETE , identity ( "github" ) ) ,
473+ ( Method :: DELETE , identity ( "myspace" ) ) ,
474+ ( Method :: POST , item ( emails:: PRIMARY , & id) ) ,
475+ ( Method :: POST , item ( emails:: PRIMARY , "not-an-id" ) ) ,
476+ ( Method :: DELETE , item ( emails:: ITEM , & id) ) ,
477+ ( Method :: DELETE , item ( emails:: ITEM , "not-an-id" ) ) ,
467478 ] {
468479 let ( status, body) = social. call ( & routes, method. clone ( ) , & path) . await ;
469480 assert_eq ! (
@@ -474,18 +485,32 @@ async fn owners_confirm_the_changes_that_need_it() {
474485 }
475486}
476487
477- /// A change that needs the owner's confirmation checks it on the session as the
478- /// request's cookie found it, too: a request whose session was confirmed only
479- /// while it waited for the account lock is refused, so a cookie from before a
480- /// confirmation never gains it.
488+ /// A change that needs the owner's confirmation checks it under the account lock
489+ /// on the session as the request's cookie found it, too: an owner whose session
490+ /// was confirmed only while the change waited for the lock is refused, so a
491+ /// cookie from before a confirmation never gains it. The account routes refuse
492+ /// such a request before it waits; this one calls the operation from a plain
493+ /// [`Owner`], as an in-process caller does.
481494#[ tokio:: test]
482495#[ ignore = "requires TEST_DATABASE_URL" ]
483496async fn a_confirmation_while_waiting_does_not_count ( ) {
484497 let database = Replicas :: database ( ) . await ;
485498 let owner = Browser :: new_account ( & database) . await ;
486499 let social =
487500 Browser :: sign_in_with ( & database, owner. user_id , AuthenticationMethod :: Federation ) . await ;
488- let routes = AccountApplication :: new ( database. clone ( ) ) . routes ( ) ;
501+ let routes = Router :: new ( )
502+ . route (
503+ passkey:: ITEM ,
504+ delete (
505+ |State ( database) : State < Database > , owner : Owner , Path ( id) : Path < PasskeyId > | async move {
506+ AccountService :: new ( database)
507+ . revoke_passkey ( & Subject :: from ( owner) , id)
508+ . await
509+ . map_err ( ApiError :: from)
510+ } ,
511+ ) ,
512+ )
513+ . with_state ( database. clone ( ) ) ;
489514 let mut confirmation = database. begin ( ) . await . expect ( "transaction" ) ;
490515 confirmation
491516 . users ( )
0 commit comments