Commit 75b41be8 authored by Hiro's avatar Hiro 🏄
Browse files

Add test to check for sanitized contact field

parent 2f9859f2
Pipeline #39006 failed with stage
in 1 minute and 32 seconds
......@@ -129,7 +129,7 @@ public class DetailsStatus extends Document {
public void setContact(String contact) {
if ((contact != null) && (contact.indexOf('%') != -1)) {
contact = contact.replace("%", "%%");
contact = contact.replace("%", "");
}
this.contact = escapeJson(contact);
}
......
......@@ -96,5 +96,46 @@ public class DetailsDocumentWriterTest {
Arrays.asList(GABELMOO_OR_ADDRESS),
document.getUnreachableOrAddresses());
}
}
@Test
public void testContactDetails() {
DetailsStatus status = new DetailsStatus();
status.setRelay(true);
status.setAdvertisedOrAddresses(Arrays.asList(GABELMOO_OR_ADDRESS));
status.setOrAddressesAndPorts(new TreeSet<>(Arrays.asList(
GABELMOO_OR_ADDRESS)));
status.setContact("gabelmoo@torproject.org");
this.documentStore.addDocument(status, GABELMOO_FINGERPRINT);
DetailsDocumentWriter writer = new DetailsDocumentWriter();
writer.writeDocuments(-1L);
assertEquals("One document should be written.", 1,
this.documentStore.getPerformedStoreOperations());
DetailsDocument document = this.documentStore.getDocument(
DetailsDocument.class, GABELMOO_FINGERPRINT);
assertNotNull("There should be a document for the given fingerprint.",
document);
assertEquals("gabelmoo@torproject.org",
document.getContact());
}
@Test
public void testContactDetailsWithPercentCharacters() {
DetailsStatus status = new DetailsStatus();
status.setRelay(true);
status.setAdvertisedOrAddresses(Arrays.asList(GABELMOO_OR_ADDRESS));
status.setOrAddressesAndPorts(new TreeSet<>(Arrays.asList(
GABELMOO_OR_ADDRESS)));
status.setContact("gabelmoo%@torproject.org (% 2+6)");
this.documentStore.addDocument(status, GABELMOO_FINGERPRINT);
DetailsDocumentWriter writer = new DetailsDocumentWriter();
writer.writeDocuments(-1L);
assertEquals("One document should be written.", 1,
this.documentStore.getPerformedStoreOperations());
DetailsDocument document = this.documentStore.getDocument(
DetailsDocument.class, GABELMOO_FINGERPRINT);
assertNotNull("There should be a document for the given fingerprint.",
document);
assertEquals("gabelmoo@torproject.org ( 2+6)",
document.getContact());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment