mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-25 14:56:23 -05:00
Make it work on CI
This commit is contained in:
parent
e1d8a1c39b
commit
ae1ea08bb2
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@ -46,12 +46,20 @@ jobs:
|
|||||||
build_test:
|
build_test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Install tor
|
|
||||||
run: sudo apt-get tor
|
|
||||||
|
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install and stop tor in case it was running
|
||||||
|
run: |
|
||||||
|
sudo apt install software-properties-common
|
||||||
|
sudo curl https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | sudo gpg --import
|
||||||
|
sudo gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
|
||||||
|
sudo add-apt-repository 'deb https://deb.torproject.org/torproject.org bionic main'
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install tor deb.torproject.org-keyring
|
||||||
|
sudo /etc/init.d/tor stop
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
@ -33,6 +33,7 @@ hyper = "0.13"
|
|||||||
monero-harness = { path = "../monero-harness" }
|
monero-harness = { path = "../monero-harness" }
|
||||||
port_check = "0.1"
|
port_check = "0.1"
|
||||||
spectral = "0.6"
|
spectral = "0.6"
|
||||||
|
tempfile = "3"
|
||||||
testcontainers = "0.10"
|
testcontainers = "0.10"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.2"
|
tracing-subscriber = "0.2"
|
||||||
|
@ -112,6 +112,6 @@ impl AuthenticatedConnection {
|
|||||||
.iter(),
|
.iter(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| anyhow!("Could not add onion service."))
|
.map_err(|e| anyhow!("Could not add onion service.: {:#?}", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,14 @@ mod tor_test {
|
|||||||
use hyper::service::{make_service_fn, service_fn};
|
use hyper::service::{make_service_fn, service_fn};
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use spectral::prelude::*;
|
use spectral::prelude::*;
|
||||||
use std::{convert::Infallible, process::Child};
|
use std::{convert::Infallible, fs};
|
||||||
|
use tempfile::{Builder, NamedTempFile};
|
||||||
use tokio::sync::oneshot::Receiver;
|
use tokio::sync::oneshot::Receiver;
|
||||||
use torut::{
|
use torut::{
|
||||||
onion::TorSecretKeyV3,
|
onion::TorSecretKeyV3,
|
||||||
utils::{run_tor, AutoKillChild},
|
utils::{run_tor, AutoKillChild},
|
||||||
};
|
};
|
||||||
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
use xmr_btc::tor::UnauthenticatedConnection;
|
use xmr_btc::tor::UnauthenticatedConnection;
|
||||||
|
|
||||||
async fn hello_world(
|
async fn hello_world(
|
||||||
@ -32,9 +34,16 @@ mod tor_test {
|
|||||||
eprintln!("server error: {}", e);
|
eprintln!("server error: {}", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tracing::info!("Test server started at port: {}", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_tmp_tor() -> (Child, u16, u16) {
|
fn run_tmp_tor() -> Result<(AutoKillChild, u16, u16, NamedTempFile)> {
|
||||||
|
// we create an empty torrc file to not use the system one
|
||||||
|
let temp_torrc = Builder::new().tempfile()?;
|
||||||
|
let torrc_file = format!("{}", fs::canonicalize(temp_torrc.path())?.display());
|
||||||
|
tracing::info!("Temp torrc file created at: {}", torrc_file);
|
||||||
|
|
||||||
let control_port = if port_check::is_local_port_free(9051) {
|
let control_port = if port_check::is_local_port_free(9051) {
|
||||||
9051
|
9051
|
||||||
} else {
|
} else {
|
||||||
@ -46,30 +55,33 @@ mod tor_test {
|
|||||||
port_check::free_local_port().unwrap()
|
port_check::free_local_port().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
let child = run_tor(
|
||||||
run_tor(
|
"tor",
|
||||||
"tor",
|
&mut [
|
||||||
&mut [
|
"--CookieAuthentication",
|
||||||
"--CookieAuthentication",
|
"1",
|
||||||
"1",
|
"--ControlPort",
|
||||||
"--ControlPort",
|
control_port.to_string().as_str(),
|
||||||
control_port.to_string().as_str(),
|
"--SocksPort",
|
||||||
"--SocksPort",
|
proxy_port.to_string().as_str(),
|
||||||
proxy_port.to_string().as_str(),
|
"-f",
|
||||||
]
|
&torrc_file,
|
||||||
.iter(),
|
]
|
||||||
)
|
.iter(),
|
||||||
.expect("Starting tor filed"),
|
)?;
|
||||||
control_port,
|
tracing::info!("Tor running with pid: {}", child.id());
|
||||||
proxy_port,
|
let child = AutoKillChild::new(child);
|
||||||
)
|
Ok((child, control_port, proxy_port, temp_torrc))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_tor_control_port() -> Result<()> {
|
async fn test_tor_control_port() -> Result<()> {
|
||||||
|
let _guard = tracing_subscriber::fmt()
|
||||||
|
.with_env_filter("info")
|
||||||
|
.set_default();
|
||||||
|
|
||||||
// start tmp tor
|
// start tmp tor
|
||||||
let (child, control_port, proxy_port) = run_tmp_tor();
|
let (_child, control_port, proxy_port, _tmp_torrc) = run_tmp_tor()?;
|
||||||
let _child = AutoKillChild::new(child);
|
|
||||||
|
|
||||||
// Setup test HTTP Server
|
// Setup test HTTP Server
|
||||||
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
|
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
|
||||||
@ -82,6 +94,8 @@ mod tor_test {
|
|||||||
.init_authenticated_connection()
|
.init_authenticated_connection()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
tracing::info!("Tor authenticated.");
|
||||||
|
|
||||||
// Expose an onion service that re-directs to the echo server.
|
// Expose an onion service that re-directs to the echo server.
|
||||||
let tor_secret_key_v3 = TorSecretKeyV3::generate();
|
let tor_secret_key_v3 = TorSecretKeyV3::generate();
|
||||||
authenticated_connection
|
authenticated_connection
|
||||||
@ -96,11 +110,18 @@ mod tor_test {
|
|||||||
let onion_address = tor_secret_key_v3.public().get_onion_address().to_string();
|
let onion_address = tor_secret_key_v3.public().get_onion_address().to_string();
|
||||||
let onion_url = format!("http://{}:8080", onion_address);
|
let onion_url = format!("http://{}:8080", onion_address);
|
||||||
|
|
||||||
|
tracing::info!("Tor service added: {}", onion_url);
|
||||||
|
|
||||||
let res = client.get(&onion_url).send().await?;
|
let res = client.get(&onion_url).send().await?;
|
||||||
|
|
||||||
assert_that(&res.status()).is_equal_to(StatusCode::OK);
|
assert_that(&res.status()).is_equal_to(StatusCode::OK);
|
||||||
|
|
||||||
let text = res.text().await?;
|
let text = res.text().await?;
|
||||||
assert_that!(text).contains("Hello World");
|
assert_that!(text).contains("Hello World");
|
||||||
|
tracing::info!(
|
||||||
|
"Local server called via Tor proxy. Its response is: {}",
|
||||||
|
text
|
||||||
|
);
|
||||||
|
|
||||||
// gracefully shut down server
|
// gracefully shut down server
|
||||||
let _ = tx.send(());
|
let _ = tx.send(());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user