package com.warrenstrange.googleauth;


import org.junit.Test;

/*
 * Not really a unit test- but it shows usage
 */
public class GoogleAuthTest  {
	
	@Test
	public void genSecretTest() {
		String secret = GoogleAuthenticator.generateSecretKey();
		
		String url = GoogleAuthenticator.getQRBarcodeURL("testuser", "testhost", secret);
		System.out.println("Please register " + url);
		
		System.out.println("Secret key is " + secret);		
	}
	
	
	// Change this to the saved secret from the running the above test. 
	static String savedSecret = "74FRHJTV4VC2BC72";
	
	@Test 
	public void authTest()  {	
		// enter the code shown on device. Edit this and run it fast before the code expires!
		long code =  437167 ;
		long t = System.currentTimeMillis();
		GoogleAuthenticator ga = new GoogleAuthenticator();
		ga.setWindowSize(5);  //should give 5 * 30 seconds of grace...
		
		boolean r = ga.check_code(savedSecret, code, t);
		
		System.out.println("Check code = " + r);		
	}
		

}

@@ -142,21 +142,25 @@
 est 
- 
 %7B%0A
-%09%0A%09
+%0A    
 @Test%0A
-%09
+    
 publ
@@ -189,25 +189,85 @@
 ) %7B%0A
-%09%09String secret =
+        GoogleAuthenticator gauth = new GoogleAuthenticator();%0A%0A        final
  Goo
@@ -282,16 +282,31 @@
 nticator
+Key key = gauth
 .generat
@@ -319,21 +319,69 @@
 tKey();%0A
-%09%09%0A%09%09
+        final String secret = key.getKey();%0A%0A        
 String u
@@ -404,16 +404,19 @@
 nticator
+Key
 .getQRBa
@@ -457,18 +457,25 @@
 ecret);%0A
-%09%09
+%0A        
 System.o
@@ -512,21 +512,24 @@
 + url);%0A
-%09%09%0A%09%09
+        
 System.o
@@ -570,19 +570,21 @@
 et);
-%09%09%0A%09%7D%0A%09%0A%09%0A%09
+%0A    %7D%0A%0A%0A    
 // C
@@ -646,19 +646,21 @@
 ve test.
- %0A%09
+%0A    
 static S
@@ -684,38 +684,42 @@
  = %22
-74FRHJTV4VC2BC72%22;%0A%09%0A%09@Test %0A%09
+VV5OVNP4S42DQSS3%22;%0A%0A    @Test%0A    
 publ
@@ -741,14 +741,18 @@
 t() 
- %7B%09%0A%09%09
+%7B%0A        
 // e
@@ -837,73 +837,44 @@
 es!%0A
-%09%09long code =  437167 ;%0A%09%09long t = System.currentTimeMillis();%0A%09%09
+        int code = 863311;%0A%0A        
 Goog
@@ -921,18 +921,24 @@
 ator();%0A
-%09%09
+        
 ga.setWi
@@ -992,21 +992,25 @@
 race...%0A
-%09%09%0A%09%09
+%0A        
 boolean 
@@ -1020,17 +1020,16 @@
  ga.
-check_cod
+authoriz
 e(sa
@@ -1047,19 +1047,20 @@
 code
-, t);%0A%09%09%0A%09%09
+);%0A%0A        
 Syst
@@ -1099,16 +1099,15 @@
  r);
-%09%09%0A%09%7D%0A%09%09
+%0A    %7D%0A
 %0A%0A%7D%0A

Refactor the existing tests.