diff --git a/Cargo.lock b/Cargo.lock index bda597b..6486556 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,7 +2,7 @@ name = "inth-oauth2" version = "0.11.0" dependencies = [ - "chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.11 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -46,7 +46,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "chrono" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -506,7 +506,7 @@ dependencies = [ "checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" -"checksum chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9123be86fd2a8f627836c235ecdf331fdd067ecf7ac05aa1a68fbcf2429f056" +"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" "checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" "checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d" "checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec" diff --git a/Cargo.toml b/Cargo.toml index e3d1da2..2eb8827 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/programble/inth-oauth2" readme = "README.md" [dependencies] -chrono = { version = "0.3", features = ["serde"] } +chrono = { version = "0.4", features = ["serde"] } hyper = "0.10" serde = "1.0.8" serde_derive = "1.0.5" diff --git a/src/token/bearer.rs b/src/token/bearer.rs index efbb8b1..ded32aa 100644 --- a/src/token/bearer.rs +++ b/src/token/bearer.rs @@ -64,7 +64,7 @@ impl FromResponse for Bearer { #[cfg(test)] mod tests { - use chrono::{UTC, Duration}; + use chrono::{Utc, Duration}; use client::response::{FromResponse, ParseError}; use token::{Static, Refresh}; @@ -135,8 +135,8 @@ mod tests { assert_eq!(None, bearer.scope); let refresh = bearer.lifetime; assert_eq!("bbbbbbbb", refresh.refresh_token()); - assert!(refresh.expires() > &UTC::now()); - assert!(refresh.expires() <= &(UTC::now() + Duration::seconds(3600))); + assert!(refresh.expires() > &Utc::now()); + assert!(refresh.expires() <= &(Utc::now() + Duration::seconds(3600))); } #[test] @@ -163,7 +163,7 @@ mod tests { assert_eq!(None, bearer.scope); let refresh = bearer.lifetime; assert_eq!("bbbbbbbb", refresh.refresh_token()); - assert!(refresh.expires() > &UTC::now()); - assert!(refresh.expires() <= &(UTC::now() + Duration::seconds(3600))); + assert!(refresh.expires() > &Utc::now()); + assert!(refresh.expires() <= &(Utc::now() + Duration::seconds(3600))); } } diff --git a/src/token/expiring.rs b/src/token/expiring.rs index 28e5edc..2229846 100644 --- a/src/token/expiring.rs +++ b/src/token/expiring.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, UTC, Duration}; +use chrono::{DateTime, Utc, Duration}; use serde_json::Value; use client::response::{FromResponse, ParseError}; @@ -7,16 +7,16 @@ use token::Lifetime; /// An expiring token. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct Expiring { - expires: DateTime, + expires: DateTime, } impl Expiring { /// Returns the expiry time of the access token. - pub fn expires(&self) -> &DateTime { &self.expires } + pub fn expires(&self) -> &DateTime { &self.expires } } impl Lifetime for Expiring { - fn expired(&self) -> bool { self.expires < UTC::now() } + fn expired(&self) -> bool { self.expires < Utc::now() } } impl FromResponse for Expiring { @@ -32,14 +32,14 @@ impl FromResponse for Expiring { .ok_or(ParseError::ExpectedFieldType("expires_in", "i64"))?; Ok(Expiring { - expires: UTC::now() + Duration::seconds(expires_in), + expires: Utc::now() + Duration::seconds(expires_in), }) } } #[cfg(test)] mod tests { - use chrono::{UTC, Duration}; + use chrono::{Utc, Duration}; use client::response::FromResponse; use super::Expiring; @@ -48,7 +48,7 @@ mod tests { fn from_response() { let json = r#"{"expires_in":3600}"#.parse().unwrap(); let expiring = Expiring::from_response(&json).unwrap(); - assert!(expiring.expires > UTC::now()); - assert!(expiring.expires <= UTC::now() + Duration::seconds(3600)); + assert!(expiring.expires > Utc::now()); + assert!(expiring.expires <= Utc::now() + Duration::seconds(3600)); } } diff --git a/src/token/refresh.rs b/src/token/refresh.rs index 8698ef7..a2e60e6 100644 --- a/src/token/refresh.rs +++ b/src/token/refresh.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, UTC, Duration}; +use chrono::{DateTime, Utc, Duration}; use serde_json::Value; use client::response::{FromResponse, ParseError}; @@ -8,7 +8,7 @@ use token::Lifetime; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Refresh { refresh_token: String, - expires: DateTime, + expires: DateTime, } impl Refresh { @@ -18,11 +18,11 @@ impl Refresh { pub fn refresh_token(&self) -> &str { &self.refresh_token } /// Returns the expiry time of the access token. - pub fn expires(&self) -> &DateTime { &self.expires } + pub fn expires(&self) -> &DateTime { &self.expires } } impl Lifetime for Refresh { - fn expired(&self) -> bool { self.expires < UTC::now() } + fn expired(&self) -> bool { self.expires < Utc::now() } } impl FromResponse for Refresh { @@ -38,7 +38,7 @@ impl FromResponse for Refresh { Ok(Refresh { refresh_token: refresh_token.into(), - expires: UTC::now() + Duration::seconds(expires_in), + expires: Utc::now() + Duration::seconds(expires_in), }) } @@ -56,14 +56,14 @@ impl FromResponse for Refresh { Ok(Refresh { refresh_token: refresh_token.into(), - expires: UTC::now() + Duration::seconds(expires_in), + expires: Utc::now() + Duration::seconds(expires_in), }) } } #[cfg(test)] mod tests { - use chrono::{UTC, Duration}; + use chrono::{Utc, Duration}; use client::response::FromResponse; use super::Refresh; @@ -73,8 +73,8 @@ mod tests { let json = r#"{"refresh_token":"aaaaaaaa","expires_in":3600}"#.parse().unwrap(); let refresh = Refresh::from_response(&json).unwrap(); assert_eq!("aaaaaaaa", refresh.refresh_token); - assert!(refresh.expires > UTC::now()); - assert!(refresh.expires <= UTC::now() + Duration::seconds(3600)); + assert!(refresh.expires > Utc::now()); + assert!(refresh.expires <= Utc::now() + Duration::seconds(3600)); } #[test] @@ -82,11 +82,11 @@ mod tests { let json = r#"{"expires_in":3600}"#.parse().unwrap(); let prev = Refresh { refresh_token: String::from("aaaaaaaa"), - expires: UTC::now(), + expires: Utc::now(), }; let refresh = Refresh::from_response_inherit(&json, &prev).unwrap(); assert_eq!("aaaaaaaa", refresh.refresh_token); - assert!(refresh.expires > UTC::now()); - assert!(refresh.expires <= UTC::now() + Duration::seconds(3600)); + assert!(refresh.expires > Utc::now()); + assert!(refresh.expires <= Utc::now() + Duration::seconds(3600)); } } diff --git a/tests/mock.rs b/tests/mock.rs index f0e760b..1e58f68 100644 --- a/tests/mock.rs +++ b/tests/mock.rs @@ -4,7 +4,7 @@ extern crate inth_oauth2; #[macro_use] extern crate yup_hyper_mock; -use chrono::{UTC, Duration}; +use chrono::{Utc, Duration}; use inth_oauth2::{Client, ClientError, Token, Lifetime}; use inth_oauth2::error::OAuth2ErrorCode; @@ -95,8 +95,8 @@ fn request_token_bearer_expiring_success() { assert_eq!("aaaaaaaa", token.access_token()); assert_eq!(Some("example"), token.scope()); assert_eq!(false, token.lifetime().expired()); - assert!(token.lifetime().expires() > &UTC::now()); - assert!(token.lifetime().expires() <= &(UTC::now() + Duration::seconds(3600))); + assert!(token.lifetime().expires() > &Utc::now()); + assert!(token.lifetime().expires() <= &(Utc::now() + Duration::seconds(3600))); } #[test] @@ -107,8 +107,8 @@ fn request_token_bearer_refresh_success() { assert_eq!(Some("example"), token.scope()); assert_eq!("bbbbbbbb", token.lifetime().refresh_token()); assert_eq!(false, token.lifetime().expired()); - assert!(token.lifetime().expires() > &UTC::now()); - assert!(token.lifetime().expires() <= &(UTC::now() + Duration::seconds(3600))); + assert!(token.lifetime().expires() > &Utc::now()); + assert!(token.lifetime().expires() <= &(Utc::now() + Duration::seconds(3600))); } #[test] @@ -120,8 +120,8 @@ fn refresh_token_bearer_full() { assert_eq!(Some("example"), token.scope()); assert_eq!("dddddddd", token.lifetime().refresh_token()); assert_eq!(false, token.lifetime().expired()); - assert!(token.lifetime().expires() > &UTC::now()); - assert!(token.lifetime().expires() <= &(UTC::now() + Duration::seconds(3600))); + assert!(token.lifetime().expires() > &Utc::now()); + assert!(token.lifetime().expires() <= &(Utc::now() + Duration::seconds(3600))); } #[test] @@ -133,8 +133,8 @@ fn refresh_token_bearer_partial() { assert_eq!(Some("example"), token.scope()); assert_eq!("bbbbbbbb", token.lifetime().refresh_token()); assert_eq!(false, token.lifetime().expired()); - assert!(token.lifetime().expires() > &UTC::now()); - assert!(token.lifetime().expires() <= &(UTC::now() + Duration::seconds(3600))); + assert!(token.lifetime().expires() > &Utc::now()); + assert!(token.lifetime().expires() <= &(Utc::now() + Duration::seconds(3600))); } #[test]