Extract out contruction of Web Key Directory URLs

Moves `toWebKeyDirectoryURL` to a separate class adding unit tests
for URL correctness as well as support for spaces at the beginning
and end of the e-mail. Spaces are frequently automatically inserted
by soft keyboards.
This commit is contained in:
Wiktor Kwapisiewicz
2018-05-22 10:01:47 +02:00
parent 090eb7e6e3
commit bc25b345fc
3 changed files with 88 additions and 42 deletions

View File

@@ -0,0 +1,30 @@
package org.sufficientlysecure.keychain.util;
import org.junit.Test;
import java.net.URL;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
public class WebKeyDirectoryUtilTest {
@Test
public void testWkd() {
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL("test-wkd@openkeychain.org");
assertNotNull(url);
assertEquals("openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
}
@Test
public void testWkdWithSpaces() {
URL url = WebKeyDirectoryUtil.toWebKeyDirectoryURL(" test-wkd@openkeychain.org ");
assertNotNull(url);
assertEquals("openkeychain.org", url.getHost());
assertEquals("https", url.getProtocol());
assertEquals("/.well-known/openpgpkey/hu/4hg7tescnttreaouu4z1izeuuyibwww1", url.getPath());
}
}