Release v1.1.0

This commit is contained in:
thakares committed 2026-09-02 15:19:19 +05:30
1 parent 34227efd2b
commit edc710cbd2
46 files changed
+5324 -190

No files matched your search

+52 -4
View File
@@ -5,7 +5,10 @@ use nx9_wg_api::routes::build_api_router;
use nx9_wg_api::state::AppState;
use nx9_wg_core::config::AppConfig;
use nx9_wg_db::Store;
use nx9_wg_network::SimulatedNetworkEngine;
use nx9_wireguard::SimulatedWireGuardEngine;
use serde_json::{Value, json};
use std::sync::Arc;
use tower::ServiceExt;
async fn setup_test_app() -> (axum::Router, String) {
@@ -21,7 +24,11 @@ async fn setup_test_app() -> (axum::Router, String) {
.await
.expect("bootstrap");
let state = AppState::new(store);
let state = AppState::with_engines(
store,
Arc::new(SimulatedWireGuardEngine::new()),
Arc::new(SimulatedNetworkEngine::new()),
);
let app = build_api_router(state.clone());
// Login to get session ID
@@ -78,6 +85,7 @@ async fn test_public_health_and_version_endpoints() {
let body = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let val: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(val["name"], "nx9-wg");
assert_eq!(val["version"], "1.1.0");
}
#[tokio::test]
@@ -176,14 +184,54 @@ async fn test_interfaces_and_peers_rest_lifecycle() {
let peer_val: Value = serde_json::from_slice(&body).unwrap();
assert_eq!(peer_val["state"], "disabled");
// 6. Delete interface (cascades peer)
let del_iface_req = Request::builder()
// 6. Delete wg0 interface (must be rejected with 403 Forbidden)
let del_wg0_req = Request::builder()
.method("DELETE")
.uri(format!("/api/v1/interfaces/{iface_id}"))
.header(header::COOKIE, &cookie)
.body(Body::empty())
.unwrap();
let resp = app.clone().oneshot(del_iface_req).await.unwrap();
let resp = app.clone().oneshot(del_wg0_req).await.unwrap();
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
// 7. Restart wg0 interface (must succeed)
let restart_wg0_req = Request::builder()
.method("POST")
.uri(format!("/api/v1/interfaces/{iface_id}/restart"))
.header(header::COOKIE, &cookie)
.body(Body::empty())
.unwrap();
let resp = app.clone().oneshot(restart_wg0_req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
// 8. Create secondary interface and delete it (must succeed)
let create_sec_req = Request::builder()
.method("POST")
.uri("/api/v1/interfaces")
.header(header::COOKIE, &cookie)
.header(header::CONTENT_TYPE, "application/json")
.body(Body::from(
json!({
"name": "custom0",
"listen_port": 51822,
"address_v4": "10.200.0.1/24"
})
.to_string(),
))
.unwrap();
let resp = app.clone().oneshot(create_sec_req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
let body = to_bytes(resp.into_body(), usize::MAX).await.unwrap();
let sec_val: Value = serde_json::from_slice(&body).unwrap();
let sec_id = sec_val["id"].as_str().unwrap();
let del_sec_req = Request::builder()
.method("DELETE")
.uri(format!("/api/v1/interfaces/{sec_id}"))
.header(header::COOKIE, &cookie)
.body(Body::empty())
.unwrap();
let resp = app.clone().oneshot(del_sec_req).await.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}