improve test_client diagnostics

This commit is contained in:
Robin Appelman 2021-03-04 11:01:10 +01:00
Родитель ee1dbe303f
Коммит 464b69695b
5 изменённых файлов: 285 добавлений и 1066 удалений

247
Cargo.lock сгенерированный
Просмотреть файл

@ -163,6 +163,12 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "base-x"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.12.3" version = "0.12.3"
@ -290,10 +296,16 @@ dependencies = [
"libc", "libc",
"num-integer", "num-integer",
"num-traits", "num-traits",
"time", "time 0.1.43",
"winapi", "winapi",
] ]
[[package]]
name = "chunked_transfer"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e"
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "2.33.3"
@ -349,6 +361,39 @@ dependencies = [
"tokio", "tokio",
] ]
[[package]]
name = "const_fn"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
[[package]]
name = "cookie"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951"
dependencies = [
"percent-encoding",
"time 0.2.25",
"version_check",
]
[[package]]
name = "cookie_store"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3"
dependencies = [
"cookie",
"idna",
"log",
"publicsuffix",
"serde",
"serde_json",
"time 0.2.25",
"url",
]
[[package]] [[package]]
name = "cpuid-bool" name = "cpuid-bool"
version = "0.1.2" version = "0.1.2"
@ -433,6 +478,12 @@ dependencies = [
"generic-array 0.14.4", "generic-array 0.14.4",
] ]
[[package]]
name = "discard"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]] [[package]]
name = "dotenv" name = "dotenv"
version = "0.15.0" version = "0.15.0"
@ -710,7 +761,7 @@ dependencies = [
"http", "http",
"mime", "mime",
"sha-1 0.8.2", "sha-1 0.8.2",
"time", "time 0.1.43",
] ]
[[package]] [[package]]
@ -1118,7 +1169,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d59c5b7e31b67ba9018dbe63a1ada4ea333c0f0ae7e160263c1564afb1215cf" checksum = "9d59c5b7e31b67ba9018dbe63a1ada4ea333c0f0ae7e160263c1564afb1215cf"
dependencies = [ dependencies = [
"semver", "semver 0.10.0",
"thiserror", "thiserror",
"xpath_reader", "xpath_reader",
] ]
@ -1162,6 +1213,7 @@ dependencies = [
"smallvec", "smallvec",
"sqlx", "sqlx",
"structopt", "structopt",
"test_client",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
@ -1471,6 +1523,25 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "publicsuffix"
version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f"
dependencies = [
"idna",
"url",
]
[[package]]
name = "qstring"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e"
dependencies = [
"percent-encoding",
]
[[package]] [[package]]
name = "quick-error" name = "quick-error"
version = "1.2.3" version = "1.2.3"
@ -1736,6 +1807,15 @@ version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver 0.9.0",
]
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.19.0" version = "0.19.0"
@ -1783,6 +1863,15 @@ dependencies = [
"untrusted", "untrusted",
] ]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]] [[package]]
name = "semver" name = "semver"
version = "0.10.0" version = "0.10.0"
@ -2059,12 +2148,70 @@ dependencies = [
"tokio-rustls", "tokio-rustls",
] ]
[[package]]
name = "standback"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2beb4d1860a61f571530b3f855a1b538d0200f7871c63331ecd6f17b1f014f8"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "static_assertions" name = "static_assertions"
version = "1.1.0" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stdweb"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
dependencies = [
"discard",
"rustc_version",
"stdweb-derive",
"stdweb-internal-macros",
"stdweb-internal-runtime",
"wasm-bindgen",
]
[[package]]
name = "stdweb-derive"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_derive",
"syn",
]
[[package]]
name = "stdweb-internal-macros"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde",
"serde_derive",
"serde_json",
"sha1",
"syn",
]
[[package]]
name = "stdweb-internal-runtime"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
[[package]] [[package]]
name = "stringprep" name = "stringprep"
version = "0.1.2" version = "0.1.2"
@ -2187,6 +2334,18 @@ dependencies = [
"redox_termios", "redox_termios",
] ]
[[package]]
name = "test_client"
version = "0.1.0"
dependencies = [
"color-eyre",
"flexi_logger",
"log",
"serde_json",
"tungstenite 0.13.0",
"ureq",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.11.0"
@ -2235,6 +2394,44 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "time"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1195b046942c221454c2539395f85413b33383a067449d78aab2b7b052a142f7"
dependencies = [
"const_fn",
"libc",
"standback",
"stdweb",
"time-macros",
"version_check",
"winapi",
]
[[package]]
name = "time-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1"
dependencies = [
"proc-macro-hack",
"time-macros-impl",
]
[[package]]
name = "time-macros-impl"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa"
dependencies = [
"proc-macro-hack",
"proc-macro2",
"quote",
"standback",
"syn",
]
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
version = "1.1.1" version = "1.1.1"
@ -2313,7 +2510,7 @@ dependencies = [
"log", "log",
"pin-project", "pin-project",
"tokio", "tokio",
"tungstenite", "tungstenite 0.12.0",
] ]
[[package]] [[package]]
@ -2457,6 +2654,29 @@ dependencies = [
"utf-8", "utf-8",
] ]
[[package]]
name = "tungstenite"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fe8dada8c1a3aeca77d6b51a4f1314e0f4b8e438b7b1b71e3ddaca8080e4093"
dependencies = [
"base64 0.13.0",
"byteorder",
"bytes",
"http",
"httparse",
"input_buffer",
"log",
"rand 0.8.3",
"rustls",
"sha-1 0.9.4",
"thiserror",
"url",
"utf-8",
"webpki",
"webpki-roots",
]
[[package]] [[package]]
name = "twoway" name = "twoway"
version = "0.1.8" version = "0.1.8"
@ -2544,6 +2764,25 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "ureq"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "294b85ef5dbc3670a72e82a89971608a1fcc4ed5c7c5a2895230d31a95f0569b"
dependencies = [
"base64 0.13.0",
"chunked_transfer",
"cookie",
"cookie_store",
"log",
"once_cell",
"qstring",
"rustls",
"url",
"webpki",
"webpki-roots",
]
[[package]] [[package]]
name = "url" name = "url"
version = "2.2.1" version = "2.2.1"

