Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / lur / test / JU_ConfigPrincipal.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * * ===========================================================================
7  * * Licensed under the Apache License, Version 2.0 (the "License");
8  * * you may not use this file except in compliance with the License.
9  * * You may obtain a copy of the License at
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
13  *  * Unless required by applicable law or agreed to in writing, software
14  * * distributed under the License is distributed on an "AS IS" BASIS,
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * * See the License for the specific language governing permissions and
17  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.cadi.lur.test;
23
24 import org.junit.*;
25 import static org.junit.Assert.*;
26 import static org.hamcrest.CoreMatchers.*;
27 import java.lang.reflect.Field;
28
29 import java.io.IOException;
30
31 import org.onap.aaf.cadi.lur.ConfigPrincipal;
32
33 public class JU_ConfigPrincipal {
34
35     private final String name = "User";
36     private final String pass = "pass";
37
38     // Expected output of base64("User:pass")
39     private final String b64encoded = "VXNlcjpwYXNz";
40
41     private Field content_field;
42     
43     @Before
44     public void setup() throws NoSuchFieldException {
45         content_field = ConfigPrincipal.class.getDeclaredField("content");
46         content_field.setAccessible(true);
47     }
48
49     @Test
50     public void testConfigPrincipalStringString() throws IOException, IllegalArgumentException, IllegalAccessException {
51         ConfigPrincipal p =  new ConfigPrincipal(name, pass);
52         
53         assertThat(p.getName(), is(name));
54         assertThat(p.toString(), is(name));
55         assertThat(p.getCred(), is(pass.getBytes()));
56         assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
57         content_field.set(p, "pass");
58         assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
59
60         // One more time for coverage purposes
61         assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
62     }
63
64     @Test
65     public void testConfigPrincipalStringByteArray() throws IOException, IllegalArgumentException, IllegalAccessException {
66         ConfigPrincipal p =  new ConfigPrincipal(name, pass.getBytes());
67         
68         assertThat(p.getName(), is(name));
69         assertThat(p.toString(), is(name));
70         assertThat(p.getCred(), is(pass.getBytes()));
71         assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
72         content_field.set(p, "pass");
73         assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
74
75         // One more time for coverage purposes
76         assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
77     }
78     
79 }