Skip to content

Commit 0b06c3a

Browse files
author
Alexandre BOSSARD
committed
Merge branch 'ab/always_attach' into 'master'
fix: Add new error IdentityAlreadyAttached See merge request TankerHQ/sdk-rust!35
2 parents 113c33a + 5688dc3 commit 0b06c3a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pub enum ErrorCode {
3636
Conflict = 13,
3737
/// A new version of the SDK is required to perform the requested action
3838
UpgradeRequired = 14,
39+
/// A provisional identity has already been attached
40+
IdentityAlreadyAttached = 15,
3941

4042
#[num_enum(default)]
4143
UnknownError = u32::max_value(),
@@ -109,6 +111,7 @@ impl From<Error> for futures::io::Error {
109111
| ErrorCode::TooManyAttempts
110112
| ErrorCode::Conflict
111113
| ErrorCode::UpgradeRequired
114+
| ErrorCode::IdentityAlreadyAttached
112115
| ErrorCode::UnknownError => ErrorKind::Other,
113116
};
114117
futures::io::Error::new(kind, e)

tests/tanker_tests.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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")]
196232
async fn attach_provisional_with_single_verif() -> Result<(), Error> {
197233
let message = b"Variable 'message' is never used";

0 commit comments

Comments
 (0)