fix(auth): iam check
This commit is contained in:
40
tests/iam_refresh_decode.rs
Normal file
40
tests/iam_refresh_decode.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AppResponse<T> {
|
||||
code: i32,
|
||||
message: String,
|
||||
data: Option<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct RefreshResponseData {
|
||||
access_token: String,
|
||||
refresh_token: String,
|
||||
token_type: Option<String>,
|
||||
expires_in: usize,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_decode_iam_refresh_response_snake_case() {
|
||||
let json = r#"
|
||||
{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": {
|
||||
"access_token": "a",
|
||||
"refresh_token": "r",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 7200
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
let parsed: AppResponse<RefreshResponseData> = serde_json::from_str(json).unwrap();
|
||||
let data = parsed.data.unwrap();
|
||||
assert_eq!(data.access_token, "a");
|
||||
assert_eq!(data.refresh_token, "r");
|
||||
assert_eq!(data.token_type.as_deref(), Some("Bearer"));
|
||||
assert_eq!(data.expires_in, 7200);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user