PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/facebook-java-api/src/test/java/com/google/code/facebookapi/HashTest.java

http://facebook-java-api.googlecode.com/
Java | 59 lines | 45 code | 14 blank | 0 comment | 0 complexity | 001f2cc1ec17a88af24d1aba419fc7bd MD5 | raw file
 1package com.google.code.facebookapi;
 2
 3import static junit.framework.Assert.assertEquals;
 4
 5import java.util.SortedMap;
 6import java.util.TreeMap;
 7
 8import org.apache.log4j.Logger;
 9import org.junit.Test;
10
11public class HashTest {
12
13	protected static Logger logger = Logger.getLogger( HashTest.class );
14
15	@Test
16	public void test_emailHash() {
17		String email = "mary@example.com";
18		String expectedHash = "4228600737_c96da02bba97aedfd26136e980ae3761";
19		String hash = FacebookSignatureUtil.generateEmailHash( email );
20		assertEquals( expectedHash, hash );
21	}
22
23	@Test
24	public void test_Sig() {
25		SortedMap<String,String> paramsA = new TreeMap<String,String>();
26		paramsA.put( "aA", "aA" );
27		paramsA.put( "bB", "bB" );
28		paramsA.put( "cC", "cC" );
29
30		String expectedBaseString = "aA=aAbB=bBcC=cC";
31		StringBuilder baseString = FacebookSignatureUtil.generateBaseString( paramsA );
32		assertEquals( expectedBaseString, baseString.toString() );
33
34		String secret = "secret";
35		String expectedSignature = "9376fd922ce506221cc1b3892ddca0b9";
36		String sig = FacebookSignatureUtil.generateSignature( paramsA, secret );
37		assertEquals( expectedSignature, sig );
38	}
39
40	@Test
41	public void test_FbSig() {
42		SortedMap<String,String> paramsA = new TreeMap<String,String>();
43		paramsA.put( "aA", "aA" );
44		paramsA.put( "bB", "bB" );
45		paramsA.put( "cC", "cC" );
46
47		String secret = "secret";
48		SortedMap<String,String> paramsB = new TreeMap<String,String>();
49		paramsB.put( "fb_sig_aA", "aA" );
50		paramsB.put( "fb_sig_bB", "bB" );
51		paramsB.put( "fb_sig_cC", "cC" );
52		paramsB.put( "fb_sig", "9376fd922ce506221cc1b3892ddca0b9" );
53
54		SortedMap<String,String> paramsC = FacebookSignatureUtil.getVerifiedParams( "fb_sig", paramsB, secret );
55
56		assertEquals( paramsA, paramsC );
57	}
58
59}