From 53ac5f8e058a3d70cc8ad7dc6f769a436d4ed604 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Tue, 29 Dec 2015 23:02:12 -0500 Subject: [PATCH] Add refresh token mock tests --- tests/mock.rs | 32 +++++++++++++++++++ tests/response/refresh_token_bearer_full.http | 12 +++++++ .../refresh_token_bearer_partial.http | 11 +++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/response/refresh_token_bearer_full.http create mode 100644 tests/response/refresh_token_bearer_partial.http diff --git a/tests/mock.rs b/tests/mock.rs index cd2b59c..bb57931 100644 --- a/tests/mock.rs +++ b/tests/mock.rs @@ -37,6 +37,12 @@ mod connector { mock_connector_in_order!(BearerExpiringSuccess { include_str!("response/request_token_bearer_expiring_success.http") + include_str!("response/refresh_token_bearer_full.http") + }); + + mock_connector_in_order!(BearerExpiringSuccessPartial { + include_str!("response/request_token_bearer_expiring_success.http") + include_str!("response/refresh_token_bearer_partial.http") }); } @@ -71,3 +77,29 @@ fn request_token_bearer_expiring_success() { assert!(token.lifetime().expires() > &UTC::now()); assert!(token.lifetime().expires() <= &(UTC::now() + Duration::seconds(3600))); } + +#[test] +fn refresh_token_bearer_full() { + let client = mock_client!(provider::BearerExpiring, connector::BearerExpiringSuccess); + let token = client.request_token("code").unwrap(); + let token = client.refresh_token(token, None).unwrap(); + assert_eq!("cccccccc", token.access_token()); + 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))); +} + +#[test] +fn refresh_token_bearer_partial() { + let client = mock_client!(provider::BearerExpiring, connector::BearerExpiringSuccessPartial); + let token = client.request_token("code").unwrap(); + let token = client.refresh_token(token, None).unwrap(); + assert_eq!("cccccccc", token.access_token()); + 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))); +} diff --git a/tests/response/refresh_token_bearer_full.http b/tests/response/refresh_token_bearer_full.http new file mode 100644 index 0000000..60cb0f2 --- /dev/null +++ b/tests/response/refresh_token_bearer_full.http @@ -0,0 +1,12 @@ +HTTP/1.1 200 OK +Content-Type: application/json;charset=UTF-8 +Cache-Control: no-store +Pragma: no-cache + +{ + "access_token":"cccccccc", + "token_type":"bearer", + "expires_in":3600, + "refresh_token":"dddddddd", + "scope":"example" +} diff --git a/tests/response/refresh_token_bearer_partial.http b/tests/response/refresh_token_bearer_partial.http new file mode 100644 index 0000000..d88034a --- /dev/null +++ b/tests/response/refresh_token_bearer_partial.http @@ -0,0 +1,11 @@ +HTTP/1.1 200 OK +Content-Type: application/json;charset=UTF-8 +Cache-Control: no-store +Pragma: no-cache + +{ + "access_token":"cccccccc", + "token_type":"bearer", + "expires_in":3600, + "scope":"example" +}