| 1 |  |  | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  |  | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  |  | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  |  | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 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 |  |  | 
               
        |  |  | 
           
           |  | 95.1% | Uncovered Elements: 3 (61) | Complexity: 8 | Complexity Density: 0.16 |  | 
  
  
    | 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 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (14) | Complexity: 1 | Complexity Density: 0.07 | 1
    PASS |  | 
  
  
    | 44 | 1 |  @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 |  |  | 
            
  
    | 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 |  |  | 
            
  
    | 55 | 1 | Element requestType = createElement("RequestType"); | 
            
  
    | 56 | 1 | requestType.setTextContent("/Issue"); | 
            
  
    | 57 | 1 | rst.getAny().add(requestType); | 
            
  
    | 58 |  |  | 
            
  
    | 59 |  |  | 
            
  
    | 60 | 1 | Element casProxyTicket = createElement("CasProxyTicket"); | 
            
  
    | 61 | 1 | casProxyTicket.setTextContent("ST-4-ZlNqDu6oukc1NcizlAbL-cas"); | 
            
  
    | 62 | 1 | rst.getAny().add(casProxyTicket); | 
            
  
    | 63 |  |  | 
            
  
    | 64 |  |  | 
            
  
    | 65 | 1 | Element casProxyTargetService = createElement("CasProxyTargetService"); | 
            
  
    | 66 | 1 | casProxyTargetService.setTextContent("http://localhost:18080/bar"); | 
            
  
    | 67 | 1 | rst.getAny().add(casProxyTargetService); | 
            
  
    | 68 |  |  | 
            
  
    | 69 |  |  | 
            
  
    | 70 |  |  | 
            
  
    | 71 |  |  | 
            
  
    | 72 |  |  | 
            
  
    | 73 |  |  | 
            
  
    | 74 |  |  | 
            
  
    | 75 |  |  | 
            
  
    | 76 |  |  | 
            
  
    | 77 |  |  | 
            
  
    | 78 |  |  | 
            
  
    | 79 |  |  | 
            
  
    | 80 |  |  | 
            
  
    | 81 |  |  | 
            
  
    | 82 |  |  | 
            
  
    | 83 |  |  | 
            
  
    | 84 |  |  | 
            
  
    | 85 |  |  | 
            
  
    | 86 |  |  | 
            
  
    | 87 |  |  | 
            
  
    | 88 |  |  | 
            
  
    | 89 |  |  | 
            
  
    | 90 |  |  | 
            
  
    | 91 |  |  | 
            
  
    | 92 |  |  | 
            
  
    | 93 |  |  | 
            
  
    | 94 |  |  | 
            
  
    | 95 |  |  | 
            
  
    | 96 |  | } | 
            
  
    | 97 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (2) | Complexity: 1 | Complexity Density: 0.5 | 1
    PASS |  | 
  
  
    | 98 | 1 |  @Test... | 
            
  
    | 99 |  | public void requestSecurityToken2() throws KSSecurityException { | 
            
  
    | 100 | 1 | RequestSecurityTokenResponseCollectionType rstr = client.requestSecurityToken2(null); | 
            
  
    | 101 | 1 | assertNull(rstr); | 
            
  
    | 102 |  | } | 
            
  
    | 103 |  |  | 
            
  
    | 104 |  |  | 
               
        |  |  | 
           
           |  | 93.9% | Uncovered Elements: 2 (33) | Complexity: 4 | Complexity Density: 0.15 | 1
    PASS |  | 
  
  
    | 105 | 1 |  @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 |  |  | 
            
  
    | 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 |  |  | 
            
  
    | 118 | 1 | Element requestType = createElement("RequestType"); | 
            
  
    | 119 | 1 | requestType.setTextContent("/Issue"); | 
            
  
    | 120 | 1 | rst.getAny().add(requestType); | 
            
  
    | 121 |  |  | 
            
  
    | 122 |  |  | 
            
  
    | 123 | 1 | Element casProxyTicket = createElement("CasProxyTicket"); | 
            
  
    | 124 | 1 | casProxyTicket.setTextContent("ST-4-ZlNqDu6oukc1NcizlAbL-cas"); | 
            
  
    | 125 | 1 | rst.getAny().add(casProxyTicket); | 
            
  
    | 126 |  |  | 
            
  
    | 127 |  |  | 
            
  
    | 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 |  |  | 
            
  
    | 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 |  |  | 
               
        |  |  | 
           
           |  | 87.5% | Uncovered Elements: 1 (8) | Complexity: 2 | Complexity Density: 0.25 |  | 
  
  
    | 153 | 8 |  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 |  | } |