From c3386da82772f876c0ee1961ec4abfde758a9701 Mon Sep 17 00:00:00 2001 From: Christoph Walcher Date: Sun, 28 Jul 2019 15:27:25 +0200 Subject: [PATCH] Added integrationtests --- .travis.yml | 27 +++++++++++++++++++------ Cargo.toml | 3 +++ tests/mosquitto_invalid_alg.conf | 6 ++++++ tests/mosquitto_valid.conf | 6 ++++++ tests/tests.rs | 34 ++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 tests/mosquitto_invalid_alg.conf create mode 100644 tests/mosquitto_valid.conf create mode 100644 tests/tests.rs diff --git a/.travis.yml b/.travis.yml index e37a069..d22f51a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: rust - cache: cargo - -#codecov sudo: required - addons: apt: + sources: + - sourceline: deb https://repo.mosquitto.org/debian jessie main + key_url: http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key + packages: - libcurl4-openssl-dev - libelf-dev @@ -15,10 +15,17 @@ addons: - gcc - binutils-dev - libiberty-dev - env: - RUST_TEST_THREADS=1 +before_install: + - wget http://ftp.nz.debian.org/debian/pool/main/libw/libwebsockets/libwebsockets3_1.2.2-1_amd64.deb + - sudo dpkg -i libwebsockets3_1.2.2-1_amd64.deb + - sudo apt install -y mosquitto +script: + - cargo build --verbose + - cargo test --verbose + - cargo build --release --verbose after_success: | cargo install cargo-kcov && mkdir kcov && @@ -26,5 +33,13 @@ after_success: | cargo kcov --print-install-kcov-sh | sh && cd ${TRAVIS_BUILD_DIR} && rm -rf kcov && - cargo kcov --all -v --coveralls && + cargo kcov --all -v --coveralls --no-clean-rebuild && echo "Uploaded code coverage" +deploy: + provider: releases + api_key: + secure: MsOQjpV5QdqOUqG8qJOPJ8IZ5wXARq9y0SDHbqVX2W13vJx3n1sYkbFYTQcuionL5HtMve62AsE+TrRbaUSUob9aytqjOU8eFH095aqpG6ZZh+CzDOnuirVs0WPIizU9zHtzAQT7YcbN59hvivJwnZ03w7SWS129zuoY3VNiOCAgq0h8jmUH/weFc+CuiohhCPXhvTOTuOIemMbnS6r1CTq2hzpj0mdrXRMEwInBpTV8vhOR3TLruIWObHHijW6wnCt0ROobDWq+MaY+3tv3jsdTLJKH++U00c1h3XIznFIyb6GZM2MHkjMsOebHnMnkHqj7Sgi8sbvXsdVazCD/mH4QVrjRuOxuYpWJ700hUnezahuK4uRk62rRr/oc383CBJri2fuXv2V8SY9rPgQAmn0VwSEk7Sys7jmlQ59Y8SYrwMpgFpJjxqrNMU9jOYnSU7O+9IjoD5z5GC8wTRtw+jyzXjm7FcU+/W0fT0yCYdbYGPCs0epc8jB/Na+A14M/y8AcFR86DvOjsv5ko1hWw/yROPR9Y9N/f6unVgCgf90osxLFP6NE8KxSC+CZI2ZAbtll3iwxuPfZxRYanT7g+MgqWnwRJhzrlb/W40NSEX5XT+8+mq1E5aD/O0FBLi54NDK/GuUelaL99S1YPxCcmFvSnXoRZ+dehhHckluPktE= + file: target/release/libmosquitto_jwt_auth.so + on: + repo: wiomoc/mosquitto-jwt-auth + tags: true diff --git a/Cargo.toml b/Cargo.toml index 4e8178c..34d55d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ name = "mosquitto-jwt-auth" version = "0.1.0" authors = ["Christoph Walcher "] edition = "2018" +[badges] +travis-ci = { repository = "wiomoc/mosquitto-jwt-auth" } +coveralls = { repository = "wiomoc/mosquitto-jwt-auth" } [lib] crate-type=["dylib"] diff --git a/tests/mosquitto_invalid_alg.conf b/tests/mosquitto_invalid_alg.conf new file mode 100644 index 0000000..148b2cf --- /dev/null +++ b/tests/mosquitto_invalid_alg.conf @@ -0,0 +1,6 @@ +auth_plugin target/debug/libmosquitto_jwt_auth.so +auth_opt_jwt_alg HS999 +auth_opt_jwt_sec_base64 XmThTwNsoLBlbk3cbOi5r2g1EIJNT7o7zSKy9tMUsIg= +auth_opt_jwt_validate_exp false +auth_opt_jwt_validate_sub_match_username false +listener 3883 diff --git a/tests/mosquitto_valid.conf b/tests/mosquitto_valid.conf new file mode 100644 index 0000000..d837dd1 --- /dev/null +++ b/tests/mosquitto_valid.conf @@ -0,0 +1,6 @@ +auth_plugin target/debug/libmosquitto_jwt_auth.so +auth_opt_jwt_alg HS256 +auth_opt_jwt_sec_base64 XmThTwNsoLBlbk3cbOi5r2g1EIJNT7o7zSKy9tMUsIg= +auth_opt_jwt_validate_exp false +auth_opt_jwt_validate_sub_match_username false +listener 3884 diff --git a/tests/tests.rs b/tests/tests.rs new file mode 100644 index 0000000..f3b843a --- /dev/null +++ b/tests/tests.rs @@ -0,0 +1,34 @@ +use std::io::{BufRead, BufReader}; +use std::process::{Child, Command, Stdio}; +use std::thread; +use std::time::Duration; + +#[test] +#[cfg(target_os = "linux")] +fn test_should_start() { + let mut child = Command::new("mosquitto") + .args(&["-c", "tests/mosquitto_valid.conf"]) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + + thread::sleep(Duration::from_secs(3)); + + assert!(child.try_wait().unwrap().is_none()); + child.kill().unwrap(); + thread::sleep(Duration::from_secs(3)); +} + +#[test] +#[cfg(target_os = "linux")] +fn test_invalid_config() { + let mut child = Command::new("mosquitto") + .args(&["-c", "tests/mosquitto_invalid_alg.conf"]) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + + thread::sleep(Duration::from_secs(3)); + + assert_eq!(child.wait().unwrap().code().unwrap(), 1); +}