Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / sso / test / JU_AAFSSO.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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.sso.test;
23
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.nullValue;
26 import static org.junit.Assert.assertThat;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.IOException;
31
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aaf.cadi.CadiException;
36 import org.onap.aaf.cadi.PropAccess;
37 import org.onap.aaf.cadi.config.Config;
38 import org.onap.aaf.cadi.sso.AAFSSO;
39
40 public class JU_AAFSSO {
41
42     private static final String resourceDirString = "src/test/resources";
43     private static final String aafDir = resourceDirString + "/aaf";
44
45     private ByteArrayInputStream inStream;
46
47     @Before
48     public void setup() {
49         System.setProperty("user.home", aafDir);
50
51         // Simulate user input
52         inStream = new ByteArrayInputStream("test\npassword".getBytes());
53         System.setIn(inStream);
54     }
55
56     @After
57     public void tearDown() {
58         recursiveDelete(new File(aafDir));
59     }
60
61     @Test
62     public void test() throws IOException, CadiException {
63         AAFSSO sso;
64         String[] args;
65
66         args = new String[] {
67                 "-login",
68                 "-noexit",
69         };
70         sso = new AAFSSO(args);
71         
72         assertThat(new File(aafDir).exists(), is(true));
73         assertThat(new File(aafDir + "/.aaf").exists(), is(true));
74         assertThat(new File(aafDir + "/.aaf/keyfile").exists(), is(true));
75         assertThat(new File(aafDir + "/.aaf/sso.out").exists(), is(true));
76         assertThat(sso.loginOnly(), is(true));
77
78 // Not necessarily true
79 //        assertThat(new File(aafDir + "/.aaf/sso.props").exists(), is(true));
80         
81         sso.setLogDefault();
82         sso.setStdErrDefault();
83
84         inStream.reset();
85         args = new String[] {
86                 "-logout",
87                 "\\*",
88                 "-noexit",
89         };
90         sso = new AAFSSO(args);
91
92         assertThat(new File(aafDir).exists(), is(true));
93         assertThat(new File(aafDir + "/.aaf").exists(), is(true));
94         assertThat(new File(aafDir + "/.aaf/keyfile").exists(), is(false));
95         assertThat(new File(aafDir + "/.aaf/sso.out").exists(), is(true));
96         assertThat(sso.loginOnly(), is(false));
97
98         PropAccess access = sso.access();
99         assertThat(sso.enc_pass(), is(access.getProperty(Config.AAF_APPPASS)));
100         assertThat(sso.user(), is(access.getProperty(Config.AAF_APPID)));
101
102         sso.addProp("key", "value");
103         assertThat(sso.err(), is(nullValue()));
104         
105         assertThat(sso.useX509(), is(false));
106
107         sso.close();
108     }
109
110     private void recursiveDelete(File file) {
111         for (File f : file.listFiles()) {
112             if (f.isDirectory()) {
113                 recursiveDelete(f);
114             }
115             f.delete();
116         }
117         file.delete();
118     }
119
120 }