Remove Tabs, per Jococo
[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()  {
63         
64     // Note  this is desctructive of personal dirs, and doesn't really test anything.  Needs redoing. 
65 //        AAFSSO sso;
66 //        String[] args;
67 //
68 //        args = new String[] {
69 //                "-login",
70 //                "-noexit",
71 //        };
72 //        try {
73 //            sso = new AAFSSO(args);
74 //        
75 //        assertThat(new File(aafDir).exists(), is(true));
76 //        assertThat(new File(aafDir + "/.aaf").exists(), is(true));
77 //        assertThat(new File(aafDir + "/.aaf/keyfile").exists(), is(true));
78 //        assertThat(new File(aafDir + "/.aaf/sso.out").exists(), is(true));
79 //        assertThat(sso.loginOnly(), is(true));
80 //
81 //// Not necessarily true
82 ////        assertThat(new File(aafDir + "/.aaf/sso.props").exists(), is(true));
83 //        
84 //        sso.setLogDefault();
85 //        sso.setStdErrDefault();
86 //
87 //        inStream.reset();
88 //        args = new String[] {
89 //                "-logout",
90 //                "\\*",
91 //                "-noexit",
92 //        };
93 //        sso = new AAFSSO(args);
94 //
95 //        assertThat(new File(aafDir).exists(), is(true));
96 //        assertThat(new File(aafDir + "/.aaf").exists(), is(true));
97 //        assertThat(new File(aafDir + "/.aaf/keyfile").exists(), is(false));
98 //        assertThat(new File(aafDir + "/.aaf/sso.out").exists(), is(true));
99 //        assertThat(sso.loginOnly(), is(false));
100 //
101 //        PropAccess access = sso.access();
102 //        assertThat(sso.enc_pass(), is(access.getProperty(Config.AAF_APPPASS)));
103 //        assertThat(sso.user(), is(access.getProperty(Config.AAF_APPID)));
104 //
105 //        sso.addProp("key", "value");
106 //        assertThat(sso.err(), is(nullValue()));
107 //        
108 //        assertThat(sso.useX509(), is(false));
109 ////
110 ////        sso.close();
111 //        } catch (IOException | CadiException e) {
112 //            e.printStackTrace();
113 //        }
114
115     }
116
117     private void recursiveDelete(File file) {
118         for (File f : file.listFiles()) {
119             if (f.isDirectory()) {
120                 recursiveDelete(f);
121             }
122             f.delete();
123         }
124         file.delete();
125     }
126
127 }