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

addresses issue #41 #45

Merged
merged 1 commit into from
Dec 14, 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
1 change: 1 addition & 0 deletions icann-rdap-client/src/md/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pub(crate) fn events_to_table(
let event_date = &event
.event_date
.to_owned()
.unwrap_or("????".to_string())
.format_date_time(params)
.unwrap_or_default();
let mut ul: Vec<&String> = vec![event_date];
Expand Down
6 changes: 6 additions & 0 deletions icann-rdap-common/src/check/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl CheckItem {
}

// Events
pub fn event_date_is_absent() -> CheckItem {
CheckItem {
check_class: CheckClass::SpecificationError,
check: Check::EventDateIsAbsent,
}
}
pub fn event_date_is_not_rfc3339() -> CheckItem {
CheckItem {
check_class: CheckClass::SpecificationError,
Expand Down
2 changes: 2 additions & 0 deletions icann-rdap-common/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ pub enum Check {
EmptyDomainVariant,

// Events
#[strum(message = "event date is absent")]
EventDateIsAbsent,
#[strum(message = "event date is not RFC 3339 compliant")]
EventDateIsNotRfc3339,

Expand Down
83 changes: 78 additions & 5 deletions icann-rdap-common/src/check/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,19 @@ impl GetSubChecks for ObjectCommon {
// events
if let Some(events) = &self.events {
events.iter().for_each(|e| {
let date = DateTime::parse_from_rfc3339(&e.event_date);
if date.is_err() {
if let Some(date) = &e.event_date {
let date = DateTime::parse_from_rfc3339(date);
if date.is_err() {
sub_checks.push(Checks {
struct_name: "Events",
items: vec![CheckItem::event_date_is_not_rfc3339()],
sub_checks: Vec::new(),
})
}
} else {
sub_checks.push(Checks {
struct_name: "Links",
items: vec![CheckItem::event_date_is_not_rfc3339()],
struct_name: "Events",
items: vec![CheckItem::event_date_is_absent()],
sub_checks: Vec::new(),
})
}
Expand Down Expand Up @@ -265,7 +273,7 @@ mod tests {
domain::Domain,
entity::Entity,
nameserver::Nameserver,
types::{Common, Extension, Link, ObjectCommon, StatusValue},
types::{Common, Event, Extension, Link, ObjectCommon, StatusValue},
RdapResponse,
};

Expand Down Expand Up @@ -547,6 +555,71 @@ mod tests {
.expect("link missing check");
}

#[test]
fn GIVEN_event_with_no_date_WHEN_checked_THEN_event_date_absent() {
// GIVEN
let rdap = RdapResponse::Domain(
Domain::builder()
.common(Common::builder().build())
.object_common(
ObjectCommon::domain()
.events(vec![Event::builder().event_action("foo").build()])
.build(),
)
.build(),
);

// WHEN
let checks = rdap.get_checks(CheckParams {
do_subchecks: true,
root: &rdap,
parent_type: rdap.get_type(),
});

// THEN
checks
.sub("Events")
.expect("Events not found")
.items
.iter()
.find(|c| c.check == Check::EventDateIsAbsent)
.expect("event missing check");
}

#[test]
fn GIVEN_event_with_bad_date_WHEN_checked_THEN_event_date_is_not_date() {
// GIVEN
let rdap = RdapResponse::Domain(
Domain::builder()
.common(Common::builder().build())
.object_common(
ObjectCommon::domain()
.events(vec![Event::builder()
.event_action("foo")
.event_date("bar")
.build()])
.build(),
)
.build(),
);

// WHEN
let checks = rdap.get_checks(CheckParams {
do_subchecks: true,
root: &rdap,
parent_type: rdap.get_type(),
});

// THEN
checks
.sub("Events")
.expect("Events not found")
.items
.iter()
.find(|c| c.check == Check::EventDateIsNotRfc3339)
.expect("event missing check");
}

#[test]
fn GIVEN_nameserver_with_no_links_WHEN_checked_THEN_no_object_classes_should_have_self_link() {
// GIVEN
Expand Down
7 changes: 6 additions & 1 deletion icann-rdap-common/src/response/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ pub struct Event {
#[serde(skip_serializing_if = "Option::is_none")]
pub event_actor: Option<String>,

/// This value is required by RFC 9083 (and 7483),
/// however some servers don't include it. Therefore
/// it is optional here to be compatible with these
/// types of non-compliant servers.
#[serde(rename = "eventDate")]
pub event_date: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub event_date: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Links>,
Expand Down