package edu.mit.anonauth;

import static org.junit.Assert.*;

import org.junit.Test;

public class ProtocolTest {
	
    @Test
    public void testBasicExchange() {
    	int r = 5;
    	int user = 5001;
    	
    	ProtocolDoor door = new ProtocolDoor(r);
    	ProtocolCard card = new ProtocolCard(door.privatePoints(user));
    	assertTrue(exchange(door, card));
    }
    
    @Test
    public void testRevocation() {
    	int r = 5;
    	int user = 5001;
    	
    	ProtocolDoor door = new ProtocolDoor(r);
    	ProtocolCard card = new ProtocolCard(door.privatePoints(user));
    	
    	assertTrue(exchange(door, card));
    	door.revoke(user);
    	assertFalse(exchange(door, card));
    }
    
    @Test
    public void testRevocationMultiUser() {
    	int r = 5;
    	int userA = 5001;
    	int userB = 5002;
    	
    	ProtocolDoor door = new ProtocolDoor(r);
    	ProtocolCard cardA = new ProtocolCard(door.privatePoints(userA));
    	ProtocolCard cardB = new ProtocolCard(door.privatePoints(userB));
    	
    	assertTrue(exchange(door, cardA));
    	assertTrue(exchange(door, cardB));
    	door.revoke(userB);
    	assertTrue(exchange(door, cardA));
    	assertFalse(exchange(door, cardB));
    }
    
    public boolean exchange(ProtocolDoor door, ProtocolCard card) {
    	byte[] broadcast = door.getBroadcast();
    	byte[] response;
    	try {
        	response = card.authenticate(broadcast);
    	} catch (ArithmeticException e) {
    		return false;
    	}
    	return door.checkResponse(response);
    }
}

@@ -55,16 +55,68 @@
 ert.*;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import o
@@ -1251,24 +1251,642 @@
 %0A    %7D%0A    %0A
+    @Test%0A    public void testMultipleRevocation() %7B%0A    %09int r = 50;%0A    %09%0A    %09ProtocolDoor door = new ProtocolDoor(r);%0A    %09%0A    %09List%3CProtocolCard%3E cards = new ArrayList%3CProtocolCard%3E();%0A    %09for (int i = 0; i %3C r; i++) %7B%0A    %09%09int user = r + i + 1;%0A    %09%09cards.add(new ProtocolCard(door.privatePoints(user)));%0A    %09%7D%0A    %09%0A    %09for (int round = 0; round %3C r; round++) %7B%0A    %09%09for (int i = 0; i %3C r; i++) %7B%0A    %09%09%09if (i %3C round) %7B%0A    %09%09%09%09assertFalse(exchange(door, cards.get(i)));%0A    %09%09%09%7D else %7B%0A    %09%09%09%09assertTrue(exchange(door, cards.get(i)));%0A    %09%09%09%7D%0A    %09%09%7D%0A%09%09%09door.revoke(r + round + 1);%0A    %09%7D%0A    %7D%0A    %0A
     public b

Add multiple-revocation protocol test