1 package net.pterodactylus.sone.freenet;
3 import static freenet.support.Base64.encode;
4 import static net.pterodactylus.sone.freenet.Key.from;
5 import static net.pterodactylus.sone.freenet.Key.routingKey;
6 import static org.hamcrest.MatcherAssert.assertThat;
7 import static org.hamcrest.Matchers.is;
9 import java.net.MalformedURLException;
11 import freenet.keys.FreenetURI;
13 import org.junit.Test;
16 * Unit test for {@link Key}.
18 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
20 public class KeyTest {
22 private final FreenetURI uri;
23 private final Key key;
25 public KeyTest() throws MalformedURLException {
27 "SSK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/some-site-12/foo/bar.html");
32 public void keyCanBeCreatedFromFreenetUri() throws MalformedURLException {
33 assertThat(key.getRoutingKey(),
34 is("NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"));
35 assertThat(key.getCryptoKey(),
36 is("Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI"));
37 assertThat(key.getExtra(), is("AQACAAE"));
41 public void keyCanBeConvertedToUsk() throws MalformedURLException {
42 FreenetURI uskUri = key.toUsk("other-site", 15, "some", "path.html");
43 assertThat(uskUri.toString(),
44 is("USK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/other-site/15/some/path.html"));
48 public void keyCanBeConvertedToSskWithoutEdition()
49 throws MalformedURLException {
50 FreenetURI uskUri = key.toSsk("other-site", "some", "path.html");
51 assertThat(uskUri.toString(),
52 is("SSK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/other-site/some/path.html"));
56 public void keyCanBeConvertedToSskWithEdition()
57 throws MalformedURLException {
58 FreenetURI uskUri = key.toSsk("other-site", 15, "some", "path.html");
59 assertThat(uskUri.toString(),
60 is("SSK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/other-site-15/some/path.html"));
64 public void routingKeyIsExtractCorrectly() {
65 assertThat(routingKey(uri),
66 is("NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"));