Skip to content

Commit

Permalink
Use DummyRandomSource in test
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBab committed Nov 13, 2024
1 parent 44bfc61 commit 02129a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
23 changes: 12 additions & 11 deletions test/freenet/node/NewPacketFormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.Test;

import freenet.crypt.BlockCipher;
import freenet.crypt.DummyRandomSource;
import freenet.crypt.ciphers.Rijndael;
import freenet.io.comm.DMT;
import freenet.io.comm.FreenetInetAddress;
Expand All @@ -33,7 +34,7 @@ public void setUp() {
@Test
public void testEmptyCreation() throws BlockedTooLongException {
NewPacketFormat npf = new NewPacketFormat(null, 0, 0);
PeerMessageQueue pmq = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue pmq = new PeerMessageQueue(new DummyRandomSource(1234));
SessionKey s = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);

NPFPacket p = npf.createPacket(1400, pmq, s, false);
Expand All @@ -44,7 +45,7 @@ public void testEmptyCreation() throws BlockedTooLongException {
public void testAckOnlyCreation() throws BlockedTooLongException, InterruptedException {
BasePeerNode pn = new NullBasePeerNode();
NewPacketFormat npf = new NewPacketFormat(pn, 0, 0);
PeerMessageQueue pmq = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue pmq = new PeerMessageQueue(new DummyRandomSource(1234));
SessionKey s = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);

NPFPacket p = null;
Expand All @@ -65,10 +66,10 @@ public void testAckOnlyCreation() throws BlockedTooLongException, InterruptedExc
public void testLostLastAck() throws BlockedTooLongException, InterruptedException {
NullBasePeerNode senderNode = new NullBasePeerNode();
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));
NullBasePeerNode receiverNode = new NullBasePeerNode();
NewPacketFormat receiver = new NewPacketFormat(receiverNode, 0, 0);
PeerMessageQueue receiverQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue receiverQueue = new PeerMessageQueue(new DummyRandomSource(1234));
SessionKey senderKey = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);
senderNode.currentKey = senderKey;
SessionKey receiverKey = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);
Expand Down Expand Up @@ -116,7 +117,7 @@ public void testLostLastAck() throws BlockedTooLongException, InterruptedExcepti
public void testOutOfOrderDelivery() throws BlockedTooLongException {
NullBasePeerNode senderNode = new NullBasePeerNode();
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));
NullBasePeerNode receiverNode = new NullBasePeerNode();
NewPacketFormat receiver = new NewPacketFormat(receiverNode, 0, 0);
SessionKey senderKey = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);
Expand All @@ -142,7 +143,7 @@ public void testOutOfOrderDelivery() throws BlockedTooLongException {
public void testReceiveUnknownMessageLength() throws BlockedTooLongException {
NullBasePeerNode senderNode = new NullBasePeerNode();
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));
NullBasePeerNode receiverNode = new NullBasePeerNode();
NewPacketFormat receiver = new NewPacketFormat(receiverNode, 0, 0);
SessionKey senderKey = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);
Expand All @@ -166,7 +167,7 @@ public void testReceiveUnknownMessageLength() throws BlockedTooLongException {
public void testResendAlreadyCompleted() throws BlockedTooLongException, InterruptedException {
NullBasePeerNode senderNode = new NullBasePeerNode();
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));
NullBasePeerNode receiverNode = new NullBasePeerNode();
NewPacketFormat receiver = new NewPacketFormat(receiverNode, 0, 0);
SessionKey senderKey = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1);
Expand Down Expand Up @@ -219,7 +220,7 @@ public SessionKey getCurrentKeyTracker() {

};
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));
NullBasePeerNode receiverNode = new NullBasePeerNode() {

@Override
Expand Down Expand Up @@ -284,7 +285,7 @@ public SessionKey getCurrentKeyTracker() {

};
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));

senderQueue.queueAndEstimateSize(new MessageItem(new byte[128], null, false, null, (short) 0, false, true), 1024);

Expand Down Expand Up @@ -319,7 +320,7 @@ public void handleMessage(Message msg) {

};
NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0);
PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));
NullBasePeerNode receiverNode = new NullBasePeerNode() {

@Override
Expand Down Expand Up @@ -434,7 +435,7 @@ public void testEncryption()
receiverNPF =
new NewPacketFormat(receiverNode, receiverStartSeq, senderStartSeq);

PeerMessageQueue senderQueue = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue senderQueue = new PeerMessageQueue(new DummyRandomSource(1234));

byte[] message = new byte[1024];
random.nextBytes(message);
Expand Down
10 changes: 6 additions & 4 deletions test/freenet/node/PeerMessageQueueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

import org.junit.Test;

import freenet.crypt.DummyRandomSource;

public class PeerMessageQueueTest {
@Test
public void testUrgentTimeEmpty() {
PeerMessageQueue pmq = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue pmq = new PeerMessageQueue(new DummyRandomSource(1234));
assertEquals(Long.MAX_VALUE, pmq.getNextUrgentTime(Long.MAX_VALUE, System.currentTimeMillis()));
}

@Test
public void testUrgentTime() {
PeerMessageQueue pmq = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue pmq = new PeerMessageQueue(new DummyRandomSource(1234));

//Constructor might take some time, so grab a range
long start = System.currentTimeMillis();
Expand All @@ -37,7 +39,7 @@ public void testUrgentTime() {
* it. */
@Test
public void testUrgentTimeQueuedWrong() {
PeerMessageQueue pmq = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue pmq = new PeerMessageQueue(new DummyRandomSource(1234));

//Constructor might take some time, so grab a range
long start = System.currentTimeMillis();
Expand Down Expand Up @@ -67,7 +69,7 @@ public void testUrgentTimeQueuedWrong() {

@Test
public void testGrabQueuedMessageItem() {
PeerMessageQueue pmq = new PeerMessageQueue(new MersenneTwister(new byte[16]));
PeerMessageQueue pmq = new PeerMessageQueue(new DummyRandomSource(1234));

MessageItem itemUrgent = new MessageItem(new byte[1024], null, false, null, (short) 0, false, false);

Expand Down

0 comments on commit 02129a6

Please sign in to comment.