@@ -192,6 +192,42 @@ async fn share_with_provisional_user() -> Result<(), Error> {
192192 Ok ( ( ) )
193193}
194194
195+ #[ tokio:: test( flavor = "multi_thread" ) ]
196+ async fn throws_if_identity_is_already_attached ( ) -> Result < ( ) , Error > {
197+ let app = TestApp :: get ( ) . await ;
198+
199+ let bob_email =
"[email protected] " . to_owned ( ) ; 200+ let bob_provisional = app. create_provisional_identity ( & bob_email) ;
201+
202+ let bob = app. start_anonymous ( & app. create_identity ( None ) ) . await ?;
203+ let attach_result = bob. attach_provisional_identity ( & bob_provisional) . await ?;
204+ assert_eq ! ( attach_result. status, Status :: IdentityVerificationNeeded ) ;
205+ assert_eq ! (
206+ attach_result. verification_method,
207+ Some ( VerificationMethod :: Email ( bob_email. clone( ) ) )
208+ ) ;
209+
210+ let verif = Verification :: Email {
211+ email : bob_email. clone ( ) ,
212+ verification_code : app. get_verification_code ( & bob_email) . await ?,
213+ } ;
214+ bob. verify_provisional_identity ( & verif) . await ?;
215+
216+ let alice = app. start_anonymous ( & app. create_identity ( None ) ) . await ?;
217+ let attach_result = alice. attach_provisional_identity ( & bob_provisional) . await ?;
218+ assert_eq ! ( attach_result. status, Status :: IdentityVerificationNeeded ) ;
219+ let verif = Verification :: Email {
220+ email : bob_email. clone ( ) ,
221+ verification_code : app. get_verification_code ( & bob_email) . await ?,
222+ } ;
223+ let err = alice. verify_provisional_identity ( & verif) . await . unwrap_err ( ) ;
224+ assert_eq ! ( err. code( ) , ErrorCode :: IdentityAlreadyAttached ) ;
225+
226+ bob. stop ( ) . await ?;
227+ alice. stop ( ) . await ?;
228+ Ok ( ( ) )
229+ }
230+
195231#[ tokio:: test( flavor = "multi_thread" ) ]
196232async fn attach_provisional_with_single_verif ( ) -> Result < ( ) , Error > {
197233 let message = b"Variable 'message' is never used" ;
0 commit comments