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 ******************************************************************************/
23 package org.onap.aaf.cadi.lur.test;
26 import static org.junit.Assert.*;
27 import static org.hamcrest.CoreMatchers.*;
28 import java.lang.reflect.Field;
30 import java.io.IOException;
32 import org.onap.aaf.cadi.lur.ConfigPrincipal;
34 public class JU_ConfigPrincipal {
36 private final String name = "User";
37 private final String pass = "pass";
39 // Expected output of base64("User:pass")
40 private final String b64encoded = "VXNlcjpwYXNz";
42 private Field content_field;
45 public void setup() throws NoSuchFieldException {
46 content_field = ConfigPrincipal.class.getDeclaredField("content");
47 content_field.setAccessible(true);
51 public void testConfigPrincipalStringString() throws IOException, IllegalArgumentException, IllegalAccessException {
52 ConfigPrincipal p = new ConfigPrincipal(name, pass);
54 assertThat(p.getName(), is(name));
55 assertThat(p.toString(), is(name));
56 assertThat(p.getCred(), is(pass.getBytes()));
57 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
58 content_field.set(p, "pass");
59 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
61 // One more time for coverage purposes
62 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
66 public void testConfigPrincipalStringByteArray() throws IOException, IllegalArgumentException, IllegalAccessException {
67 ConfigPrincipal p = new ConfigPrincipal(name, pass.getBytes());
69 assertThat(p.getName(), is(name));
70 assertThat(p.toString(), is(name));
71 assertThat(p.getCred(), is(pass.getBytes()));
72 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
73 content_field.set(p, "pass");
74 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));
76 // One more time for coverage purposes
77 assertThat(p.getAsBasicAuthHeader(), is("Basic " + b64encoded));