public void setUp() { // Reset RNG for each test (it's static so not reset by junit). random = new DummyRandomSource(1234); URI = FreenetURI.generateRandomCHK(random); }
System.out.println("Insert/retrieve test"); System.out.println(); DummyRandomSource random = new DummyRandomSource(3142); DummyRandomSource topologyRandom = new DummyRandomSource(3143); waitForPingAverage(0.5, nodes, new DummyRandomSource(3143), MAX_PINGS, 1000); random = new DummyRandomSource(3144);
DummyRandomSource random = new DummyRandomSource(3142); waitForPingAverage(0.98, nodes, new DummyRandomSource(3143), MAX_PINGS, 5000); System.exit(0);
private void setupSone(Sone sone, Class<? extends Identity> identityClass) { Identity identity = mock(identityClass); InsertableClientSSK clientSSK = createRandom(new DummyRandomSource(), "WoT"); when(identity.getRequestUri()).thenReturn(clientSSK.getURI().toString()); when(identity.getId()).thenReturn("identity"); when(sone.getId()).thenReturn("identity"); when(sone.getIdentity()).thenReturn(identity); requestUri = clientSSK.getURI().setKeyType("USK").setDocName("Sone"); when(sone.getRequestUri()).thenAnswer(new Answer<FreenetURI>() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { return requestUri; } }); when(sone.getTime()) .thenReturn(currentTimeMillis() - DAYS.toMillis(1)); }
@Before public void setupSone() { Sone sone = SoneDownloaderTest.this.sone; Identity identity = mock(Identity.class); InsertableClientSSK clientSSK = createRandom(new DummyRandomSource(), "WoT"); when(identity.getRequestUri()).thenReturn(clientSSK.getURI().toString()); when(identity.getId()).thenReturn("identity"); when(sone.getId()).thenReturn("identity"); when(sone.getIdentity()).thenReturn(identity); requestUri = clientSSK.getURI().setKeyType("USK").setDocName("Sone"); when(sone.getRequestUri()).thenAnswer(new Answer<FreenetURI>() { @Override public FreenetURI answer(InvocationOnMock invocation) throws Throwable { return requestUri; } }); when(sone.getTime()).thenReturn(currentTimeMillis() - DAYS.toMillis(1)); }
@Test public void returnedUriHasCorrectDocNameAndMetaStrings() { FreenetURI uri = createRandom(new DummyRandomSource(), "test-0").getURI().uskForSSK(); assertThat(create(uri.toString()).getDocName(), is("Sone")); assertThat(create(uri.toString()).getAllMetaStrings(), is(new String[0])); }
private void testRestart(String password) throws MasterKeysWrongPasswordException, MasterKeysFileSizeException, IOException { File keysFile = new File(base, "test.master.keys"); DummyRandomSource random = new DummyRandomSource(77391); MasterKeys original = MasterKeys.read(keysFile, random, password); byte[] clientCacheMasterKey = original.clientCacheMasterKey; DatabaseKey dkey = original.createDatabaseKey(random); MasterSecret tempfileMasterSecret = original.getPersistentMasterSecret(); MasterKeys restored = MasterKeys.read(keysFile, random, password); assertArrayEquals(clientCacheMasterKey, restored.clientCacheMasterKey); assertEquals(dkey,restored.createDatabaseKey(random)); assertEquals(tempfileMasterSecret, restored.getPersistentMasterSecret()); }
private void testChangePassword(String oldPassword, String newPassword) throws MasterKeysWrongPasswordException, MasterKeysFileSizeException, IOException { File keysFile = new File(base, "test.master.keys"); DummyRandomSource random = new DummyRandomSource(77391); MasterKeys original = MasterKeys.read(keysFile, random, oldPassword); byte[] clientCacheMasterKey = original.clientCacheMasterKey; DatabaseKey dkey = original.createDatabaseKey(random); MasterSecret tempfileMasterSecret = original.getPersistentMasterSecret(); // Change password. original.changePassword(keysFile, newPassword, random); // Now restore. if(!oldPassword.equals(newPassword)) { try { MasterKeys.read(keysFile, random, oldPassword); fail("Old password should not work!"); } catch (MasterKeysWrongPasswordException e) { // Ok. } } MasterKeys restored = MasterKeys.read(keysFile, random, newPassword); assertArrayEquals(clientCacheMasterKey, restored.clientCacheMasterKey); assertEquals(dkey,restored.createDatabaseKey(random)); assertEquals(tempfileMasterSecret, restored.getPersistentMasterSecret()); }
public SplitFileInserterStorageTest() throws IOException { dir = new File("split-file-inserter-storage-test"); dir.mkdir(); executor = new WaitableExecutor(new PooledExecutor()); ticker = new CheatingTicker(executor); RandomSource r = new DummyRandomSource(12345); fg = new FilenameGenerator(r, true, dir, "freenet-test"); persistentFileTracker = new TrivialPersistentFileTracker(dir, fg); bigRAFFactory = new PooledFileRandomAccessBufferFactory(fg, r); smallBucketFactory = new ArrayBucketFactory(); bigBucketFactory = new TempBucketFactory(executor, fg, 0, 0, r, false, 0, null); baseContext = HighLevelSimpleClientImpl.makeDefaultInsertContext(bigBucketFactory, new SimpleEventProducer()); cryptoKey = new byte[32]; r.nextBytes(cryptoKey); checker = new CRCChecksumChecker(); memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 20, executor, NativeThread.JAVA_PRIORITY_RANGE); jobRunner = new DummyJobRunner(executor, null); URI = FreenetURI.generateRandomCHK(r); }
public ClientRequestSelectorTest() throws IOException { dir = new File("split-file-inserter-storage-test"); dir.mkdir(); executor = new WaitableExecutor(new PooledExecutor()); ticker = new CheatingTicker(executor); RandomSource r = new DummyRandomSource(12345); fg = new FilenameGenerator(r, true, dir, "freenet-test"); persistentFileTracker = new TrivialPersistentFileTracker(dir, fg); bigRAFFactory = new PooledFileRandomAccessBufferFactory(fg, r); smallBucketFactory = new ArrayBucketFactory(); bigBucketFactory = new TempBucketFactory(executor, fg, 0, 0, r, false, 0, null); baseContext = HighLevelSimpleClientImpl.makeDefaultInsertContext(bigBucketFactory, new SimpleEventProducer()); cryptoKey = new byte[32]; r.nextBytes(cryptoKey); checker = new CRCChecksumChecker(); memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 20, executor, NativeThread.JAVA_PRIORITY_RANGE); jobRunner = new DummyJobRunner(executor, null); URI = FreenetURI.generateRandomCHK(r); }
CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, saltStore, tracker); cachingStore.start(null, true); RandomSource random = new DummyRandomSource(12345);
@Test public void testFetchPullSingleNode() throws InvalidThresholdException, NodeInitException, InsertException, FetchException, IOException { if(!TestProperty.EXTENSIVE) return; DummyRandomSource random = new DummyRandomSource(25312); final Executor executor = new PooledExecutor(); FileUtil.removeAll(dir); Logger.LogLevel.ERROR, "", true, random); TestNodeParameters params = new TestNodeParameters(); params.random = new DummyRandomSource(253121); params.ramStore = true; params.storeSize = FILE_SIZE * 3;
CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, saltStore, tracker); cachingStore.start(null, true); RandomSource random = new DummyRandomSource(12345);
@Test public void testFetchPullBlobSingleNode() throws InvalidThresholdException, NodeInitException, InsertException, FetchException, IOException, BinaryBlobFormatException { if(!TestProperty.EXTENSIVE) return; DummyRandomSource random = new DummyRandomSource(25312); final Executor executor = new PooledExecutor(); FileUtil.removeAll(dir); Logger.LogLevel.ERROR, "", true, random); TestNodeParameters params = new TestNodeParameters(); params.random = new DummyRandomSource(253121); params.ramStore = true; params.storeSize = FILE_SIZE * 3; params.random = new DummyRandomSource(253121); params.ramStore = true; params.storeSize = FILE_SIZE * 3;
public void testSimpleSSK() throws IOException, KeyCollisionException, SSKVerifyException, KeyDecodeException, SSKEncodeException, InvalidCompressionCodecException { File f = new File(tempDir, "saltstore"); FileUtil.removeAll(f); final int keys = 5; PubkeyStore pk = new PubkeyStore(); new RAMFreenetStore<DSAPublicKey>(pk, keys); GetPubkey pubkeyCache = new SimpleGetPubkey(pk); SSKStore store = new SSKStore(pubkeyCache); SaltedHashFreenetStore<SSKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testSaltedHashFreenetStoreSSK", store, weakPRNG, 20, false, SemiOrderedShutdownHook.get(), true, true, ticker, null); saltStore.start(null, true); RandomSource random = new DummyRandomSource(12345); for(int i=0;i<5;i++) { String test = "test" + i; ClientSSKBlock block = encodeBlockSSK(test, random); SSKBlock sskBlock = (SSKBlock) block.getBlock(); store.put(sskBlock, false, false); ClientSSK key = block.getClientKey(); NodeSSK ssk = (NodeSSK) key.getNodeKey(); pubkeyCache.cacheKey(ssk.getPubKeyHash(), ssk.getPubKey(), false, false, false, false, false); SSKBlock verify = store.fetch(ssk, false, false, false, false, null); String data = decodeBlockSSK(verify, key); assertEquals(test, data); } saltStore.close(); }
CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, saltStore, tracker); cachingStore.start(null, true); RandomSource random = new DummyRandomSource(12345);
private void testRoundTripCrossSegmentDataBlocks(long size) throws IOException, InsertException, MissingKeyException, FetchException, MetadataParseException, Exception { RandomSource r = new DummyRandomSource(12123); LockableRandomAccessBuffer data = generateData(r, size); Bucket dataBucket = new RAFBucket(data);
CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, saltStore, tracker); cachingStore.start(null, true); RandomSource random = new DummyRandomSource(12345);
SaltedHashFreenetStore<SSKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testSaltedHashFreenetStoreOnCloseSSK", store, weakPRNG, 10, true, SemiOrderedShutdownHook.get(), true, true, ticker, null); saltStore.start(null, true); RandomSource random = new DummyRandomSource(12345);
CachingFreenetStore<SSKBlock> cachingStore = new CachingFreenetStore<SSKBlock>(store, saltStore, tracker); cachingStore.start(null, true); RandomSource random = new DummyRandomSource(12345);