Skip to content

Commit c4adfcc

Browse files
authored
Merge pull request #123 from icann/andy_dev
Fix #122
2 parents b7128fb + 4d3a034 commit c4adfcc

File tree

1 file changed

+193
-15
lines changed

1 file changed

+193
-15
lines changed

icann-rdap-client/src/rdap/qtype.rs

Lines changed: 193 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl QueryType {
122122
Self::DomainNsIpSearch(value) => {
123123
search_query(&value.to_string(), "domains?nsIp", base_url)
124124
}
125-
Self::NameserverNameSearch(value) => search_query(value, "nameserver?name=", base_url),
125+
Self::NameserverNameSearch(value) => search_query(value, "nameservers?name", base_url),
126126
Self::NameserverIpSearch(value) => {
127127
search_query(&value.to_string(), "nameservers?ip", base_url)
128128
}
@@ -294,7 +294,6 @@ fn is_nameserver(text: &str) -> bool {
294294
}
295295

296296
#[cfg(test)]
297-
#[allow(non_snake_case)]
298297
mod tests {
299298
use std::str::FromStr;
300299

@@ -303,7 +302,7 @@ mod tests {
303302
use super::*;
304303

305304
#[test]
306-
fn GIVEN_ipv4_WHEN_query_type_from_str_THEN_query_is_ipv4() {
305+
fn test_ipv4_query_type_from_str() {
307306
// GIVEN
308307
let s = "129.129.1.1";
309308

@@ -315,7 +314,7 @@ mod tests {
315314
}
316315

317316
#[test]
318-
fn GIVEN_ipv6_WHEN_query_type_from_str_THEN_query_is_ipv6() {
317+
fn test_ipv6_query_type_from_str() {
319318
// GIVEN
320319
let s = "2001::1";
321320

@@ -327,7 +326,7 @@ mod tests {
327326
}
328327

329328
#[test]
330-
fn GIVEN_ipv4_cidr_WHEN_query_type_from_str_THEN_query_is_ipv4_cidr() {
329+
fn test_ipv4_cidr_query_type_from_str() {
331330
// GIVEN
332331
let s = "129.129.1.1/8";
333332

@@ -339,7 +338,7 @@ mod tests {
339338
}
340339

341340
#[test]
342-
fn GIVEN_ipv6_cidr_WHEN_query_type_from_str_THEN_query_is_ipv6_cidr() {
341+
fn test_ipv6_cidr_query_type_from_str() {
343342
// GIVEN
344343
let s = "2001::1/20";
345344

@@ -351,7 +350,7 @@ mod tests {
351350
}
352351

353352
#[test]
354-
fn GIVEN_number_WHEN_query_type_from_str_THEN_query_is_autnum() {
353+
fn test_number_query_type_from_str() {
355354
// GIVEN
356355
let s = "16509";
357356

@@ -363,7 +362,7 @@ mod tests {
363362
}
364363

365364
#[test]
366-
fn GIVEN_as_followed_by_number_WHEN_query_type_from_str_THEN_query_is_autnum() {
365+
fn test_as_followed_by_number_query_type_from_str() {
367366
// GIVEN
368367
let s = "as16509";
369368

@@ -380,7 +379,7 @@ mod tests {
380379
#[case("snark.fail")]
381380
#[case("ns.fail")]
382381
#[case(".com")]
383-
fn GIVEN_domain_name_WHEN_query_type_from_str_THEN_query_is_domain(#[case] input: &str) {
382+
fn test_domain_name_query_type_from_str(#[case] input: &str) {
384383
// GIVEN case input
385384

386385
// WHEN
@@ -394,7 +393,7 @@ mod tests {
394393
#[case("ns.example.com")]
395394
#[case("ns1.example.com")]
396395
#[case("NS1.example.com")]
397-
fn GIVEN_name_server_WHEN_query_type_from_str_THEN_query_is_nameserver(#[case] input: &str) {
396+
fn test_name_server_query_type_from_str(#[case] input: &str) {
398397
// GIVEN case input
399398

400399
// WHEN
@@ -405,7 +404,7 @@ mod tests {
405404
}
406405

407406
#[test]
408-
fn GIVEN_single_word_WHEN_query_type_from_str_THEN_query_is_entity() {
407+
fn test_single_word_query_type_from_str() {
409408
// GIVEN
410409
let s = "foo";
411410

@@ -420,7 +419,7 @@ mod tests {
420419
#[rstest]
421420
#[case("https://example.com")]
422421
#[case("http://foo.example.com")]
423-
fn GIVEN_url_WHEN_query_type_from_str_THEN_query_is_url(#[case] input: &str) {
422+
fn test_url_query_type_from_str(#[case] input: &str) {
424423
// GIVEN case input
425424

426425
// WHEN
@@ -433,7 +432,7 @@ mod tests {
433432
#[rstest]
434433
#[case("ns.foo_bar.com")]
435434
#[case("ns.foo bar.com")]
436-
fn GIVEN_bad_input_WHEN_query_type_from_str_THEN_error(#[case] input: &str) {
435+
fn test_bad_input_query_type_from_str(#[case] input: &str) {
437436
// GIVEN case input
438437

439438
// WHEN
@@ -454,14 +453,193 @@ mod tests {
454453
#[case("10/24", "10.0.0.0/24")]
455454
#[case("129.129.1.1/8", "129.0.0.0/8")]
456455
#[case("2001::1/32", "2001::/32")]
457-
fn GIVEN_cidr_WHEN_parse_cidr_THEN_error(#[case] actual: &str, #[case] expected: &str) {
456+
fn test_cidr_parse_cidr(#[case] actual: &str, #[case] expected: &str) {
458457
// GIVEN case input
459458

460459
// WHEN
461-
462460
let q = parse_cidr(actual);
463461

464462
// THEN
465463
assert_eq!(q.unwrap().to_string(), expected)
466464
}
465+
466+
#[test]
467+
fn test_ipv4addr_query_url() {
468+
// GIVEN ipv4 addr query
469+
let q = QueryType::from_str("199.1.1.1").expect("query type");
470+
471+
// WHEN
472+
let actual = q.query_url("https://example.com").expect("query url");
473+
474+
// THEN
475+
assert_eq!(actual, "https://example.com/ip/199.1.1.1")
476+
}
477+
478+
#[test]
479+
fn test_ipv6addr_query_url() {
480+
// GIVEN
481+
let q = QueryType::from_str("2000::1").expect("query type");
482+
483+
// WHEN
484+
let actual = q.query_url("https://example.com").expect("query url");
485+
486+
// THEN
487+
assert_eq!(actual, "https://example.com/ip/2000%3A%3A1")
488+
}
489+
490+
#[test]
491+
fn test_ipv4cidr_query_url() {
492+
// GIVEN
493+
let q = QueryType::from_str("199.1.1.1/16").expect("query type");
494+
495+
// WHEN
496+
let actual = q.query_url("https://example.com").expect("query url");
497+
498+
// THEN
499+
assert_eq!(actual, "https://example.com/ip/199.1.0.0/16")
500+
}
501+
502+
#[test]
503+
fn test_ipv6cidr_query_url() {
504+
// GIVEN
505+
let q = QueryType::from_str("2000::1/16").expect("query type");
506+
507+
// WHEN
508+
let actual = q.query_url("https://example.com").expect("query url");
509+
510+
// THEN
511+
assert_eq!(actual, "https://example.com/ip/2000%3A%3A/16")
512+
}
513+
514+
#[test]
515+
fn test_autnum_query_url() {
516+
// GIVEN
517+
let q = QueryType::from_str("as16509").expect("query type");
518+
519+
// WHEN
520+
let actual = q.query_url("https://example.com").expect("query url");
521+
522+
// THEN
523+
assert_eq!(actual, "https://example.com/autnum/16509")
524+
}
525+
526+
#[test]
527+
fn test_domain_query_url() {
528+
// GIVEN
529+
let q = QueryType::from_str("example.com").expect("query type");
530+
531+
// WHEN
532+
let actual = q.query_url("https://example.com").expect("query url");
533+
534+
// THEN
535+
assert_eq!(actual, "https://example.com/domain/example.com")
536+
}
537+
538+
#[test]
539+
fn test_ns_query_url() {
540+
// GIVEN
541+
let q = QueryType::from_str("ns.example.com").expect("query type");
542+
543+
// WHEN
544+
let actual = q.query_url("https://example.com").expect("query url");
545+
546+
// THEN
547+
assert_eq!(actual, "https://example.com/nameserver/ns.example.com")
548+
}
549+
550+
#[test]
551+
fn test_entity_query_url() {
552+
// GIVEN
553+
let q = QueryType::from_str("foo").expect("query type");
554+
555+
// WHEN
556+
let actual = q.query_url("https://example.com").expect("query url");
557+
558+
// THEN
559+
assert_eq!(actual, "https://example.com/entity/foo")
560+
}
561+
562+
#[test]
563+
fn test_entity_name_search_query_url() {
564+
// GIVEN
565+
let q = QueryType::EntityNameSearch("foo".to_string());
566+
567+
// WHEN
568+
let actual = q.query_url("https://example.com").expect("query url");
569+
570+
// THEN
571+
assert_eq!(actual, "https://example.com/entities?fn=foo")
572+
}
573+
574+
#[test]
575+
fn test_entity_handle_search_query_url() {
576+
// GIVEN
577+
let q = QueryType::EntityHandleSearch("foo".to_string());
578+
579+
// WHEN
580+
let actual = q.query_url("https://example.com").expect("query url");
581+
582+
// THEN
583+
assert_eq!(actual, "https://example.com/entities?handle=foo")
584+
}
585+
586+
#[test]
587+
fn test_domain_name_search_query_url() {
588+
// GIVEN
589+
let q = QueryType::DomainNameSearch("foo".to_string());
590+
591+
// WHEN
592+
let actual = q.query_url("https://example.com").expect("query url");
593+
594+
// THEN
595+
assert_eq!(actual, "https://example.com/domains?name=foo")
596+
}
597+
598+
#[test]
599+
fn test_domain_ns_name_search_query_url() {
600+
// GIVEN
601+
let q = QueryType::DomainNsNameSearch("foo".to_string());
602+
603+
// WHEN
604+
let actual = q.query_url("https://example.com").expect("query url");
605+
606+
// THEN
607+
assert_eq!(actual, "https://example.com/domains?nsLdhName=foo")
608+
}
609+
610+
#[test]
611+
fn test_domain_ns_ip_search_query_url() {
612+
// GIVEN
613+
let q = QueryType::DomainNsIpSearch(IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1)));
614+
615+
// WHEN
616+
let actual = q.query_url("https://example.com").expect("query url");
617+
618+
// THEN
619+
assert_eq!(actual, "https://example.com/domains?nsIp=1.1.1.1")
620+
}
621+
622+
#[test]
623+
fn test_ns_name_search_query_url() {
624+
// GIVEN
625+
let q = QueryType::NameserverNameSearch("foo".to_string());
626+
627+
// WHEN
628+
let actual = q.query_url("https://example.com").expect("query url");
629+
630+
// THEN
631+
assert_eq!(actual, "https://example.com/nameservers?name=foo")
632+
}
633+
634+
#[test]
635+
fn test_ns_ip_search_query_url() {
636+
// GIVEN
637+
let q = QueryType::NameserverIpSearch(IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1)));
638+
639+
// WHEN
640+
let actual = q.query_url("https://example.com").expect("query url");
641+
642+
// THEN
643+
assert_eq!(actual, "https://example.com/nameservers?ip=1.1.1.1")
644+
}
467645
}

0 commit comments

Comments
 (0)