From 23c8053d4a429f4b1adb67e2e00dfa43b43c13e0 Mon Sep 17 00:00:00 2001 From: Lewin Bormann Date: Fri, 8 Apr 2022 23:27:22 -0700 Subject: [PATCH] for #165: update refresh flow test --- tests/tests.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 846e51e..6ffa6bd 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -446,6 +446,8 @@ async fn test_refresh() { .expect("failed to get token"); assert_eq!("accesstoken3", tok.as_str()); + // Refresh fails, but renewing the token succeeds. + // PR #165 server.expect( Expectation::matching(all_of![ request::method_path("POST", "/token"), @@ -458,18 +460,26 @@ async fn test_refresh() { "error": "invalid_request", }))), ); + server.expect( + Expectation::matching(all_of![ + request::method_path("POST", "/token"), + request::body(url_decoded(all_of![ + contains(("code", "authorizationcode")), + contains(("client_id", matches("^9022167"))), + ])) + ]) + .respond_with(json_encoded(serde_json::json!({ + "access_token": "accesstoken", + "refresh_token": "refreshtoken", + "token_type": "Bearer", + "expires_in": 59, + }))), + ); let tok_err = auth .token(&["https://googleapis.com/some/scope"]) - .await - .expect_err("token refresh succeeded unexpectedly"); - match tok_err { - Error::AuthError(AuthError { - error: AuthErrorCode::InvalidRequest, - .. - }) => {} - e => panic!("unexpected error on refresh: {:?}", e), - } + .await; + assert!(tok_err.is_ok()); } #[tokio::test]