mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-23 02:18:53 +01:00
Merge pull request #123 from ggriffiniii/master
Update to httptest v0.11.1
This commit is contained in:
@@ -25,7 +25,7 @@ tokio = { version = "0.2", features = ["fs", "macros", "io-std", "time"] }
|
||||
url = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
httptest = "0.5"
|
||||
httptest = "0.11.1"
|
||||
env_logger = "0.6"
|
||||
tempfile = "3.1"
|
||||
|
||||
|
||||
112
tests/tests.rs
112
tests/tests.rs
@@ -59,9 +59,8 @@ async fn test_device_success() {
|
||||
let server = Server::run();
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/code"),
|
||||
request::body(url_decoded(contains_entry((
|
||||
request::method_path("POST", "/code"),
|
||||
request::body(url_decoded(contains((
|
||||
"client_id",
|
||||
matches("902216714886")
|
||||
)))),
|
||||
@@ -76,11 +75,10 @@ async fn test_device_success() {
|
||||
);
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("client_secret", "iuMPN6Ne1PD7cos29Tk9rlqH")),
|
||||
contains_entry(("code", "devicecode")),
|
||||
contains(("client_secret", "iuMPN6Ne1PD7cos29Tk9rlqH")),
|
||||
contains(("code", "devicecode")),
|
||||
])),
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -105,9 +103,8 @@ async fn test_device_no_code() {
|
||||
let server = Server::run();
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/code"),
|
||||
request::body(url_decoded(contains_entry((
|
||||
request::method_path("POST", "/code"),
|
||||
request::body(url_decoded(contains((
|
||||
"client_id",
|
||||
matches("902216714886")
|
||||
)))),
|
||||
@@ -129,9 +126,8 @@ async fn test_device_no_token() {
|
||||
let server = Server::run();
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/code"),
|
||||
request::body(url_decoded(contains_entry((
|
||||
request::method_path("POST", "/code"),
|
||||
request::body(url_decoded(contains((
|
||||
"client_id",
|
||||
matches("902216714886")
|
||||
)))),
|
||||
@@ -146,11 +142,10 @@ async fn test_device_no_token() {
|
||||
);
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("client_secret", "iuMPN6Ne1PD7cos29Tk9rlqH")),
|
||||
contains_entry(("code", "devicecode")),
|
||||
contains(("client_secret", "iuMPN6Ne1PD7cos29Tk9rlqH")),
|
||||
contains(("code", "devicecode")),
|
||||
])),
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -241,11 +236,10 @@ async fn test_installed_interactive_success() {
|
||||
create_installed_flow_auth(&server, InstalledFlowReturnMethod::Interactive, None).await;
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("9022167.*"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("9022167.*"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -271,11 +265,10 @@ async fn test_installed_redirect_success() {
|
||||
create_installed_flow_auth(&server, InstalledFlowReturnMethod::HTTPRedirect, None).await;
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("9022167.*"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("9022167.*"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -301,11 +294,10 @@ async fn test_installed_error() {
|
||||
create_installed_flow_auth(&server, InstalledFlowReturnMethod::Interactive, None).await;
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("9022167.*"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("9022167.*"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(
|
||||
@@ -351,10 +343,8 @@ async fn test_service_account_success() {
|
||||
let auth = create_service_account_auth(&server).await;
|
||||
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
]).respond_with(json_encoded(serde_json::json!({
|
||||
Expectation::matching(request::method_path("POST", "/token"))
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
"access_token": "ya29.c.ElouBywiys0LyNaZoLPJcp1Fdi2KjFMxzvYKLXkTdvM-rDfqKlvEq6PiMhGoGHx97t5FAvz3eb_ahdwlBjSStxHtDVQB4ZPRJQ_EOi-iS7PnayahU2S9Jp8S6rk",
|
||||
"expires_in": 3600,
|
||||
"token_type": "Bearer"
|
||||
@@ -374,10 +364,11 @@ async fn test_service_account_error() {
|
||||
let server = Server::run();
|
||||
let auth = create_service_account_auth(&server).await;
|
||||
server.expect(
|
||||
Expectation::matching(all_of![request::method("POST"), request::path("/token"),])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
Expectation::matching(request::method_path("POST", "/token")).respond_with(json_encoded(
|
||||
serde_json::json!({
|
||||
"error": "access_denied",
|
||||
}))),
|
||||
}),
|
||||
)),
|
||||
);
|
||||
|
||||
let result = auth
|
||||
@@ -397,11 +388,10 @@ async fn test_refresh() {
|
||||
// the next token call.
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -419,11 +409,10 @@ async fn test_refresh() {
|
||||
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("refresh_token", "refreshtoken")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("refresh_token", "refreshtoken")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -441,11 +430,10 @@ async fn test_refresh() {
|
||||
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("refresh_token", "refreshtoken")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("refresh_token", "refreshtoken")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -463,11 +451,10 @@ async fn test_refresh() {
|
||||
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("refresh_token", "refreshtoken")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("refresh_token", "refreshtoken")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -496,11 +483,10 @@ async fn test_memory_storage() {
|
||||
create_installed_flow_auth(&server, InstalledFlowReturnMethod::Interactive, None).await;
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -530,11 +516,10 @@ async fn test_memory_storage() {
|
||||
create_installed_flow_auth(&server, InstalledFlowReturnMethod::Interactive, None).await;
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
]))
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
@@ -559,11 +544,10 @@ async fn test_disk_storage() {
|
||||
let storage_path = tempdir.path().join("tokenstorage.json");
|
||||
server.expect(
|
||||
Expectation::matching(all_of![
|
||||
request::method("POST"),
|
||||
request::path("/token"),
|
||||
request::method_path("POST", "/token"),
|
||||
request::body(url_decoded(all_of![
|
||||
contains_entry(("code", "authorizationcode")),
|
||||
contains_entry(("client_id", matches("^9022167"))),
|
||||
contains(("code", "authorizationcode")),
|
||||
contains(("client_id", matches("^9022167"))),
|
||||
])),
|
||||
])
|
||||
.respond_with(json_encoded(serde_json::json!({
|
||||
|
||||
Reference in New Issue
Block a user