Skip to content

Commit

Permalink
Merge pull request #83 from icann/dev
Browse files Browse the repository at this point in the history
Release v0.0.18
  • Loading branch information
anewton1998 authored Sep 6, 2024
2 parents 92e1d91 + 706922e commit 707d906
Show file tree
Hide file tree
Showing 72 changed files with 2,839 additions and 758 deletions.
70 changes: 66 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ members = [
resolver = "2"

[workspace.package]
version = "0.0.17"
version = "0.0.18"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/icann/icann-rdap"
keywords = ["whois", "rdap"]

[workspace.dependencies]

# for suffix string searchs
ab-radix-trie = "0.2.1"

# easy error handling
anyhow = "1.0"

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ This repository contains open source code written by the Internet Corporation fo
for use with the Registry Data Access Protocol (RDAP). RDAP is standard of the [IETF](https://ietf.org/), and extensions
to RDAP are a current work activity of the IETF's [REGEXT working group](https://datatracker.ietf.org/wg/regext/documents/).
More information on ICANN's role in RDAP can be found [here](https://www.icann.org/rdap).
General information on RDAP can be found [here](https://rdap.rcode3.com/).

About
-----

This repository hosts 4 separate Rust crates:
This repository hosts 4 separate packages (i.e. Rust crates):

* [icann-rdap-cli](icann-rdap-cli/README.md) is the Command Line Interface client.
* [icann-rdap-cli](icann-rdap-cli/README.md) is the Command Line Interface client. This package produces an executable binary.
* [icann-rdap-client](icann-rdap-client/README.md) is a library handling making RDAP requests.
* [icann-rdap-common](icann-rdap-common/README.md) is a library of RDAP structures.
* [icann-rdap-srv](icann-rdap-srv/README.md) is a simple, in-memory RDAP server.
* [icann-rdap-srv](icann-rdap-srv/README.md) is a simple, in-memory RDAP server. This package produces multiple executable binaries.

License
-------
Expand Down
4 changes: 2 additions & 2 deletions icann-rdap-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ path = "src/main.rs"

[dependencies]

icann-rdap-client = { version = "0.0.17", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.17", path = "../icann-rdap-common" }
icann-rdap-client = { version = "0.0.18", path = "../icann-rdap-client" }
icann-rdap-common = { version = "0.0.18", path = "../icann-rdap-common" }

anyhow.workspace = true
clap.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion icann-rdap-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ by the Internet Corporation for Assigned Names and Numbers [(ICANN)](https://www
RDAP is standard of the [IETF](https://ietf.org/), and extensions
to RDAP are a current work activity of the IETF's [REGEXT working group](https://datatracker.ietf.org/wg/regext/documents/).
More information on ICANN's role in RDAP can be found [here](https://www.icann.org/rdap).
General information on RDAP can be found [here](https://rdap.rcode3.com/).

Installing the RDAP Client
--------------------------
Expand Down Expand Up @@ -79,7 +80,7 @@ Output Format
-------------

By default, the client will attempt to determine the output format of the information. If it determines the shell
is interactive, output will be in `rendered-markdown`. Otherwise the output will be JSON.
is interactive, output will be in `rendered-markdown`. Otherwise, the output will be JSON.

You can explicitly control this behavior using the `-O` command argument or the `RDAP_OUTPUT` environment variable
(see below).
Expand Down
26 changes: 16 additions & 10 deletions icann-rdap-cli/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ async fn do_domain_query<'a, W: std::io::Write>(
let mut transactions = RequestResponses::new();
let base_url = get_base_url(&processing_params.bootstrap_type, client, query_type).await?;
let response = do_request(&base_url, query_type, processing_params, client).await;
let registrar_response;
match response {
Ok(response) => {
let source_host = response.http_data.host.to_owned();
Expand All @@ -106,11 +107,12 @@ async fn do_domain_query<'a, W: std::io::Write>(
if let Some(url) = get_related_link(&response.rdap).first() {
info!("Querying domain name from registrar.");
let query_type = QueryType::Url(url.to_string());
let registrar_response =
let registrar_response_result =
do_request(&base_url, &query_type, processing_params, client).await;
match registrar_response {
Ok(registrar_response) => {
regr_source_host = registrar_response.http_data.host;
match registrar_response_result {
Ok(response_data) => {
registrar_response = response_data;
regr_source_host = registrar_response.http_data.host.to_owned();
regr_req_data = RequestData {
req_number: 2,
source_host: &regr_source_host,
Expand All @@ -119,7 +121,7 @@ async fn do_domain_query<'a, W: std::io::Write>(
transactions = do_output(
processing_params,
&regr_req_data,
&response,
&registrar_response,
write,
transactions,
)?;
Expand Down Expand Up @@ -363,18 +365,22 @@ fn get_related_link(rdap_response: &RdapResponse) -> Vec<&str> {
let urls: Vec<&str> = links
.iter()
.filter(|l| {
if let Some(rel) = &l.rel {
if let Some(media_type) = &l.media_type {
rel.eq_ignore_ascii_case("related")
&& media_type.eq_ignore_ascii_case(RDAP_MEDIA_TYPE)
if l.href.as_ref().is_some() {
if let Some(rel) = &l.rel {
if let Some(media_type) = &l.media_type {
rel.eq_ignore_ascii_case("related")
&& media_type.eq_ignore_ascii_case(RDAP_MEDIA_TYPE)
} else {
false
}
} else {
false
}
} else {
false
}
})
.map(|l| l.href.as_str())
.map(|l| l.href.as_ref().unwrap().as_str())
.collect::<Vec<&str>>();
urls
} else {
Expand Down
42 changes: 22 additions & 20 deletions icann-rdap-cli/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,35 @@ pub(crate) async fn do_request(
let response = rdap_url_request(&query_url, client).await?;
if !processing_params.no_cache {
if let Some(self_link) = response.rdap.get_self_link() {
if response.http_data.should_cache() {
let data = serde_json::to_string_pretty(&response)?;
let cache_contents = response.http_data.to_lines(&data)?;
let query_url = query_type.query_url(base_url)?;
let file_name = format!(
"{}.cache",
PctString::encode(query_url.chars(), URIReserved)
);
debug!("Saving response to cache file {file_name}");
let path = rdap_cache_path().join(file_name);
fs::write(path, &cache_contents)?;
if query_url != self_link.href {
if let Some(self_link_href) = &self_link.href {
if response.http_data.should_cache() {
let data = serde_json::to_string_pretty(&response)?;
let cache_contents = response.http_data.to_lines(&data)?;
let query_url = query_type.query_url(base_url)?;
let file_name = format!(
"{}.cache",
PctString::encode(self_link.href.chars(), URIReserved)
PctString::encode(query_url.chars(), URIReserved)
);
debug!("Saving response to cache file {file_name}");
let path = rdap_cache_path().join(file_name);
fs::write(path, &cache_contents)?;
if query_url != *self_link_href {
let file_name = format!(
"{}.cache",
PctString::encode(self_link_href.chars(), URIReserved)
);
debug!("Saving response to cache file {file_name}");
let path = rdap_cache_path().join(file_name);
fs::write(path, &cache_contents)?;
}
} else {
debug!("Not caching data according to server policy.");
debug!("Expires header: {:?}", &response.http_data.expires);
debug!(
"Cache-control header: {:?}",
&response.http_data.cache_control
);
}
} else {
debug!("Not caching data according to server policy.");
debug!("Expires header: {:?}", &response.http_data.expires);
debug!(
"Cache-control header: {:?}",
&response.http_data.cache_control
);
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions icann-rdap-cli/tests/integration/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,21 @@ async fn GIVEN_idn_WHEN_query_a_label_THEN_success() {
let assert = test_jig.cmd.assert();
assert.success();
}

#[tokio::test(flavor = "multi_thread")]
async fn GIVEN_domain_WHEN_search_domain_names_THEN_success() {
// GIVEN
let mut test_jig = TestJig::new_with_enable_domain_name_search().await;
let mut tx = test_jig.mem.new_tx().await.expect("new transaction");
tx.add_domain(&Domain::basic().ldh_name("foo.example").build())
.await
.expect("add domain in tx");
tx.commit().await.expect("tx commit");

// WHEN
test_jig.cmd.arg("-t").arg("domain-name").arg("foo.*");

// THEN
let assert = test_jig.cmd.assert();
assert.success();
}
16 changes: 15 additions & 1 deletion icann-rdap-cli/tests/integration/test_jig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use assert_cmd::Command;
use icann_rdap_srv::config::ListenConfig;
use icann_rdap_srv::server::AppState;
use icann_rdap_srv::server::Listener;
use icann_rdap_srv::storage::mem::config::MemConfig;
use icann_rdap_srv::storage::mem::ops::Mem;
use icann_rdap_srv::storage::CommonConfig;
use std::time::Duration;
use test_dir::DirBuilder;
use test_dir::FileType;
Expand All @@ -18,7 +20,19 @@ pub struct TestJig {

impl TestJig {
pub async fn new() -> TestJig {
let mem = Mem::default();
let common_config = CommonConfig::default();
TestJig::new_common_config(common_config).await
}

pub async fn new_with_enable_domain_name_search() -> TestJig {
let common_config = CommonConfig::builder()
.domain_search_by_name_enable(true)
.build();
TestJig::new_common_config(common_config).await
}

pub async fn new_common_config(common_config: CommonConfig) -> TestJig {
let mem = Mem::new(MemConfig::builder().common_config(common_config).build());
let app_state = AppState {
storage: mem.clone(),
bootstrap: false,
Expand Down
2 changes: 1 addition & 1 deletion icann-rdap-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An RDAP client library.

[dependencies]

icann-rdap-common = { version = "0.0.17", path = "../icann-rdap-common" }
icann-rdap-common = { version = "0.0.18", path = "../icann-rdap-common" }

buildstructor.workspace = true
cidr-utils.workspace = true
Expand Down
Loading

0 comments on commit 707d906

Please sign in to comment.