Skip to content

Commit 07dc400

Browse files
committed
refactor(auth): invitation links can't fail either, as the link keys they build on
Main's invitations arrived with link keys that returned a Result for HMAC, which aws-lc-rs can't fail.
1 parent 5132482 commit 07dc400

4 files changed

Lines changed: 8 additions & 16 deletions

File tree

‎apps/auth-service/src/admin/service/access.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl AdminService {
5454
EmailApplication::sendable(email).map_err(AdminError::InvitationUnsendable)?;
5555
}
5656
let id = TokenId::new();
57-
let token = links.token(id)?;
57+
let token = links.token(id);
5858
let expires_at = Utc::now() + expires_in.duration();
5959
let mut tx = self.database.begin().await?;
6060
if let Some(email) = &email {

‎apps/auth-service/src/admin/tests/invitations.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async fn revoked_invitations_cannot_be_redeemed() {
131131
panic!("a link to pass on: {created:?}");
132132
};
133133
assert_eq!(url.path(), crate::routes::page::REGISTER);
134-
let digest = links.token(created.id).expect("token").digest();
134+
let digest = links.token(created.id).digest();
135135
let open = || async {
136136
harness
137137
.database
@@ -182,7 +182,7 @@ async fn invitation_revocation_waits_for_signup() {
182182
)
183183
.await
184184
.expect("invitation");
185-
let digest = links.token(invitation.id).expect("token").digest();
185+
let digest = links.token(invitation.id).digest();
186186
let mut signup = harness.database.begin().await.expect("transaction");
187187
assert!(
188188
signup

‎apps/auth-service/src/deliveries/email/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ async fn an_invitation_is_mailed_while_it_is_open() {
424424
let sender =
425425
EmailSender::with_mailer(database.clone(), Some(Arc::new(Outbox::default())), &config);
426426
let id = TokenId::new();
427-
let token = config.invitation_links.token(id).expect("token");
427+
let token = config.invitation_links.token(id);
428428
let address = format!("{id}@example.com");
429429
database
430430
.security()

‎apps/auth-service/src/invitations.rs‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
use crate::{config::LinkKeys, routes};
1515
use sourceorigin_common::{TokenId, config::Origin};
16-
use sourceorigin_crypto::{CryptoError, Secret};
16+
use sourceorigin_crypto::Secret;
1717
use url::Url;
1818

1919
/// Derives invitation links' tokens from invitations' IDs, with keys derived
@@ -36,24 +36,16 @@ impl InvitationLinks {
3636
}
3737

3838
/// The token of a new invitation `id`'s link, under the current key.
39-
///
40-
/// # Errors
41-
///
42-
/// Returns [`CryptoError`] if the HMAC provider fails.
43-
pub(crate) fn token(&self, id: TokenId) -> Result<Secret, CryptoError> {
39+
pub(crate) fn token(&self, id: TokenId) -> Secret {
4440
self.keys.token(id.as_uuid().as_bytes())
4541
}
4642

4743
/// Invitation `id`'s link, as [`Self::url`] builds it, under the key whose
4844
/// token has the stored SHA-256 `digest`. `None` once no configured key
4945
/// derives it, which fails its delivery.
50-
///
51-
/// # Errors
52-
///
53-
/// Returns [`CryptoError`] if the HMAC provider fails.
54-
pub(crate) fn link(&self, id: TokenId, digest: &[u8]) -> Result<Option<Url>, CryptoError> {
46+
pub(crate) fn link(&self, id: TokenId, digest: &[u8]) -> Option<Url> {
5547
let token = self.keys.rebuild(id.as_uuid().as_bytes(), digest)?;
56-
Ok(token.map(|token| self.url(&token)))
48+
Some(self.url(&token))
5749
}
5850

5951
/// The link holding `token`: the registration page, with the token in its

0 commit comments

Comments
 (0)