-
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.
- Loading branch information
1 parent
01ab322
commit c6b709b
Showing
9 changed files
with
144 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members=[ | ||
"reginleif", | ||
"reginleif-test", | ||
"reginleif-utils", | ||
"reginleif-macro" | ||
] | ||
|
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 @@ | ||
mod auth; |
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,75 @@ | ||
|
||
#[cfg(test)] | ||
mod test{ | ||
use std::time::Duration; | ||
use reginleif::auth::account::Account; | ||
use reginleif::auth::microsoft::{DeviceCode, MicrosoftAuthError}; | ||
use reginleif::auth::minecraft::{MinecraftAuth, Profile}; | ||
use reginleif::auth::xbox::{XboxLiveToken, XboxSecurityToken}; | ||
use reginleif_utils::expiring_data::ExpiringData; | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
async fn test_auth_token(){ | ||
|
||
let client = reqwest::Client::new(); | ||
let client_id = "47f3e635-2886-4628-a1c2-fd8a9f4d7a5f"; | ||
let res = DeviceCode::fetch(&client,client_id).await; | ||
|
||
let device_code = match res{ | ||
Ok(device_code) => { | ||
println!("auth url: {}",device_code.verification_uri); | ||
println!("user code: {}",device_code.user_code); | ||
device_code | ||
} | ||
Err(e) => { | ||
panic!("Error: {}",e); // error while fetching token. | ||
} | ||
}; | ||
|
||
|
||
let mut res = loop{ | ||
let result = device_code.exchange(&client,client_id).await; | ||
let res = match result{ | ||
Ok(res) => {res} | ||
Err(e) => { | ||
match e { | ||
MicrosoftAuthError::AuthorizationPending => { | ||
tokio::time::sleep(device_code.interval).await; | ||
continue; | ||
} | ||
_=> {panic!("Error: {}",e);} | ||
} | ||
} | ||
}; | ||
break res; | ||
}; | ||
|
||
println!("{:?}",res); | ||
|
||
let cloned = res.clone(); | ||
|
||
let xbox_live_token = XboxLiveToken::fetch(&client,&res.data.access_token).await.unwrap(); | ||
println!("{:?}",xbox_live_token); | ||
let xbox_security_token = XboxSecurityToken::fetch(&client,xbox_live_token).await.unwrap(); | ||
println!("{:?}",xbox_security_token); | ||
|
||
let minecraft_auth = MinecraftAuth::fetch(&client,xbox_security_token).await.unwrap(); | ||
println!("{:?}",minecraft_auth); | ||
let profile = Profile::fetch(&client,&minecraft_auth).await.unwrap(); | ||
println!("{:?}",profile); | ||
|
||
let account:Account = (minecraft_auth,profile,res.clone()).into(); | ||
let mut account: ExpiringData<Account> = account.into(); | ||
account.refresh(&client_id.to_string()).await.unwrap(); | ||
println!("{:?}",account); | ||
|
||
tokio::time::sleep(Duration::from_secs(2)).await; | ||
res.refresh(&(client,client_id.to_string())).await.unwrap(); | ||
|
||
assert_ne!(cloned.created_at,res.created_at); | ||
|
||
|
||
} | ||
|
||
} |
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 @@ | ||
mod expiring_data; |
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 @@ | ||
#[cfg(test)] | ||
mod test{ | ||
use std::time::Duration; | ||
use reginleif_macro::{Expirable, NoRefresh}; | ||
use reginleif_utils::expiring_data::{ExpiringData, Refreshable}; | ||
|
||
#[derive(Expirable,NoRefresh,Default)] | ||
struct TestStruct1{ | ||
#[dur] duration: Duration | ||
} | ||
|
||
#[derive(Expirable,Default)] | ||
struct TestStruct2{ | ||
#[dur] duration: Duration | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Refreshable for TestStruct2{ | ||
|
||
type Args = (); | ||
|
||
async fn refresh(&mut self,_:&()) -> anyhow::Result<()> { | ||
Ok(()) // do nothing in test | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn test_expire(){ | ||
let test:ExpiringData<_> = TestStruct1::default().into(); | ||
tokio::time::sleep(Duration::from_secs(2)).await; | ||
let temp = test.is_expired(); | ||
let _test = test.get_ref(); | ||
assert!(temp) | ||
} | ||
|
||
#[tokio::test] | ||
#[should_panic] | ||
pub async fn test_no_refresh(){ | ||
let mut test:ExpiringData<_> = TestStruct1::default().into(); | ||
test.refresh(&()).await.expect("it's should be panic!"); | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn test_expire2(){ | ||
let mut test:ExpiringData<_> = TestStruct2::default().into(); | ||
tokio::time::sleep(Duration::from_secs(2)).await; | ||
test.refresh(&()).await.unwrap(); | ||
test.try_ref(&()).await.unwrap(); | ||
} | ||
|
||
} |
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