-
Notifications
You must be signed in to change notification settings - Fork 125
feat(proxy): allow setting allow-lan via API #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,85 @@ use std::{path::PathBuf, time::Duration}; | |
|
|
||
| mod common; | ||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
| #[serial_test::serial] | ||
| async fn test_get_set_allow_lan() { | ||
| let wd = | ||
| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/data/config/client"); | ||
| let config_path = wd.join("rules.yaml"); | ||
| assert!( | ||
| config_path.exists(), | ||
| "Config file does not exist at: {}", | ||
| config_path.to_string_lossy() | ||
| ); | ||
|
|
||
| std::thread::spawn(move || { | ||
| start_clash(Options { | ||
| config: Config::File(config_path.to_string_lossy().to_string()), | ||
| cwd: Some(wd.to_string_lossy().to_string()), | ||
| rt: None, | ||
| log_file: None, | ||
| }) | ||
| .expect("Failed to start clash"); | ||
| }); | ||
|
|
||
| wait_port_ready(9090).expect("Clash server is not ready"); | ||
|
|
||
| async fn get_allow_lan() -> bool { | ||
| let get_configs_url = "http://localhost:9090/configs"; | ||
| let curl_cmd = format!( | ||
| "curl -s -H 'Authorization: Bearer {}' {}", | ||
| "clash-rs", get_configs_url | ||
| ); | ||
| let output = tokio::process::Command::new("sh") | ||
|
||
| .arg("-c") | ||
| .arg(curl_cmd) | ||
| .output() | ||
| .await | ||
| .expect("Failed to execute curl command"); | ||
| assert!( | ||
| output.status.success(), | ||
| "Curl command failed with output: {}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
| let response = String::from_utf8_lossy(&output.stdout); | ||
| let json = serde_json::from_str::<serde_json::Value>(&response) | ||
| .expect("Failed to parse JSON response"); | ||
| json.get("allow-lan") | ||
| .expect("No 'allow-lan' field in response") | ||
| .as_bool() | ||
| .expect("'allow-lan' is not a boolean") | ||
| } | ||
|
|
||
| assert!( | ||
| get_allow_lan().await, | ||
| "'allow_lan' should be true by config" | ||
| ); | ||
|
|
||
| let configs_url = "http://localhost:9090/configs"; | ||
| let curl_cmd = format!( | ||
| "curl -s -X PATCH -H 'Authorization: Bearer {}' -H 'Content-Type: \ | ||
| application/json' -d '{{\"allow-lan\": false}}' {configs_url}", | ||
| "clash-rs" | ||
| ); | ||
| let output = tokio::process::Command::new("sh") | ||
| .arg("-c") | ||
| .arg(curl_cmd) | ||
| .output() | ||
| .await | ||
| .expect("Failed to execute curl command"); | ||
| assert!( | ||
| output.status.success(), | ||
| "Curl command failed with output: {}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
|
|
||
| assert!( | ||
| !get_allow_lan().await, | ||
| "'allow_lan' should be false after update" | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
| #[serial_test::serial] | ||
| async fn test_connections_returns_proxy_chain_names() { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebuilding the entire handlers map on each allow_lan toggle can be inefficient. Instead, iterate over guard.values_mut() and update common_opts_mut().allow_lan in place to avoid unnecessary allocations.