Просмотреть файл

@ -34,6 +34,7 @@ structopt = "0.3"
mini-redis = "0.4" mini-redis = "0.4"
tokio-tungstenite = "0.13" tokio-tungstenite = "0.13"
http-auth-basic = "0.1" http-auth-basic = "0.1"
test_client = { path = "test_client" }
[build-dependencies] [build-dependencies]
nextcloud_appinfo = "0.6" nextcloud_appinfo = "0.6"
@ -43,3 +44,5 @@ opt-level = 3
[profile.release] [profile.release]
lto = true lto = true
[workspace]

1047
test_client/Cargo.lock сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,6 +5,9 @@ authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
tungstenite = { version = "0.13.0", default-features = false, features = ["rustls-tls"] } tungstenite = { version = "0.13", default-features = false, features = ["rustls-tls"] }
color-eyre = "0.5.8" color-eyre = "0.5"
ureq = { version = "1.5", features = ["json"] } serde_json = "1"
ureq = "1"
flexi_logger = { version = "0.17", features = ["colors"] }
log = "0.4"

Просмотреть файл

@ -1,9 +1,13 @@
use color_eyre::{eyre::WrapErr, Report, Result}; use color_eyre::{eyre::WrapErr, Report, Result};
use flexi_logger::Logger;
use serde_json::Value;
use std::env::var;
use tungstenite::http::Request; use tungstenite::http::Request;
use tungstenite::{connect, Message}; use tungstenite::{connect, Message};
fn main() -> Result<()> { fn main() -> Result<()> {
color_eyre::install()?; color_eyre::install()?;
Logger::with_str(&var("LOG").unwrap_or_else(|_| String::from("warn"))).start()?;
let mut args = std::env::args(); let mut args = std::env::args();
@ -52,19 +56,36 @@ fn main() -> Result<()> {
} }
fn get_endpoint(nc_url: &str, user: &str, password: &str) -> Result<String> { fn get_endpoint(nc_url: &str, user: &str, password: &str) -> Result<String> {
let json = ureq::get(&format!("{}/ocs/v2.php/cloud/capabilities", nc_url)) let raw = ureq::get(&format!("{}/ocs/v2.php/cloud/capabilities", nc_url))
.auth(user, password) .auth(user, password)
.set("Accept", "application/json") .set("Accept", "application/json")
.set("OCS-APIREQUEST", "true") .set("OCS-APIREQUEST", "true")
.call() .call()
.into_json() .into_string()?;
.wrap_err("Failed to decode json capabilities response")?; log::debug!("Capabilities response: {}", raw);
Ok( let json: Value = serde_json::from_str(&raw)
json["ocs"]["data"]["capabilities"]["notify_push"]["endpoints"]["websocket"] .wrap_err_with(|| format!("Failed to decode json capabilities response: {}", raw))?;
.as_str() if let Some(capabilities) = json["ocs"]["data"]["capabilities"].as_object() {
.map(|url| url.to_string()) log::info!(
.ok_or(Report::msg( "Supported capabilities: {:?}",
"notify_push app not enabled, invalid credentials or invalid capabilities response", capabilities.keys().collect::<Vec<_>>()
))?, );
) if let Some(notify_push) = capabilities.get("notify_push") {
notify_push["endpoints"]["websocket"]
.as_str()
.map(|url| url.to_string())
.ok_or(Report::msg("invalid notify_push capabilities"))
} else if !capabilities.contains_key("files_sharing") {
Err(Report::msg("capabilities response doesn't contain expect items, credentials are probably invalid"))
} else {
Err(Report::msg(
"notify_push app doesn't seem to be enabled or setup",
))
}
} else {
Err(Report::msg(format!(
"invalid capabilities response: {}",
json
)))
}
} }