1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.cadi.test.lur;
25 import static org.junit.Assert.*;
26 import static org.hamcrest.CoreMatchers.*;
27 import java.lang.reflect.Field;
29 import java.io.IOException;
31 import org.onap.aaf.cadi.lur.ConfigPrincipal;
33 public class JU_ConfigPrincipal {
35 private final String name = "User";
36 private final String pass = "pass";
38 // Expected output of base64("User:pass")
39 private final String b64encoded = "VXNlcjpwYXNz";
41 private Field content_field;
44 public void setup() throws NoSuchFieldException {
45 content_field = ConfigPrincipal.class.getDeclaredField("content");
46 content_field.setAccessible(true);
50 public void testConfigPrincipalStringString() throws IOException, IllegalArgumentException, IllegalAccessException {
51 ConfigPrincipal p = new ConfigPrincipal(name, pass);
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));
60 // One more time for coverage purposes
61 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
65 public void testConfigPrincipalStringByteArray() throws IOException, IllegalArgumentException, IllegalAccessException {
66 ConfigPrincipal p = new ConfigPrincipal(name, pass.getBytes());
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));
75 // One more time for coverage purposes
76 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));