Clover Coverage Report - KS Security 1.2.1-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Nov 2 2011 05:24:14 EST
51   169   8   12.75
6   89   0.16   4
4     2  
1    
 
  TestSecurityTokenService       Line # 39 51 0% 8 3 95.1% 0.9508197
 
  (3)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.security.trust;
17   
18    import static org.junit.Assert.assertEquals;
19    import static org.junit.Assert.assertNull;
20   
21    import java.util.List;
22   
23    import javax.xml.parsers.DocumentBuilder;
24    import javax.xml.parsers.DocumentBuilderFactory;
25   
26    import org.junit.Test;
27    import org.kuali.student.common.test.spring.AbstractServiceTest;
28    import org.kuali.student.common.test.spring.Client;
29    import org.kuali.student.security.exceptions.KSSecurityException;
30    import org.kuali.student.security.trust.dto.RequestSecurityTokenResponseCollectionType;
31    import org.kuali.student.security.trust.dto.RequestSecurityTokenResponseType;
32    import org.kuali.student.security.trust.dto.RequestSecurityTokenType;
33    import org.kuali.student.security.trust.service.SecurityTokenService;
34    import org.kuali.student.security.trust.service.SecurityTokenServiceImpl;
35    import org.w3c.dom.Document;
36    import org.w3c.dom.Element;
37   
38   
 
39    public class TestSecurityTokenService extends AbstractServiceTest {
40   
41    @Client(value="org.kuali.student.security.trust.service.SecurityTokenServiceImpl",additionalContextFile="classpath:test-sts-context.xml")
42    public SecurityTokenService client;
43   
 
44  1 toggle @Test
45    public void requestSecurityToken() throws KSSecurityException {
46  1 RequestSecurityTokenType rst = new RequestSecurityTokenType();
47  1 rst.setContext("Optional URI specifies this request identifier");
48   
49    // "TokenType"
50  1 Element tokenType = createElement("TokenType");
51  1 tokenType.setTextContent("urn:oasis:names:tc:SAML:1.0:assertion");
52  1 rst.getAny().add(tokenType);
53   
54    // "RequestType"
55  1 Element requestType = createElement("RequestType");
56  1 requestType.setTextContent("/Issue");
57  1 rst.getAny().add(requestType);
58   
59    // "CasProxyTicket"
60  1 Element casProxyTicket = createElement("CasProxyTicket");
61  1 casProxyTicket.setTextContent("ST-4-ZlNqDu6oukc1NcizlAbL-cas");
62  1 rst.getAny().add(casProxyTicket);
63   
64    // "CasProxyTargetService"
65  1 Element casProxyTargetService = createElement("CasProxyTargetService");
66  1 casProxyTargetService.setTextContent("http://localhost:18080/bar");
67  1 rst.getAny().add(casProxyTargetService);
68   
69    /*
70    * This test has been disbled on purpose, there is error when running it with mvn test.
71    * If its run as a Junit test without maven it works. Its Jaxb binding error and it has
72    * something to do with the SAML Assertion, I think changing to SAML 2 might solve this.
73    * */
74   
75    //RequestSecurityTokenResponseType rstr = client.requestSecurityToken(rst);
76   
77    // Assert
78    /*assertEquals("Optional URI specifies this request identifier", rstr.getContext());
79   
80    List<Object> objects = rstr.getAny();
81    for(Object o : objects){
82    if(o instanceof JAXBElement){
83    JAXBElement<?> e = (JAXBElement<?>)o;
84   
85    if( e.getName().getLocalPart().equalsIgnoreCase("TokenType")){
86    assertEquals("urn:oasis:names:tc:SAML:1.0:assertion", (String)e.getValue());
87    }
88    else if(e.getName().getLocalPart().equalsIgnoreCase("RequestedSecurityToken")) {
89    RequestedSecurityTokenType requestedToken = (RequestedSecurityTokenType)e.getValue();
90    Element ksSecureToken = (Element)requestedToken.getAny();
91    Element saml = (Element)ksSecureToken.getFirstChild();
92    assertEquals("Assertion", saml.getLocalName());
93    }
94    }
95    }*/
96    }
97   
 
98  1 toggle @Test
99    public void requestSecurityToken2() throws KSSecurityException {
100  1 RequestSecurityTokenResponseCollectionType rstr = client.requestSecurityToken2(null);
101  1 assertNull(rstr);
102    }
103   
104    // Test the filthy impl client, no SOAP.
 
105  1 toggle @Test
106    public void requestSecurityTokenNonSoap() throws KSSecurityException {
107  1 SecurityTokenService client = new SecurityTokenServiceImpl();
108   
109  1 RequestSecurityTokenType rst = new RequestSecurityTokenType();
110  1 rst.setContext("Optional URI specifies this request identifier");
111   
112    // "TokenType"
113  1 Element tokenType = createElement("TokenType");
114  1 tokenType.setTextContent("urn:oasis:names:tc:SAML:1.0:assertion");
115  1 rst.getAny().add(tokenType);
116   
117    // "RequestType"
118  1 Element requestType = createElement("RequestType");
119  1 requestType.setTextContent("/Issue");
120  1 rst.getAny().add(requestType);
121   
122    // "CasProxyTicket"
123  1 Element casProxyTicket = createElement("CasProxyTicket");
124  1 casProxyTicket.setTextContent("ST-4-ZlNqDu6oukc1NcizlAbL-cas");
125  1 rst.getAny().add(casProxyTicket);
126   
127    // "CasProxyTargetService"
128  1 Element casProxyTargetService = createElement("CasProxyTargetService");
129  1 casProxyTargetService.setTextContent("http://localhost:18080/bar");
130  1 rst.getAny().add(casProxyTargetService);
131   
132  1 RequestSecurityTokenResponseType rstr = client.requestSecurityToken(rst);
133   
134    // Assert
135  1 assertEquals("Optional URI specifies this request identifier", rstr.getContext());
136   
137  1 List<Object> objects = rstr.getAny();
138  1 for(Object o : objects){
139  2 if(o instanceof Element){
140  2 Element e = (Element)o;
141  2 if( e.getLocalName().equalsIgnoreCase("TokenType")){
142  1 assertEquals("urn:oasis:names:tc:SAML:1.0:assertion", (String)e.getTextContent());
143    }
144  1 else if(e.getLocalName().equalsIgnoreCase("RequestedSecurityToken")) {
145  1 Element ksSecureToken = (Element)e.getFirstChild();
146  1 Element saml = (Element)ksSecureToken.getFirstChild();
147  1 assertEquals("Assertion", saml.getLocalName());
148    }
149    }
150    }
151    }
152   
 
153  8 toggle private Element createElement(String tagName){
154   
155  8 Element element = null;
156  8 try{
157  8 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
158   
159  8 DocumentBuilder db = dbf.newDocumentBuilder();
160  8 Document doc = db.newDocument();
161   
162  8 element = doc.createElementNS("http://schemas.xmlsoap.org/ws/2005/02/trust", tagName);
163   
164    } catch(Exception e){
165  0 e.printStackTrace();
166    }
167  8 return element;
168    }
169    }