Skip to content

Commit

Permalink
Rename new_shamir to new_shamir_recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Oct 31, 2024
1 parent 38db9fc commit 4af3921
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 42 deletions.
2 changes: 1 addition & 1 deletion libparsec/crates/client/src/invite/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub async fn new_shamir_invitation(
send_email: bool,
claimer_user_id: UserID,
) -> Result<(InvitationToken, InvitationEmailSentStatus), NewDeviceInvitationError> {
use authenticated_cmds::latest::invite_new_shamir::{
use authenticated_cmds::latest::invite_new_shamir_recovery::{
InvitationEmailSentStatus as ApiInvitationEmailSentStatus, Rep, Req,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
4
],
"req": {
"cmd": "invite_new_shamir",
"cmd": "invite_new_shamir_recovery",
"fields": [
{
"name": "claimer_user_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ pub fn req() {
)
.as_ref();

let req = authenticated_cmds::invite_new_shamir::Req {
let req = authenticated_cmds::invite_new_shamir_recovery::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 expected = authenticated_cmds::AnyCmdReq::InviteNewShamirRecovery(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 {
let authenticated_cmds::AnyCmdReq::InviteNewShamirRecovery(data2) = data else {
unreachable!()
};
let raw2 = data2.dump().unwrap();
Expand All @@ -60,7 +60,7 @@ pub fn rep_ok() {
// since loading raw data should fail.
//
let raw = hex!("82a6737461747573a26f6ba5746f6b656ec410d864b93ded264aae9ae583fd3d40c45a");
let err = authenticated_cmds::invite_new_shamir::Rep::load(&raw).unwrap_err();
let err = authenticated_cmds::invite_new_shamir_recovery::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)
Expand All @@ -72,23 +72,24 @@ pub fn rep_ok() {
"83aa656d61696c5f73656e74a753554343455353a6737461747573a26f6ba5746f6b656ec4"
"10d864b93ded264aae9ae583fd3d40c45a"
);
let expected = authenticated_cmds::invite_new_shamir::Rep::Ok {
let expected = authenticated_cmds::invite_new_shamir_recovery::Rep::Ok {
token: InvitationToken::from_hex("d864b93ded264aae9ae583fd3d40c45a").unwrap(),
email_sent: authenticated_cmds::invite_new_shamir::InvitationEmailSentStatus::Success,
email_sent:
authenticated_cmds::invite_new_shamir_recovery::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();
fn rep_helper(raw: &[u8], expected: authenticated_cmds::invite_new_shamir_recovery::Rep) {
let data = authenticated_cmds::invite_new_shamir_recovery::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();
let data2 = authenticated_cmds::invite_new_shamir_recovery::Rep::load(&raw2).unwrap();

p_assert_eq!(data2, expected);
}
14 changes: 13 additions & 1 deletion libparsec/src/invite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,19 @@ pub async fn client_list_invitations(
token,
claimer_user_id,
} => {
todo!("{created_on} {status:?} {token} {claimer_user_id:?}")
let addr = ParsecInvitationAddr::new(
client.organization_addr(),
client.organization_id().to_owned(),
InvitationType::ShamirRecovery,
token,
);
InviteListItem::ShamirRecovery {
addr,
created_on,
status,
token,
claimer_user_id,
}
}
})
.collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from . import (
invite_greeter_step,
invite_list,
invite_new_device,
invite_new_shamir,
invite_new_shamir_recovery,
invite_new_user,
ping,
pki_enrollment_accept,
Expand Down Expand Up @@ -57,7 +57,7 @@ class AnyCmdReq:
| invite_greeter_step.Req
| invite_list.Req
| invite_new_device.Req
| invite_new_shamir.Req
| invite_new_shamir_recovery.Req
| invite_new_user.Req
| ping.Req
| pki_enrollment_accept.Req
Expand Down Expand Up @@ -94,7 +94,7 @@ __all__ = [
"invite_greeter_step",
"invite_list",
"invite_new_device",
"invite_new_shamir",
"invite_new_shamir_recovery",
"invite_new_user",
"ping",
"pki_enrollment_accept",
Expand Down
14 changes: 6 additions & 8 deletions server/parsec/components/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ async def api_invite_new_device(
async def api_invite_new_shamir_recovery(
self,
client_ctx: AuthenticatedClientContext,
req: authenticated_cmds.latest.invite_new_shamir.Req,
) -> authenticated_cmds.latest.invite_new_shamir.Rep:
req: authenticated_cmds.latest.invite_new_shamir_recovery.Req,
) -> authenticated_cmds.latest.invite_new_shamir_recovery.Rep:
outcome = await self.new_for_shamir_recovery(
now=DateTime.now(),
organization_id=client_ctx.organization_id,
Expand All @@ -828,17 +828,15 @@ async def api_invite_new_shamir_recovery(
)
match outcome:
case (InvitationToken() as token, None):
email_sent = (
authenticated_cmds.latest.invite_new_shamir.InvitationEmailSentStatus.SUCCESS
)
email_sent = authenticated_cmds.latest.invite_new_shamir_recovery.InvitationEmailSentStatus.SUCCESS
case (
InvitationToken() as token,
SendEmailBadOutcome.BAD_SMTP_CONFIG
| SendEmailBadOutcome.SERVER_UNAVAILABLE,
):
email_sent = authenticated_cmds.latest.invite_new_shamir.InvitationEmailSentStatus.SERVER_UNAVAILABLE
email_sent = authenticated_cmds.latest.invite_new_shamir_recovery.InvitationEmailSentStatus.SERVER_UNAVAILABLE
case (InvitationToken() as token, SendEmailBadOutcome.RECIPIENT_REFUSED):
email_sent = authenticated_cmds.latest.invite_new_shamir.InvitationEmailSentStatus.RECIPIENT_REFUSED
email_sent = authenticated_cmds.latest.invite_new_shamir_recovery.InvitationEmailSentStatus.RECIPIENT_REFUSED
case InviteNewForShamirBadOutcome.ORGANIZATION_NOT_FOUND:
client_ctx.organization_not_found_abort()
case InviteNewForShamirBadOutcome.ORGANIZATION_EXPIRED:
Expand All @@ -848,7 +846,7 @@ async def api_invite_new_shamir_recovery(
case InviteNewForShamirBadOutcome.AUTHOR_REVOKED:
client_ctx.author_revoked_abort()

return authenticated_cmds.latest.invite_new_shamir.RepOk(
return authenticated_cmds.latest.invite_new_shamir_recovery.RepOk(
token=token,
email_sent=email_sent,
)
Expand Down
30 changes: 15 additions & 15 deletions server/tests/api_v4/authenticated/test_invite_new_shamir.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ async def alice_shamir(backend: Backend, coolorg: CoolorgRpcClients, with_postgr


@pytest.mark.parametrize("send_email", (False, True))
async def test_authenticated_invite_new_shamir_ok_new(
async def test_authenticated_invite_new_shamir_recovery_ok_new(
send_email: bool, coolorg: CoolorgRpcClients, backend: Backend, alice_shamir: None
) -> None:
expected_invitations = await backend.invite.test_dump_all_invitations(coolorg.organization_id)

with backend.event_bus.spy() as spy:
rep = await coolorg.bob.invite_new_shamir(
rep = await coolorg.bob.invite_new_shamir_recovery(
send_email=send_email,
claimer_user_id=coolorg.alice.user_id,
)
assert isinstance(rep, authenticated_cmds.v4.invite_new_shamir.RepOk)
assert isinstance(rep, authenticated_cmds.v4.invite_new_shamir_recovery.RepOk)
assert (
rep.email_sent
== authenticated_cmds.v4.invite_new_shamir.InvitationEmailSentStatus.SUCCESS
== authenticated_cmds.v4.invite_new_shamir_recovery.InvitationEmailSentStatus.SUCCESS
)
invitation_token = rep.token

Expand Down Expand Up @@ -118,7 +118,7 @@ async def test_authenticated_invite_new_shamir_ok_new(
)


async def test_authenticated_invite_new_shamir_ok_already_exist(
async def test_authenticated_invite_new_shamir_recovery_ok_already_exist(
coolorg: CoolorgRpcClients, backend: Backend, alice_shamir: None
) -> None:
t1 = DateTime.now()
Expand All @@ -136,11 +136,11 @@ async def test_authenticated_invite_new_shamir_ok_already_exist(
expected_invitations = await backend.invite.test_dump_all_invitations(coolorg.organization_id)

with backend.event_bus.spy() as spy:
rep = await coolorg.bob.invite_new_shamir(
rep = await coolorg.bob.invite_new_shamir_recovery(
send_email=False,
claimer_user_id=coolorg.alice.user_id,
)
assert isinstance(rep, authenticated_cmds.v4.invite_new_shamir.RepOk)
assert isinstance(rep, authenticated_cmds.v4.invite_new_shamir_recovery.RepOk)
assert rep.token == invitation_token

await spy.wait_event_occurred(
Expand All @@ -166,7 +166,7 @@ async def test_authenticated_invite_new_shamir_ok_already_exist(
SendEmailBadOutcome.SERVER_UNAVAILABLE,
),
)
async def test_authenticated_invite_new_shamir_send_email_bad_outcome(
async def test_authenticated_invite_new_shamir_recovery_send_email_bad_outcome(
coolorg: CoolorgRpcClients,
backend: Backend,
bad_outcome: SendEmailBadOutcome,
Expand All @@ -181,19 +181,19 @@ async def _mocked_send_email(*args, **kwargs):
expected_invitations = await backend.invite.test_dump_all_invitations(coolorg.organization_id)

with backend.event_bus.spy() as spy:
rep = await coolorg.bob.invite_new_shamir(
rep = await coolorg.bob.invite_new_shamir_recovery(
send_email=True, claimer_user_id=coolorg.alice.user_id
)
assert isinstance(rep, authenticated_cmds.v4.invite_new_shamir.RepOk)
assert isinstance(rep, authenticated_cmds.v4.invite_new_shamir_recovery.RepOk)
invitation_token = rep.token

match bad_outcome:
case SendEmailBadOutcome.BAD_SMTP_CONFIG:
expected_email_sent_status = authenticated_cmds.v4.invite_new_shamir.InvitationEmailSentStatus.SERVER_UNAVAILABLE
expected_email_sent_status = authenticated_cmds.v4.invite_new_shamir_recovery.InvitationEmailSentStatus.SERVER_UNAVAILABLE
case SendEmailBadOutcome.RECIPIENT_REFUSED:
expected_email_sent_status = authenticated_cmds.v4.invite_new_shamir.InvitationEmailSentStatus.RECIPIENT_REFUSED
expected_email_sent_status = authenticated_cmds.v4.invite_new_shamir_recovery.InvitationEmailSentStatus.RECIPIENT_REFUSED
case SendEmailBadOutcome.SERVER_UNAVAILABLE:
expected_email_sent_status = authenticated_cmds.v4.invite_new_shamir.InvitationEmailSentStatus.SERVER_UNAVAILABLE
expected_email_sent_status = authenticated_cmds.v4.invite_new_shamir_recovery.InvitationEmailSentStatus.SERVER_UNAVAILABLE
assert rep.email_sent == expected_email_sent_status

await spy.wait_event_occurred(
Expand Down Expand Up @@ -235,11 +235,11 @@ async def _mocked_send_email(*args, **kwargs):
)


async def test_authenticated_invite_new_shamir_http_common_errors(
async def test_authenticated_invite_new_shamir_recovery_http_common_errors(
coolorg: CoolorgRpcClients, authenticated_http_common_errors_tester: HttpCommonErrorsTester
) -> None:
async def do():
await coolorg.alice.invite_new_shamir(
await coolorg.alice.invite_new_shamir_recovery(
send_email=False,
claimer_user_id=coolorg.bob.user_id,
)
Expand Down
8 changes: 4 additions & 4 deletions server/tests/common/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ async def invite_new_device(
raw_rep = await self._do_request(req.dump(), "authenticated")
return authenticated_cmds.latest.invite_new_device.Rep.load(raw_rep)

async def invite_new_shamir(
async def invite_new_shamir_recovery(
self, claimer_user_id: UserID, send_email: bool
) -> authenticated_cmds.latest.invite_new_shamir.Rep:
req = authenticated_cmds.latest.invite_new_shamir.Req(
) -> authenticated_cmds.latest.invite_new_shamir_recovery.Rep:
req = authenticated_cmds.latest.invite_new_shamir_recovery.Req(
claimer_user_id=claimer_user_id, send_email=send_email
)
raw_rep = await self._do_request(req.dump(), "authenticated")
return authenticated_cmds.latest.invite_new_shamir.Rep.load(raw_rep)
return authenticated_cmds.latest.invite_new_shamir_recovery.Rep.load(raw_rep)

async def invite_new_user(
self, claimer_email: str, send_email: bool
Expand Down

0 comments on commit 4af3921

Please sign in to comment.