Skip to content
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

Add RequestCode::TrustedUserAgentList #37

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Introduced new request code: `RequestCode:TrustedUserAgentList`
- `RequestCode::TrustedUserAgentList`: This new request code facilitates the
REview sending a list of trusted `user-agents` to the agent. This request code
is followed by a `Vec<String>` parameter, which is a list of trusted user-agents.

## [0.8.1] - 2023-06-05

### Added
Expand Down Expand Up @@ -209,6 +218,7 @@ without relying on the content of the response.

- `send_frame` and `recv_frame` to send and receive length-delimited frames.

[Unreleased]: https://github.com/petabi/oinq/compare/0.8.1...main
[0.8.1]: https://github.com/petabi/oinq/compare/0.8.0...0.8.1
[0.8.0]: https://github.com/petabi/oinq/compare/0.7.1...0.8.0
[0.7.1]: https://github.com/petabi/oinq/compare/0.7.0...0.7.1
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub enum RequestCode {
/// Request Echo (for ping)
EchoRequest = 17,

/// Update the list of trusted User-agent
TrustedUserAgentList = 18,

/// Update the list of trusted domains
TrustedDomainList = 0,

Expand Down
40 changes: 40 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@
async fn block_list(&mut self, _list: HostNetworkGroup) -> Result<(), String> {
return Err("not supported".to_string());
}

// This feature is supported for all daemons that use oinq.
async fn echo_request(&mut self) -> Result<(), String> {
return Ok(());
}

async fn trusted_user_agent_list(&mut self, _list: &[&str]) -> Result<(), String> {
return Err("not supported".to_string());
}

Check warning on line 145 in src/request.rs

View check run for this annotation

Codecov / codecov/patch

src/request.rs#L143-L145

Added lines #L143 - L145 were not covered by tests
}

/// Handles requests to an agent.
Expand Down Expand Up @@ -255,6 +260,13 @@
RequestCode::EchoRequest => {
send_response(send, &mut buf, handler.echo_request().await).await?;
}
RequestCode::TrustedUserAgentList => {
let user_agent_list = codec
.deserialize::<Vec<&str>>(body)
.map_err(frame::RecvError::DeserializationFailure)?;
let result = handler.trusted_user_agent_list(&user_agent_list).await;
send_response(send, &mut buf, result).await?;
}
RequestCode::ReloadFilterRule => {
let rules = codec
.deserialize::<Vec<IpNet>>(body)
Expand Down Expand Up @@ -320,6 +332,7 @@
allow_list: usize,
block_list: usize,
echo_request_count: usize,
trusted_user_agents: usize,
}

#[async_trait]
Expand Down Expand Up @@ -368,6 +381,11 @@
self.echo_request_count += 1;
Ok(())
}

async fn trusted_user_agent_list(&mut self, list: &[&str]) -> Result<(), String> {
self.trusted_user_agents = list.len();
Ok(())
}
}

let mut handler = TestHandler::default();
Expand Down Expand Up @@ -480,6 +498,26 @@
.await;
assert!(res.is_ok());

let trusted_user_agent_list: Vec<String> = vec![
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0"
.to_string(),
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113."
.to_string(),
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35"
.to_string(),
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42"
.to_string(),
];
let mut buf = Vec::new();
let res = message::send_request(
&mut channel.client.send,
&mut buf,
RequestCode::TrustedUserAgentList,
trusted_user_agent_list,
)
.await;

Check warning on line 518 in src/request.rs

View check run for this annotation

Codecov / codecov/patch

src/request.rs#L518

Added line #L518 was not covered by tests
assert!(res.is_ok());

channel.client.send.finish().await.unwrap();

assert_eq!(handler.reboot_count, 0);
Expand All @@ -489,6 +527,7 @@
assert_eq!(handler.allow_list, 0);
assert_eq!(handler.block_list, 0);
assert_eq!(handler.echo_request_count, 0);
assert_eq!(handler.trusted_user_agents, 0);
let res = super::handle(
&mut handler,
&mut channel.server.send,
Expand All @@ -503,6 +542,7 @@
assert_eq!(handler.allow_list, 2);
assert_eq!(handler.block_list, 1);
assert_eq!(handler.echo_request_count, 1);
assert_eq!(handler.trusted_user_agents, 4);

frame::recv_raw(&mut channel.client.recv, &mut buf)
.await
Expand Down
Loading