-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
638 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
libparsec/crates/protocol/schema/authenticated_cmds/invite_new_shamir.json5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[ | ||
{ | ||
"major_versions": [ | ||
4 | ||
], | ||
"req": { | ||
"cmd": "invite_new_shamir", | ||
"fields": [ | ||
{ | ||
"name": "claimer_user_id", | ||
"type": "UserID" | ||
}, | ||
{ | ||
"name": "send_email", | ||
"type": "Boolean" | ||
} | ||
] | ||
}, | ||
"reps": [ | ||
{ | ||
"status": "ok", | ||
"fields": [ | ||
{ | ||
"name": "token", | ||
"type": "InvitationToken" | ||
}, | ||
// Field used when the invitation is correctly created but the invitation email cannot be sent | ||
{ | ||
"name": "email_sent", | ||
"type": "InvitationEmailSentStatus" | ||
} | ||
] | ||
} | ||
], | ||
"nested_types": [ | ||
{ | ||
"name": "InvitationEmailSentStatus", | ||
"variants": [ | ||
{ | ||
// Also returned when `send_email=false` | ||
"name": "Success", | ||
"discriminant_value": "SUCCESS" | ||
}, | ||
{ | ||
"name": "ServerUnavailable", | ||
"discriminant_value": "SERVER_UNAVAILABLE" | ||
}, | ||
{ | ||
"name": "RecipientRefused", | ||
"discriminant_value": "RECIPIENT_REFUSED" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
libparsec/crates/protocol/tests/authenticated_cmds/v4/invite_new_shamir.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS | ||
|
||
// `allow-unwrap-in-test` don't behave as expected, see: | ||
// https://github.com/rust-lang/rust-clippy/issues/11119 | ||
#![allow(clippy::unwrap_used)] | ||
|
||
use super::authenticated_cmds; | ||
|
||
use libparsec_tests_lite::{hex, p_assert_eq}; | ||
use libparsec_types::InvitationToken; | ||
use libparsec_types::UserID; | ||
|
||
// Request | ||
|
||
pub fn req() { | ||
// Generated from Parsec 3.1.1-a.0+dev | ||
// Content: | ||
// cmd: 'invite_new_shamir' | ||
// claimer_user_id: ext(2, 0x109b68ba5cdf428ea0017fc6bcc04d4a) | ||
// send_email: True | ||
let raw: &[u8] = hex!( | ||
"83a3636d64b1696e766974655f6e65775f7368616d6972af636c61696d65725f757365" | ||
"725f6964d802109b68ba5cdf428ea0017fc6bcc04d4aaa73656e645f656d61696cc3" | ||
) | ||
.as_ref(); | ||
|
||
let req = authenticated_cmds::invite_new_shamir::Req { | ||
send_email: true, | ||
claimer_user_id: UserID::from_hex("109b68ba5cdf428ea0017fc6bcc04d4a").unwrap(), | ||
}; | ||
println!("***expected: {:?}", req.dump().unwrap()); | ||
|
||
let expected = authenticated_cmds::AnyCmdReq::InviteNewShamir(req); | ||
let data = authenticated_cmds::AnyCmdReq::load(raw).unwrap(); | ||
|
||
p_assert_eq!(data, expected); | ||
|
||
// Also test serialization round trip | ||
let authenticated_cmds::AnyCmdReq::InviteNewShamir(data2) = data else { | ||
unreachable!() | ||
}; | ||
let raw2 = data2.dump().unwrap(); | ||
|
||
let data2 = authenticated_cmds::AnyCmdReq::load(&raw2).unwrap(); | ||
|
||
p_assert_eq!(data2, expected); | ||
} | ||
|
||
// Responses | ||
|
||
pub fn rep_ok() { | ||
// Generated from Rust implementation (Parsec v3.0.0-b.6+dev 2024-03-29) | ||
// Content: | ||
// status: "ok" | ||
// token: ext(2, hex!("d864b93ded264aae9ae583fd3d40c45a")) | ||
// | ||
// Note that raw data does not contain "email_sent". | ||
// This was valid behavior in api v2 but is no longer valid from v3 onwards. | ||
// The corresponding expected values used here are therefore not important | ||
// since loading raw data should fail. | ||
// | ||
let raw = hex!("82a6737461747573a26f6ba5746f6b656ec410d864b93ded264aae9ae583fd3d40c45a"); | ||
let err = authenticated_cmds::invite_new_shamir::Rep::load(&raw).unwrap_err(); | ||
p_assert_eq!(err.to_string(), "missing field `email_sent`"); | ||
|
||
// Generated from Python implementation (Parsec v3.0.0-b.6+dev 2024-03-29) | ||
// Content: | ||
// email_sent: "SUCCESS" | ||
// status: "ok" | ||
// token: ext(2, hex!("d864b93ded264aae9ae583fd3d40c45a")) | ||
let raw = hex!( | ||
"83aa656d61696c5f73656e74a753554343455353a6737461747573a26f6ba5746f6b656ec4" | ||
"10d864b93ded264aae9ae583fd3d40c45a" | ||
); | ||
let expected = authenticated_cmds::invite_new_shamir::Rep::Ok { | ||
token: InvitationToken::from_hex("d864b93ded264aae9ae583fd3d40c45a").unwrap(), | ||
email_sent: authenticated_cmds::invite_new_shamir::InvitationEmailSentStatus::Success, | ||
}; | ||
|
||
rep_helper(&raw, expected); | ||
} | ||
|
||
fn rep_helper(raw: &[u8], expected: authenticated_cmds::invite_new_shamir::Rep) { | ||
let data = authenticated_cmds::invite_new_shamir::Rep::load(raw).unwrap(); | ||
|
||
p_assert_eq!(data, expected); | ||
|
||
// Also test serialization round trip | ||
let raw2 = data.dump().unwrap(); | ||
|
||
let data2 = authenticated_cmds::invite_new_shamir::Rep::load(&raw2).unwrap(); | ||
|
||
p_assert_eq!(data2, expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.