Skip to content

Commit a447504

Browse files
committed
fix: test & lint
1 parent 231ac62 commit a447504

43 files changed

Lines changed: 456 additions & 518 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/backend/native/src/auth_session.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ pub(crate) fn sign_auth_session_access_token(
111111
serde_json::to_vec(&AccessTokenHeader {
112112
alg: "HS256",
113113
typ: "JWT",
114-
kid: &key_id,
114+
kid: key_id,
115115
})
116116
.map_err(|_| "access_token_encode_failed")?,
117117
);
118118
let claims = URL_SAFE_NO_PAD.encode(
119119
serde_json::to_vec(&AccessTokenClaims {
120-
sub: &user_id,
121-
sid: &auth_session_id,
120+
sub: user_id,
121+
sid: auth_session_id,
122122
typ: ACCESS_TOKEN_TYPE,
123123
iss: ACCESS_TOKEN_ISSUER,
124124
aud: ACCESS_TOKEN_AUDIENCE,

packages/backend/native/src/runtime/backend_runtime/auth_session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mod types;
1717

1818
use serde_json::Value;
1919
use session::{decision_time, lock_refresh_tokens, lock_user};
20-
use types::{AuthSessionCommand, PrincipalInput};
20+
use types::{AuthSessionCommand, PrincipalInput, TokenPairSession};
2121

2222
use super::{BackendRuntime, RuntimeError, RuntimeResult, to_napi_error};
2323

packages/backend/native/src/runtime/backend_runtime/auth_session/principal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async fn access_token(
105105
user_session_expires_at: row.expires_at,
106106
}) {
107107
SessionState::Active => Ok(PrincipalResult::Valid {
108-
principal: row.into_principal(Some(auth_session_id)),
108+
principal: Box::new(row.into_principal(Some(auth_session_id))),
109109
refreshed_expires_at: None,
110110
}),
111111
SessionState::Expired => Ok(PrincipalResult::AuthSessionExpired),
@@ -184,7 +184,7 @@ async fn cookie(
184184
.await
185185
.map_err(|error| RuntimeError::database("commit cookie principal", error))?;
186186
Ok(PrincipalResult::Valid {
187-
principal: row.into_principal(None),
187+
principal: Box::new(row.into_principal(None)),
188188
refreshed_expires_at,
189189
})
190190
}

packages/backend/native/src/runtime/backend_runtime/auth_session/refresh.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use sqlx::{PgPool, Row};
66
use subtle::ConstantTimeEq;
77

88
use super::{
9-
RuntimeError, RuntimeResult,
9+
RuntimeError, RuntimeResult, TokenPairSession,
1010
session::{decision_time, lock_refresh_tokens, lock_user, lock_user_session, token_pair},
1111
successor::SuccessorKey,
1212
types::RefreshResult,
@@ -164,11 +164,12 @@ pub(super) async fn refresh(
164164
&mut tx,
165165
config,
166166
&row.user_id,
167-
&row.auth_session_id,
168167
candidate,
169168
refresh_expires_at,
170-
row.absolute_expires_at,
171-
None,
169+
TokenPairSession {
170+
id: row.auth_session_id.clone(),
171+
absolute_expires_at: row.absolute_expires_at,
172+
},
172173
now,
173174
)
174175
.await?;
@@ -216,15 +217,16 @@ pub(super) async fn refresh(
216217
&mut tx,
217218
config,
218219
&row.user_id,
219-
&row.auth_session_id,
220220
crate::auth_session::AuthSessionRefreshToken {
221221
token,
222222
id: replacement.id,
223223
secret_hash: replacement.secret_hash,
224224
},
225225
replacement.expires_at,
226-
row.absolute_expires_at,
227-
None,
226+
TokenPairSession {
227+
id: row.auth_session_id.clone(),
228+
absolute_expires_at: row.absolute_expires_at,
229+
},
228230
now,
229231
)
230232
.await?;

packages/backend/native/src/runtime/backend_runtime/auth_session/session.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,20 @@ pub(super) async fn exchange(
150150
.execute(&mut *tx)
151151
.await
152152
.map_err(|error| RuntimeError::database("consume auth session exchange", error))?;
153-
let pair = token_pair(
153+
let mut pair = token_pair(
154154
&mut tx,
155155
config,
156156
&user_id,
157-
&auth_session_id,
158157
refresh,
159158
idle_expires_at,
160-
absolute_expires_at,
161-
Some(is_new_device),
159+
TokenPairSession {
160+
id: auth_session_id,
161+
absolute_expires_at,
162+
},
162163
now,
163164
)
164165
.await?;
166+
pair.is_new_device = Some(is_new_device);
165167
tx.commit()
166168
.await
167169
.map_err(|error| RuntimeError::database("commit auth session exchange", error))?;
@@ -172,18 +174,16 @@ pub(super) async fn token_pair(
172174
connection: &mut PgConnection,
173175
config: &super::super::BackendRuntimeConfig,
174176
user_id: &str,
175-
auth_session_id: &str,
176177
refresh: AuthSessionRefreshToken,
177178
refresh_expires_at: DateTime<Utc>,
178-
absolute_expires_at: DateTime<Utc>,
179-
is_new_device: Option<bool>,
179+
session: TokenPairSession,
180180
now: DateTime<Utc>,
181181
) -> RuntimeResult<TokenPair> {
182182
let signing_key = keyring::active(connection, config).await?;
183183
let expires_at = access_token_deadline(now, config.auth.access_token_ttl_seconds);
184184
let access_token = sign_auth_session_access_token(
185185
user_id,
186-
auth_session_id,
186+
&session.id,
187187
&signing_key.id,
188188
&signing_key.secret,
189189
now.timestamp(),
@@ -197,11 +197,8 @@ pub(super) async fn token_pair(
197197
expires_in: config.auth.access_token_ttl_seconds,
198198
refresh_token: refresh.token,
199199
refresh_expires_at,
200-
session: TokenPairSession {
201-
id: auth_session_id.to_string(),
202-
absolute_expires_at,
203-
},
204-
is_new_device,
200+
session,
201+
is_new_device: None,
205202
})
206203
}
207204

packages/backend/native/src/runtime/backend_runtime/auth_session/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub(super) struct Principal {
298298
#[serde(tag = "status", rename_all = "snake_case")]
299299
pub(super) enum PrincipalResult {
300300
Valid {
301-
principal: Principal,
301+
principal: Box<Principal>,
302302
#[serde(rename = "refreshedExpiresAt")]
303303
refreshed_expires_at: Option<DateTime<Utc>>,
304304
},

packages/backend/native/src/runtime/backend_runtime/doc_writer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ async fn append_authorized_updates(
122122
&input.workspace_id,
123123
Some(permission_doc_id),
124124
&command,
125-
deployment,
126125
)
127126
.await
128127
.map_err(super::to_napi_error)?;
@@ -147,7 +146,6 @@ async fn append_authorized_updates(
147146
&input.workspace_id,
148147
None,
149148
&DomainCommand::CreateDoc,
150-
deployment,
151149
)
152150
.await
153151
.map_err(super::to_napi_error)?;

0 commit comments

Comments
 (0)