mirror of https://github.com/shred/acme4j
Do not accept contacts with multiple email addresses
parent
f36294eabd
commit
a32c7bac03
|
@ -23,6 +23,7 @@ import java.security.PublicKey;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
|
@ -44,6 +45,8 @@ import org.slf4j.LoggerFactory;
|
||||||
public class AccountBuilder {
|
public class AccountBuilder {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AccountBuilder.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AccountBuilder.class);
|
||||||
|
|
||||||
|
private static final Pattern MAIL_PATTERN = Pattern.compile("\\?|@.*,");
|
||||||
|
|
||||||
private List<URI> contacts = new ArrayList<>();
|
private List<URI> contacts = new ArrayList<>();
|
||||||
private Boolean termsOfServiceAgreed;
|
private Boolean termsOfServiceAgreed;
|
||||||
private Boolean onlyExisting;
|
private Boolean onlyExisting;
|
||||||
|
@ -58,6 +61,14 @@ public class AccountBuilder {
|
||||||
* @return itself
|
* @return itself
|
||||||
*/
|
*/
|
||||||
public AccountBuilder addContact(URI contact) {
|
public AccountBuilder addContact(URI contact) {
|
||||||
|
if ("mailto".equalsIgnoreCase(contact.getScheme())) {
|
||||||
|
String address = contact.toString().substring(7);
|
||||||
|
if (MAIL_PATTERN.matcher(address).find()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"multiple recipients or hfields are not allowed: " + contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
contacts.add(contact);
|
contacts.add(contact);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,4 +240,32 @@ public class AccountBuilderTest {
|
||||||
provider.close();
|
provider.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmailAddresses() {
|
||||||
|
AccountBuilder builder = new AccountBuilder();
|
||||||
|
|
||||||
|
builder.addContact("mailto:foo@example.com");
|
||||||
|
|
||||||
|
try {
|
||||||
|
builder.addContact("mailto:foo@example.com,bar@example.com");
|
||||||
|
fail("multiple recipients are accepted");
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
builder.addContact("mailto:foo@example.com?to=bar@example.com");
|
||||||
|
fail("hfields are accepted");
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
builder.addContact("mailto:?to=foo@example.com");
|
||||||
|
fail("hfields are accepted");
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue