-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: update provider database #5966
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,7 +6,6 @@ use anyhow::{Context as _, Result}; | |
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; | ||
use serde::Deserialize; | ||
|
||
use crate::config::Config; | ||
use crate::context::Context; | ||
use crate::net::http::post_form; | ||
use crate::net::read_url_blob; | ||
|
@@ -62,8 +61,7 @@ pub async fn get_oauth2_url( | |
addr: &str, | ||
redirect_uri: &str, | ||
) -> Result<Option<String>> { | ||
let proxy_enabled = context.get_config_bool(Config::ProxyEnabled).await?; | ||
if let Some(oauth2) = Oauth2::from_address(context, addr, proxy_enabled).await { | ||
if let Some(oauth2) = Oauth2::from_address(context, addr).await { | ||
context | ||
.sql | ||
.set_raw_config("oauth2_pending_redirect_uri", Some(redirect_uri)) | ||
|
@@ -83,8 +81,7 @@ pub(crate) async fn get_oauth2_access_token( | |
code: &str, | ||
regenerate: bool, | ||
) -> Result<Option<String>> { | ||
let proxy_enabled = context.get_config_bool(Config::ProxyEnabled).await?; | ||
if let Some(oauth2) = Oauth2::from_address(context, addr, proxy_enabled).await { | ||
if let Some(oauth2) = Oauth2::from_address(context, addr).await { | ||
let lock = context.oauth2_mutex.lock().await; | ||
|
||
// read generated token | ||
|
@@ -232,8 +229,7 @@ pub(crate) async fn get_oauth2_addr( | |
addr: &str, | ||
code: &str, | ||
) -> Result<Option<String>> { | ||
let proxy_enabled = context.get_config_bool(Config::ProxyEnabled).await?; | ||
let oauth2 = match Oauth2::from_address(context, addr, proxy_enabled).await { | ||
let oauth2 = match Oauth2::from_address(context, addr).await { | ||
Some(o) => o, | ||
None => return Ok(None), | ||
}; | ||
|
@@ -268,8 +264,9 @@ pub(crate) async fn get_oauth2_addr( | |
} | ||
|
||
impl Oauth2 { | ||
async fn from_address(context: &Context, addr: &str, skip_mx: bool) -> Option<Self> { | ||
async fn from_address(context: &Context, addr: &str) -> Option<Self> { | ||
let addr_normalized = normalize_addr(addr); | ||
let skip_mx = true; | ||
if let Some(domain) = addr_normalized | ||
.find('@') | ||
.map(|index| addr_normalized.split_at(index + 1).1) | ||
|
@@ -367,38 +364,20 @@ mod tests { | |
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_oauth_from_address() { | ||
let t = TestContext::new().await; | ||
|
||
// Delta Chat does not have working Gmail client ID anymore. | ||
assert_eq!(Oauth2::from_address(&t, "[email protected]").await, None); | ||
assert_eq!(Oauth2::from_address(&t, "[email protected]").await, None); | ||
|
||
assert_eq!( | ||
Oauth2::from_address(&t, "[email protected]", false).await, | ||
Some(OAUTH2_GMAIL) | ||
); | ||
assert_eq!( | ||
Oauth2::from_address(&t, "[email protected]", false).await, | ||
Some(OAUTH2_GMAIL) | ||
); | ||
assert_eq!( | ||
Oauth2::from_address(&t, "[email protected]", false).await, | ||
Oauth2::from_address(&t, "[email protected]").await, | ||
Some(OAUTH2_YANDEX) | ||
); | ||
assert_eq!( | ||
Oauth2::from_address(&t, "[email protected]", false).await, | ||
Oauth2::from_address(&t, "[email protected]").await, | ||
Some(OAUTH2_YANDEX) | ||
); | ||
assert_eq!(Oauth2::from_address(&t, "[email protected]", false).await, None); | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_oauth_from_mx() { | ||
// youtube staff seems to use "google workspace with oauth2", figures this out by MX lookup | ||
let t = TestContext::new().await; | ||
assert_eq!( | ||
Oauth2::from_address(&t, "[email protected]", false).await, | ||
Some(OAUTH2_GMAIL) | ||
); | ||
// without MX lookup, we would not know as youtube.com is not in our provider-db | ||
assert_eq!( | ||
Oauth2::from_address(&t, "[email protected]", true).await, | ||
None | ||
); | ||
assert_eq!(Oauth2::from_address(&t, "[email protected]").await, None); | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
|
@@ -414,11 +393,11 @@ mod tests { | |
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_get_oauth2_url() { | ||
let ctx = TestContext::new().await; | ||
let addr = "dignifiedquire@gmail.com"; | ||
let addr = "example@yandex.com"; | ||
let redirect_uri = "chat.delta:/com.b44t.messenger"; | ||
let res = get_oauth2_url(&ctx.ctx, addr, redirect_uri).await.unwrap(); | ||
|
||
assert_eq!(res, Some("https://accounts.google.com/o/oauth2/auth?client_id=959970109878%2D4mvtgf6feshskf7695nfln6002mom908%2Eapps%2Egoogleusercontent%2Ecom&redirect_uri=chat%2Edelta%3A%2Fcom%2Eb44t%2Emessenger&response_type=code&scope=https%3A%2F%2Fmail.google.com%2F%20email&access_type=offline".into())); | ||
assert_eq!(res, Some("https://oauth.yandex.com/authorize?client_id=c4d0b6735fc8420a816d7e1303469341&response_type=code&scope=mail%3Aimap_full%20mail%3Asmtp&force_confirm=true".into())); | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure MX lookup will be never needed for yandex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we support it, we can enable it and test. I think Yandex has something like Google Workspace already but doubt we want to support it, especially since Yandex is unusable anyway due to strict rate limits and requests to solve captcha on the web when you hit the limit.