32ba3eba89d1c64983b0512480cf0037fb1ce2c7
[aaa.git] / aaa-encrypt-service / impl / src / test / java / org / opendaylight / aaa / encrypt / impl / AAAEncryptServiceImplTest.java
1 /*
2  * Copyright (c) 2016, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.aaa.encrypt.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.config.aaa.authn.encrypt.service.config.rev160915.AaaEncryptServiceConfigBuilder;
16
17 /*
18  *  @author - Sharon Aicler (saichler@gmail.com)
19  */
20 @Deprecated
21 public class AAAEncryptServiceImplTest {
22     private AAAEncryptionServiceImpl impl;
23
24     @Before
25     public void setup() {
26         impl = new AAAEncryptionServiceImpl(new EncryptServiceConfigImpl(
27             OSGiEncryptionServiceConfigurator.generateConfig(new AaaEncryptServiceConfigBuilder()
28                 .setCipherTransforms("AES/CBC/PKCS5Padding")
29                 .setEncryptIterationCount(32768)
30                 .setEncryptKey("")
31                 .setEncryptKeyLength(128)
32                 .setEncryptMethod("PBKDF2WithHmacSHA1")
33                 .setEncryptSalt("")
34                 .setEncryptType("AES")
35                 .setPasswordLength(12)
36                 .build())));
37     }
38
39     @Test
40     public void testShortString() {
41         String before = "shortone";
42         String encrypt = impl.encrypt(before);
43         assertNotEquals(before, encrypt);
44         String after = impl.decrypt(encrypt);
45         assertEquals(before, after);
46     }
47
48     @Test
49     public void testLongString() {
50         String before = "This is a very long string to encrypt for testing 1...2...3";
51         String encrypt = impl.encrypt(before);
52         assertNotEquals(before, encrypt);
53         String after = impl.decrypt(encrypt);
54         assertEquals(before, after);
55     }
56 }