1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.security.token;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotEquals;
22
23 import java.io.UnsupportedEncodingException;
24
25 import javax.crypto.SecretKey;
26
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30 import org.mockito.Mockito;
31
32 @Category(SmallTests.class)
33 public class TestAuthenticationKey {
34
35 @Test
36 public void test() throws UnsupportedEncodingException {
37 SecretKey secret = Mockito.mock(SecretKey.class);
38 Mockito.when(secret.getEncoded()).thenReturn("secret".getBytes("UTF-8"));
39
40 AuthenticationKey key = new AuthenticationKey(0, 1234, secret);
41 assertEquals(key.hashCode(), new AuthenticationKey(0, 1234, secret).hashCode());
42 assertEquals(key, new AuthenticationKey(0, 1234, secret));
43
44 AuthenticationKey otherID = new AuthenticationKey(1, 1234, secret);
45 assertNotEquals(key.hashCode(), otherID.hashCode());
46 assertNotEquals(key, otherID);
47
48 AuthenticationKey otherExpiry = new AuthenticationKey(0, 8765, secret);
49 assertNotEquals(key.hashCode(), otherExpiry.hashCode());
50 assertNotEquals(key, otherExpiry);
51
52 SecretKey other = Mockito.mock(SecretKey.class);
53 Mockito.when(secret.getEncoded()).thenReturn("other".getBytes("UTF-8"));
54
55 AuthenticationKey otherSecret = new AuthenticationKey(0, 1234, other);
56 assertNotEquals(key.hashCode(), otherSecret.hashCode());
57 assertNotEquals(key, otherSecret);
58 }
59
60 }