Increased auth batch coverage
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / wsse / test / JU_WSSE_Read.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.wsse.test;
23
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertNotNull;
26 import static junit.framework.Assert.assertNull;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.File;
30 import java.io.FileInputStream;
31
32 import javax.xml.stream.XMLStreamException;
33
34 import org.junit.Test;
35 import org.onap.aaf.cadi.BasicCred;
36 import org.onap.aaf.cadi.BufferedServletInputStream;
37 import org.onap.aaf.cadi.wsse.WSSEParser;
38
39 public class JU_WSSE_Read {
40
41 //      @Test
42 //      public void test() {
43 //              try {
44 //                      final BasicCred bc = new BasicCred() {
45
46 //                              private String user;
47 //                              private byte[] password;
48
49 //                              public void setUser(String user) {
50 //                                      this.user = user;
51 //                              }
52
53 //                              public void setCred(byte[] passwd) {
54 //                                      this.password = passwd;
55 //                              }
56
57 //                              public String getUser() {
58 //                                      return user;
59 //                              }
60
61 //                              public byte[] getCred() {
62 //                                      return password;
63 //                              }
64 //                      };
65
66 //                      WSSEParser wp = new WSSEParser();
67
68 //                      FileInputStream fis;
69 //                      fis = new FileInputStream("test/example.xml");
70 //                      BufferedServletInputStream is = new BufferedServletInputStream(fis);
71 //                      try {
72 //                              is.mark(1536);
73 //                              try {
74 //                                      assertNull(wp.parse(bc, is));
75 //                              } finally {
76 //                                      is.reset();
77 //                                      assertEquals(814,is.buffered());
78 //                              }
79 //                              String password = new String(bc.getCred());
80 //                              System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
81 //                              assertEquals("some_user", bc.getUser());
82 //                              assertEquals("some_password", password);
83                                 
84 //                      } finally {
85 //                              fis.close();
86 //                      }
87
88 //                      // CBUS (larger)
89 //                      fis = new FileInputStream("test/CBUSevent.xml");
90 //                      is = new BufferedServletInputStream(fis);
91 //                      try {
92 //                              is.mark(1536);
93 //                              try {
94 //                                      assertNull(wp.parse(bc, is));
95 //                              } finally {
96 //                                      is.reset();
97 //                                      assertEquals(667,is.buffered());
98 //                              }
99 //                              String password = new String(bc.getCred());
100 //                              System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
101 //                              assertEquals("none", bc.getUser());
102 //                              assertEquals("none", password);
103                                 
104 //                      } finally {
105 //                              fis.close();
106 //                      }
107
108 //                      // Closed Stream
109 //                      fis = new FileInputStream("test/example.xml");
110 //                      fis.close();
111 //                      bc.setCred(null);
112 //                      bc.setUser(null);
113 //                      XMLStreamException ex = wp.parse(bc, fis);
114 //                      assertNotNull(ex);
115 //                      assertNull(bc.getUser());
116 //                      assertNull(bc.getCred());
117
118
119 //                      fis = new FileInputStream("test/exampleNoSecurity.xml");
120 //                      try {
121 //                              bc.setCred(null);
122 //                              bc.setUser(null);
123 //                              assertNull(wp.parse(bc, fis));
124 //                              assertNull(bc.getUser());
125 //                              assertNull(bc.getCred());
126 //                      } finally {
127 //                              fis.close();
128 //                      }
129
130 //                      fis = new FileInputStream("test/exampleBad1.xml");
131 //                      try {
132 //                              bc.setCred(null);
133 //                              bc.setUser(null);
134 //                              assertNull(wp.parse(bc, fis));
135 //                              assertNull(bc.getUser());
136 //                              assertNull(bc.getCred());
137 //                      } finally {
138 //                              fis.close();
139 //                      }
140
141 //                      XMLStreamException e = wp.parse(bc, new ByteArrayInputStream("Not XML".getBytes())); // empty
142 //                      assertNotNull(e);
143
144 //                      e = wp.parse(bc, new ByteArrayInputStream("".getBytes())); // empty
145 //                      assertNotNull(e);
146                         
147                         
148 //                      long start, count = 0L;
149 //                      int iter = 30000;
150 //                      File f = new File("test/CBUSevent.xml");
151 //                      fis = new FileInputStream(f);
152 //                      is = new BufferedServletInputStream(fis);
153 //                      is.mark(0);
154 //                      try {
155 //                              while(is.read()>=0);
156 //                      } finally {
157 //                              fis.close();
158 //                      }
159
160 //                      for(int i=0;i<iter;++i) {
161 //                              start = System.nanoTime();
162 //                              is.reset();
163 //                              try {
164 //                                      assertNull(wp.parse(bc, is));
165 //                              } finally {
166 //                                      count += System.nanoTime()-start;
167 //                              }
168 //                      }
169 //                      float ms = count/1000000f;
170 //                      System.out.println("Executed " + iter + " WSSE reads from Memory Stream in " + ms + "ms.  " + ms/iter + "ms per trans");
171                         
172 //                      // SPECIFIC ISSUES
173                         
174 //                      fis = new FileInputStream("test/error2013_04_23.xml");
175 //                      try {
176 //                              bc.setCred(null);
177 //                              bc.setUser(null);
178 //                              assertNull(wp.parse(bc, fis));
179 //                              assertNull(bc.getUser());
180 //                              assertNull(bc.getCred());
181 //                      } finally {
182 //                              fis.close();
183 //                      }
184 //              } catch(Exception e) {
185 //                      e.printStackTrace(System.err);
186 //              }
187 //      }
188
189 }