@@ -7146,6 +7146,102 @@ mod postgres_tests {
71467146 assert_eq ! ( stored. channel_id, Some ( channels[ 0 ] ) ) ;
71477147 }
71487148
7149+ #[ tokio:: test]
7150+ #[ ignore = "requires Postgres" ]
7151+ async fn subject_cannot_delete_relay_verified_profile ( ) {
7152+ use buzz_core:: kind:: KIND_VERIFIED_PROFILE ;
7153+ use buzz_db:: verified_profiles:: ProfileAdmission ;
7154+ use nostr:: Tag ;
7155+ let f = ScopedTargetFixture :: new ( "verified-profile-deletion" ) . await ;
7156+ let subject = f. author . public_key ( ) . to_hex ( ) ;
7157+ let now = Utc :: now ( ) ;
7158+ let profile = f
7159+ . state
7160+ . db
7161+ . publish_verified_profile (
7162+ ProfileAdmission {
7163+ community : f. tenant . community ( ) ,
7164+ issuer : "https://issuer.test" ,
7165+ pubkey : & subject,
7166+ issued_at : now,
7167+ admitted_at : now,
7168+ display_name : "Alice" ,
7169+ username : "alice" ,
7170+ full_name : Some ( "Alice Example" ) ,
7171+ label : "Example" ,
7172+ refresh_seconds : 3600 ,
7173+ membership_required : false ,
7174+ } ,
7175+ & f. state . relay_keypair ,
7176+ )
7177+ . await
7178+ . unwrap ( )
7179+ . expect ( "publish relay-owned profile" ) ;
7180+ let auth = || IngestAuth :: Http {
7181+ pubkey : f. author . public_key ( ) ,
7182+ scopes : vec ! [ Scope :: MessagesWrite ] ,
7183+ auth_method : HttpAuthMethod :: Nip98 ,
7184+ } ;
7185+ let deletion = |tag : Tag | {
7186+ EventBuilder :: new ( Kind :: Custom ( KIND_DELETION as u16 ) , "" )
7187+ . tags ( [ tag] )
7188+ . sign_with_keys ( & f. author )
7189+ . unwrap ( )
7190+ } ;
7191+ let coordinate = |author : String | {
7192+ Tag :: parse ( [
7193+ "a" . to_owned ( ) ,
7194+ format ! ( "{KIND_VERIFIED_PROFILE}:{author}:{subject}" ) ,
7195+ ] )
7196+ . unwrap ( )
7197+ } ;
7198+ for tag in [
7199+ Tag :: parse ( [ "e" , & profile. id . to_hex ( ) ] ) . unwrap ( ) ,
7200+ coordinate ( profile. pubkey . to_hex ( ) ) ,
7201+ // Even a subject-authored coordinate cannot request deletion of this kind.
7202+ coordinate ( subject. clone ( ) ) ,
7203+ ] {
7204+ let event = deletion ( tag) ;
7205+ let id = event. id ;
7206+ let result = f. submit ( event, auth ( ) ) . await ;
7207+ assert ! (
7208+ matches!( & result, Err ( IngestError :: Rejected ( message) )
7209+ if message == "invalid: deletion target not found or not deletable by you" ) ,
7210+ "profile deletion must be denied, got {:?}" ,
7211+ result. err( )
7212+ ) ;
7213+ assert ! ( f
7214+ . state
7215+ . db
7216+ . get_event_by_id( f. tenant. community( ) , id. as_bytes( ) )
7217+ . await
7218+ . unwrap( )
7219+ . is_none( ) ) ;
7220+ let stored = f
7221+ . state
7222+ . db
7223+ . get_event_by_id ( f. tenant . community ( ) , profile. id . as_bytes ( ) )
7224+ . await
7225+ . unwrap ( )
7226+ . expect ( "profile remains readable" ) ;
7227+ assert_eq ! ( stored. event, profile) ;
7228+ }
7229+
7230+ f. submit (
7231+ deletion ( Tag :: parse ( [ "e" , & f. global . id . to_hex ( ) ] ) . unwrap ( ) ) ,
7232+ auth ( ) ,
7233+ )
7234+ . await
7235+ . expect ( "ordinary author-owned note remains deletable" ) ;
7236+ assert ! ( f
7237+ . state
7238+ . db
7239+ . get_event_by_id( f. tenant. community( ) , f. global. id. as_bytes( ) )
7240+ . await
7241+ . unwrap( )
7242+ . is_none( ) ) ;
7243+ }
7244+
71497245 /// A community with `author`'s live message in an open channel, an
71507246 /// author global note, and a second open channel for out-of-scope tokens.
71517247 struct ScopedTargetFixture {
0 commit comments