Added ownership and app existence validation to the user app secrets routes.
This commit is contained in:
@@ -138,6 +138,16 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
fn row() -> UserAppSecretRow {
|
||||
UserAppSecretRow {
|
||||
id: Uuid::new_v4(),
|
||||
app_id: Uuid::new_v4(),
|
||||
secret_hash: vec![0; 32],
|
||||
expires_at: Utc::now(),
|
||||
created_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
|
||||
fn foreign_key_violation(constraint: Constraint) -> DatabaseError {
|
||||
DatabaseError::ForeignKeyViolation {
|
||||
constraint,
|
||||
@@ -164,16 +174,6 @@ mod tests {
|
||||
assert!(matches!(error, RepositoryError::Database(_)));
|
||||
}
|
||||
|
||||
fn row() -> UserAppSecretRow {
|
||||
UserAppSecretRow {
|
||||
id: Uuid::new_v4(),
|
||||
app_id: Uuid::new_v4(),
|
||||
secret_hash: vec![7; 32],
|
||||
expires_at: Utc::now(),
|
||||
created_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn round_trips_through_rows() {
|
||||
let secret = decode(row()).unwrap();
|
||||
|
||||
@@ -58,6 +58,18 @@ where
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
pub async fn find_owner_by_id<'e, E>(
|
||||
executor: E,
|
||||
app_id: Uuid,
|
||||
) -> Result<Option<Uuid>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let owner = db::find_owner_by_id(executor, app_id).await?;
|
||||
|
||||
Ok(owner)
|
||||
}
|
||||
|
||||
pub async fn upsert<'e, E>(executor: E, app: UserApp) -> Result<Upsert<UserApp>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
|
||||
Reference in New Issue
Block a user