feat: implement delete_oauth_state for postgres adapter
This commit is contained in:
parent
c277c7af9a
commit
d72361e36f
66
src/auth/adapter/out/db/postgres/delete_oauth_state.rs
Normal file
66
src/auth/adapter/out/db/postgres/delete_oauth_state.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
use url::Url;
|
||||
|
||||
use super::DBOutPostgresAdapter;
|
||||
use crate::auth::application::port::out::db::{
|
||||
delete_oauth_state::DeleteOAuthState, errors::OutDBPortResult,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl DeleteOAuthState for DBOutPostgresAdapter {
|
||||
async fn delete_oauth_state(&self, state: &str, oauth_provider: &str) -> OutDBPortResult<()> {
|
||||
sqlx::query!(
|
||||
"DELETE FROM
|
||||
oauth_state
|
||||
WHERE
|
||||
state = $1
|
||||
AND
|
||||
oauth_provider = $2;",
|
||||
state,
|
||||
oauth_provider,
|
||||
)
|
||||
.execute(&self.pool)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::auth::application::port::out::db::oauth_state_exists::OAuthStateExists;
|
||||
use crate::auth::application::port::out::db::save_oauth_state::SaveOAuthState;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_postgres_delete_oauth_state() {
|
||||
let state = "delete_oauth_state";
|
||||
let oauth_provider = "oauthprovitestpostgres";
|
||||
let redirect_uri = Url::parse("https://oauthprovitestpostgres").unwrap();
|
||||
|
||||
let settings = crate::settings::tests::get_settings().await;
|
||||
|
||||
let db = super::DBOutPostgresAdapter::new(
|
||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
// create state
|
||||
db.save_oauth_state(state, oauth_provider, &redirect_uri)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// delete state
|
||||
db.delete_oauth_state(state, oauth_provider).await.unwrap();
|
||||
|
||||
// check state doesn't exist
|
||||
assert!(!db
|
||||
.oauth_state_exists(state, oauth_provider, &redirect_uri)
|
||||
.await
|
||||
.unwrap());
|
||||
|
||||
// try to delete non-existent state; should succeed.
|
||||
db.delete_oauth_state(state, oauth_provider).await.unwrap();
|
||||
|
||||
settings.drop_db().await;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue