forked from AppFlowy-IO/AppFlowy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: sign in url test (AppFlowy-IO#75)
* test: sign in url test * fix: Tungstenite allows remote attackers to cause a denial of service * chore: enable feature * chore: update
- Loading branch information
Showing
13 changed files
with
90 additions
and
140 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::Client; | ||
use gotrue::grant::{Grant, PasswordGrant}; | ||
use gotrue::params::GenerateLinkParams; | ||
use gotrue_entity::GoTrueError; | ||
use scraper::{Html, Selector}; | ||
|
||
impl Client { | ||
pub async fn generate_sign_in_url( | ||
&self, | ||
admin_user_email: &str, | ||
admin_user_password: &str, | ||
user_email: &str, | ||
) -> Result<String, GoTrueError> { | ||
let admin_token = self | ||
.gotrue_client | ||
.token(&Grant::Password(PasswordGrant { | ||
email: admin_user_email.to_string(), | ||
password: admin_user_password.to_string(), | ||
})) | ||
.await?; | ||
|
||
let admin_user_params: GenerateLinkParams = GenerateLinkParams { | ||
email: user_email.to_string(), | ||
..Default::default() | ||
}; | ||
|
||
let link_resp = self | ||
.gotrue_client | ||
.generate_link(&admin_token.access_token, &admin_user_params) | ||
.await?; | ||
assert_eq!(link_resp.email, user_email); | ||
|
||
let action_link = link_resp.action_link; | ||
let resp = reqwest::Client::new().get(action_link).send().await?; | ||
let resp_text = resp.text().await?; | ||
Ok(extract_appflowy_sign_in_url(&resp_text)) | ||
} | ||
} | ||
|
||
pub fn extract_appflowy_sign_in_url(html_str: &str) -> String { | ||
let fragment = Html::parse_fragment(html_str); | ||
let selector = Selector::parse("a").unwrap(); | ||
fragment | ||
.select(&selector) | ||
.next() | ||
.unwrap() | ||
.value() | ||
.attr("href") | ||
.unwrap() | ||
.to_string() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
mod http; | ||
|
||
#[cfg(feature = "client-api-test")] | ||
pub mod http_test; | ||
|
||
pub mod notify; | ||
pub mod ws; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters