Add a test.
This commit is contained in:
parent
65e9f336f2
commit
7bc97d63ca
1 changed files with 20 additions and 0 deletions
|
@ -71,6 +71,14 @@ mod tests {
|
|||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||
struct EmptyClaim { }
|
||||
|
||||
#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
|
||||
struct NonEmptyClaim {
|
||||
user_id: String,
|
||||
is_admin: bool,
|
||||
first_name: Option<String>,
|
||||
last_name: Option<String>
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_base64() {
|
||||
let enc = "eyJpc3MiOiJleGFtcGxlLmNvbSIsImV4cCI6MTMwMjMxOTEwMH0";
|
||||
|
@ -97,4 +105,16 @@ mod tests {
|
|||
let enc = claims.to_base64().unwrap();
|
||||
assert_eq!(claims, Claims::from_base64(&*enc).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrip_custom() {
|
||||
let mut claims: Claims<NonEmptyClaim> = Default::default();
|
||||
claims.reg.iss = Some("example.com".into());
|
||||
claims.reg.exp = Some(1302319100);
|
||||
claims.private.user_id = "123456".into();
|
||||
claims.private.is_admin = false;
|
||||
claims.private.first_name = Some("Random".into());
|
||||
let enc = claims.to_base64().unwrap();
|
||||
assert_eq!(claims, Claims::<NonEmptyClaim>::from_base64(&*enc).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue