Skip to content

Commit 518982f

Browse files
authored
Fix blank email validation (#591)
1 parent 9012d10 commit 518982f

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Add endpoints to fetch files as base64 for identity, contacts, companies and bills
44
* Add option to remove files for identity, contacts and companies - if the file upload id in the payload is missing, it's ignored, if it's explicitly set to undefined, the file is removed
5+
* Fix blank email validation for contacts and identities
56

67
# 0.4.2
78

crates/bcr-ebill-core/src/contact/validation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ pub fn validate_create_contact(
2525
// only node id and name need to be set
2626
}
2727
ContactType::Person | ContactType::Company => {
28-
// email and address need to be set
28+
// email and address need to be set and not blank
2929
if let Some(pa) = postal_address {
3030
pa.validate()?;
3131
} else {
3232
return Err(ValidationError::FieldEmpty(Field::Address));
3333
}
34-
if email.is_none() {
34+
35+
if let Some(set_email) = email {
36+
if set_email.trim().is_empty() {
37+
return Err(ValidationError::FieldEmpty(Field::Email));
38+
}
39+
} else {
3540
return Err(ValidationError::FieldEmpty(Field::Email));
3641
}
3742
util::validate_file_upload_id(avatar_file_upload_id.as_deref())?;
@@ -99,6 +104,7 @@ mod tests {
99104
#[case::invalid_node_id(ContactType::Anon, node_id_regtest(), "some name", &None, &None, &None, &None, ValidationError::InvalidNodeId)]
100105
#[case::invalid_name(ContactType::Anon, node_id_test(), "", &None, &None, &None, &None, ValidationError::FieldEmpty(Field::Name))]
101106
#[case::invalid_email(ContactType::Person, node_id_test(), "some name", &None, &Some(valid_address()), &None, &None, ValidationError::FieldEmpty(Field::Email))]
107+
#[case::invalid_email_blank(ContactType::Person, node_id_test(), "some name", &Some("".into()), &Some(valid_address()), &None, &None, ValidationError::FieldEmpty(Field::Email))]
102108
#[case::invalid_address(ContactType::Person, node_id_test(), "some name", &Some("[email protected]".into()), &None, &None, &None, ValidationError::FieldEmpty(Field::Address))]
103109
#[case::blank_city(ContactType::Person, node_id_test(), "some name", &Some("[email protected]".into()), &Some(PostalAddress { city: "".into(), ..valid_address()}), &None, &None, ValidationError::FieldEmpty(Field::City))]
104110
#[case::blank_country(ContactType::Person, node_id_test(), "some name", &Some("[email protected]".into()), &Some(PostalAddress { country: "".into(), ..valid_address()}), &None, &None, ValidationError::FieldEmpty(Field::Country))]

crates/bcr-ebill-core/src/identity/validation.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ pub fn validate_create_identity(
1919
// only node id and name need to be set
2020
}
2121
IdentityType::Ident => {
22-
// email needs to be set
23-
if email.is_none() {
22+
// email needs to be set and not blank
23+
if let Some(set_email) = email {
24+
if set_email.trim().is_empty() {
25+
return Err(ValidationError::FieldEmpty(Field::Email));
26+
}
27+
} else {
2428
return Err(ValidationError::FieldEmpty(Field::Email));
2529
}
2630
postal_address.validate()?;
@@ -85,6 +89,7 @@ mod tests {
8589
#[rstest]
8690
#[case::invalid_name(IdentityType::Anon, "", &None, &OptionalPostalAddress::empty(), &None, &None, ValidationError::FieldEmpty(Field::Name))]
8791
#[case::ident_no_email(IdentityType::Ident, "some name", &None, &OptionalPostalAddress::empty(), &None, &None, ValidationError::FieldEmpty(Field::Email))]
92+
#[case::ident_blank_email(IdentityType::Ident, "some name", &Some("".into()), &OptionalPostalAddress::empty(), &None, &None, ValidationError::FieldEmpty(Field::Email))]
8893
#[case::ident_blank_address(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: None, city: None, zip: None, address: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Address))]
8994
#[case::ident_blank_city(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { country: None, address: None, zip: None, city: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::City))]
9095
#[case::ident_blank_country(IdentityType::Ident, "some name", &Some("[email protected]".into()), &OptionalPostalAddress { address: None, city: None, zip: None, country: Some("".into()) }, &None, &None, ValidationError::FieldEmpty(Field::Country))]

0 commit comments

Comments
 (0)