1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.hadoop.hbase.io.crypto;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertTrue;
22
23 import java.security.Key;
24
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.HBaseConfiguration;
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.testclassification.SmallTests;
29 import org.apache.hadoop.hbase.io.crypto.aes.AES;
30
31 import org.junit.Test;
32 import org.junit.experimental.categories.Category;
33
34 @Category(SmallTests.class)
35 public class TestKeyProvider {
36
37 @Test
38 public void testTestProvider() {
39 Configuration conf = HBaseConfiguration.create();
40 conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
41 KeyProvider provider = Encryption.getKeyProvider(conf);
42 assertNotNull("Null returned for provider", provider);
43 assertTrue("Provider is not the expected type", provider instanceof KeyProviderForTesting);
44
45 Key key = provider.getKey("foo");
46 assertNotNull("Test provider did not return a key as expected", key);
47 assertEquals("Test provider did not create a key for AES", key.getAlgorithm(), "AES");
48 assertEquals("Test provider did not create a key of adequate length",
49 key.getEncoded().length, AES.KEY_LENGTH);
50 }
51
52 }