1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.cadi.wsse.test;
\r
25 import static junit.framework.Assert.assertEquals;
\r
26 import static junit.framework.Assert.assertNotNull;
\r
27 import static junit.framework.Assert.assertNull;
\r
29 import java.io.ByteArrayInputStream;
\r
30 import java.io.File;
\r
31 import java.io.FileInputStream;
\r
33 import javax.xml.stream.XMLStreamException;
\r
35 import org.junit.Test;
\r
37 import com.att.cadi.BasicCred;
\r
38 import com.att.cadi.BufferedServletInputStream;
\r
39 import com.att.cadi.wsse.WSSEParser;
\r
41 public class JU_WSSE_Read {
\r
44 public void test() {
\r
46 final BasicCred bc = new BasicCred() {
\r
48 private String user;
\r
49 private byte[] password;
\r
51 public void setUser(String user) {
\r
55 public void setCred(byte[] passwd) {
\r
56 this.password = passwd;
\r
59 public String getUser() {
\r
63 public byte[] getCred() {
\r
68 WSSEParser wp = new WSSEParser();
\r
70 FileInputStream fis;
\r
71 fis = new FileInputStream("test/example.xml");
\r
72 BufferedServletInputStream is = new BufferedServletInputStream(fis);
\r
76 assertNull(wp.parse(bc, is));
\r
79 assertEquals(814,is.buffered());
\r
81 String password = new String(bc.getCred());
\r
82 System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
\r
83 assertEquals("some_user", bc.getUser());
\r
84 assertEquals("some_password", password);
\r
91 fis = new FileInputStream("test/CBUSevent.xml");
\r
92 is = new BufferedServletInputStream(fis);
\r
96 assertNull(wp.parse(bc, is));
\r
99 assertEquals(667,is.buffered());
\r
101 String password = new String(bc.getCred());
\r
102 System.out.println("CadiWrap credentials are: " + bc.getUser() + ", " + password);
\r
103 assertEquals("none", bc.getUser());
\r
104 assertEquals("none", password);
\r
111 fis = new FileInputStream("test/example.xml");
\r
115 XMLStreamException ex = wp.parse(bc, fis);
\r
117 assertNull(bc.getUser());
\r
118 assertNull(bc.getCred());
\r
121 fis = new FileInputStream("test/exampleNoSecurity.xml");
\r
125 assertNull(wp.parse(bc, fis));
\r
126 assertNull(bc.getUser());
\r
127 assertNull(bc.getCred());
\r
132 fis = new FileInputStream("test/exampleBad1.xml");
\r
136 assertNull(wp.parse(bc, fis));
\r
137 assertNull(bc.getUser());
\r
138 assertNull(bc.getCred());
\r
143 XMLStreamException e = wp.parse(bc, new ByteArrayInputStream("Not XML".getBytes())); // empty
\r
146 e = wp.parse(bc, new ByteArrayInputStream("".getBytes())); // empty
\r
150 long start, count = 0L;
\r
152 File f = new File("test/CBUSevent.xml");
\r
153 fis = new FileInputStream(f);
\r
154 is = new BufferedServletInputStream(fis);
\r
157 while(is.read()>=0);
\r
162 for(int i=0;i<iter;++i) {
\r
163 start = System.nanoTime();
\r
166 assertNull(wp.parse(bc, is));
\r
168 count += System.nanoTime()-start;
\r
171 float ms = count/1000000f;
\r
172 System.out.println("Executed " + iter + " WSSE reads from Memory Stream in " + ms + "ms. " + ms/iter + "ms per trans");
\r
176 fis = new FileInputStream("test/error2013_04_23.xml");
\r
180 assertNull(wp.parse(bc, fis));
\r
181 assertNull(bc.getUser());
\r
182 assertNull(bc.getCred());
\r
186 } catch(Exception e) {
\r
187 e.printStackTrace(System.err);
\r