1 19 package org.netbeans.modules.websvc.wsitconf.wsdlmodelext; 20 21 import java.io.File ; 22 import junit.framework.*; 23 import org.netbeans.modules.websvc.wsitconf.ui.ComboConstants; 24 import org.netbeans.modules.websvc.wsitconf.util.TestCatalogModel; 25 import org.netbeans.modules.websvc.wsitconf.util.TestUtil; 26 import org.netbeans.modules.websvc.wsitmodelext.security.TrustElement; 27 import org.netbeans.modules.websvc.wsitmodelext.security.WssElement; 28 import org.netbeans.modules.xml.wsdl.model.Binding; 29 import org.netbeans.modules.xml.wsdl.model.Definitions; 30 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 31 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory; 32 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 33 34 38 public class SecurityPolicyTest extends TestCase { 39 40 public SecurityPolicyTest(String testName) { 41 super(testName); 42 } 43 44 @Override 45 protected void setUp() throws Exception { } 46 47 @Override 48 protected void tearDown() throws Exception { 49 TestCatalogModel.getDefault().setDocumentPooling(false); 50 } 51 52 public void testSecurityPolicy() throws Exception { 53 TestCatalogModel.getDefault().setDocumentPooling(true); 54 WSDLModel model = TestUtil.loadWSDLModel("../wsdlmodelext/resources/policy.xml"); 55 WSDLComponentFactory fact = model.getFactory(); 56 57 model.startTransaction(); 58 59 Definitions d = model.getDefinitions(); 60 Binding b = (Binding) d.getBindings().toArray()[0]; 61 62 assertFalse("WSS10 enabled indicated on empty WSDL", SecurityPolicyModelHelper.isWss10(b)); 63 assertFalse("WSS11 enabled indicated on empty WSDL", SecurityPolicyModelHelper.isWss11(b)); 64 assertFalse("Trust10 enabled indicated on empty WSDL", SecurityPolicyModelHelper.isTrust10(b)); 65 66 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportClientChallenge(b)); 67 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportServerChallenge(b)); 68 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportIssuedTokens(b)); 69 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportRefEmbeddedToken(b)); 70 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportRefEncryptedKey(b)); 71 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportRefExternalURI(b)); 72 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportRefIssuerSerial(b)); 73 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportRefKeyIdentifier(b)); 74 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportRefThumbprint(b)); 75 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isMustSupportServerChallenge(b)); 76 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isRequireClientEntropy(b)); 77 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isRequireServerEntropy(b)); 78 79 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isEncryptSignature(b)); 80 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isIncludeTimestamp(b)); 81 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isRequireSignatureConfirmation(b)); 82 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isSignEntireHeadersAndBody(b)); 83 84 assertFalse("Enabled indicated on empty WSDL", SecurityPolicyModelHelper.isEncryptBeforeSigning(b)); 85 86 String secBindingType = SecurityPolicyModelHelper.getSecurityBindingType(b); 87 assertEquals("SecurityBinding type indicated on empty wsdl", ComboConstants.NOSECURITY, secBindingType); 88 89 WssElement wss = SecurityPolicyModelHelper.enableWss(b, false); 91 assertTrue("WSS10 Not enabled correctly", SecurityPolicyModelHelper.isWss10(b)); 92 93 SecurityPolicyModelHelper.enableMustSupportRefEmbeddedToken(wss, true); 95 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefEmbeddedToken(b)); 96 SecurityPolicyModelHelper.enableMustSupportRefEmbeddedToken(wss, false); 97 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefEmbeddedToken(b)); 98 99 SecurityPolicyModelHelper.enableMustSupportRefExternalURI(wss, true); 101 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefExternalURI(b)); 102 SecurityPolicyModelHelper.enableMustSupportRefExternalURI(wss, false); 103 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefExternalURI(b)); 104 105 SecurityPolicyModelHelper.enableMustSupportRefIssuerSerial(wss, true); 107 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefIssuerSerial(b)); 108 SecurityPolicyModelHelper.enableMustSupportRefIssuerSerial(wss, false); 109 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefIssuerSerial(b)); 110 111 SecurityPolicyModelHelper.enableMustSupportRefKeyIdentifier(wss, true); 113 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefKeyIdentifier(b)); 114 SecurityPolicyModelHelper.enableMustSupportRefKeyIdentifier(wss, false); 115 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefKeyIdentifier(b)); 116 117 SecurityPolicyModelHelper.disableWss(b); 118 assertFalse("WSS10 enabled indicated", SecurityPolicyModelHelper.isWss10(b)); 119 120 wss = SecurityPolicyModelHelper.enableWss(b, true); 122 assertTrue("WSS11 Not enabled correctly", SecurityPolicyModelHelper.isWss11(b)); 123 124 SecurityPolicyModelHelper.enableMustSupportRefEmbeddedToken(wss, true); 126 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefEmbeddedToken(b)); 127 SecurityPolicyModelHelper.enableMustSupportRefEmbeddedToken(wss, false); 128 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefEmbeddedToken(b)); 129 130 SecurityPolicyModelHelper.enableMustSupportRefExternalURI(wss, true); 132 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefExternalURI(b)); 133 SecurityPolicyModelHelper.enableMustSupportRefExternalURI(wss, false); 134 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefExternalURI(b)); 135 136 SecurityPolicyModelHelper.enableMustSupportRefKeyIdentifier(wss, true); 138 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefKeyIdentifier(b)); 139 SecurityPolicyModelHelper.enableMustSupportRefKeyIdentifier(wss, false); 140 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefKeyIdentifier(b)); 141 142 SecurityPolicyModelHelper.enableMustSupportRefIssuerSerial(wss, true); 144 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefIssuerSerial(b)); 145 SecurityPolicyModelHelper.enableMustSupportRefIssuerSerial(wss, false); 146 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefIssuerSerial(b)); 147 148 SecurityPolicyModelHelper.enableMustSupportRefEncryptedKey(wss, true); 150 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefEncryptedKey(b)); 151 SecurityPolicyModelHelper.enableMustSupportRefEncryptedKey(wss, false); 152 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefEncryptedKey(b)); 153 154 SecurityPolicyModelHelper.enableMustSupportRefThumbprint(wss, true); 156 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportRefThumbprint(b)); 157 SecurityPolicyModelHelper.enableMustSupportRefThumbprint(wss, false); 158 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportRefThumbprint(b)); 159 160 SecurityPolicyModelHelper.enableRequireSignatureConfirmation(wss, true); 162 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isRequireSignatureConfirmation(b)); 163 SecurityPolicyModelHelper.enableRequireSignatureConfirmation(wss, false); 164 assertFalse("enabled indicated", SecurityPolicyModelHelper.isRequireSignatureConfirmation(b)); 165 166 SecurityPolicyModelHelper.disableWss(b); 167 assertFalse("WSS11 enabled indicated", SecurityPolicyModelHelper.isWss11(b)); 168 169 TrustElement trust = SecurityPolicyModelHelper.enableTrust10(b); 171 assertTrue("Trust10 Not enabled correctly", SecurityPolicyModelHelper.isTrust10(b)); 172 173 SecurityPolicyModelHelper.enableMustSupportClientChallenge(trust, true); 175 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportClientChallenge(b)); 176 SecurityPolicyModelHelper.enableMustSupportClientChallenge(trust, false); 177 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportClientChallenge(b)); 178 179 SecurityPolicyModelHelper.enableMustSupportServerChallenge(trust, true); 181 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportServerChallenge(b)); 182 SecurityPolicyModelHelper.enableMustSupportServerChallenge(trust, false); 183 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportServerChallenge(b)); 184 185 SecurityPolicyModelHelper.enableMustSupportIssuedTokens(trust, true); 187 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isMustSupportIssuedTokens(b)); 188 SecurityPolicyModelHelper.enableMustSupportIssuedTokens(trust, false); 189 assertFalse("enabled indicated", SecurityPolicyModelHelper.isMustSupportIssuedTokens(b)); 190 191 SecurityPolicyModelHelper.enableRequireClientEntropy(trust, true); 193 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isRequireClientEntropy(b)); 194 SecurityPolicyModelHelper.enableRequireClientEntropy(trust, false); 195 assertFalse("enabled indicated", SecurityPolicyModelHelper.isRequireClientEntropy(b)); 196 197 SecurityPolicyModelHelper.enableRequireServerEntropy(trust, true); 199 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isRequireServerEntropy(b)); 200 SecurityPolicyModelHelper.enableRequireServerEntropy(trust, false); 201 assertFalse("enabled indicated", SecurityPolicyModelHelper.isRequireServerEntropy(b)); 202 203 SecurityPolicyModelHelper.disableTrust10(b); 204 assertFalse("Trust10 enabled indicated", SecurityPolicyModelHelper.isTrust10(b)); 205 206 SecurityPolicyModelHelper.setSecurityBindingType(b, ComboConstants.TRANSPORT); 207 secBindingType = SecurityPolicyModelHelper.getSecurityBindingType(b); 208 assertEquals("Wrong SecurityBinding type indicated", ComboConstants.TRANSPORT, secBindingType); 209 210 SecurityPolicyModelHelper.setSecurityBindingType(b, ComboConstants.SYMMETRIC); 211 secBindingType = SecurityPolicyModelHelper.getSecurityBindingType(b); 212 assertEquals("Wrong SecurityBinding type indicated", ComboConstants.SYMMETRIC, secBindingType); 213 214 WSDLComponent bindingType = SecurityPolicyModelHelper.getSecurityBindingTypeElement(b); 215 216 SecurityPolicyModelHelper.enableEncryptSignature(bindingType, true); 218 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isEncryptSignature(b)); 219 SecurityPolicyModelHelper.enableEncryptSignature(bindingType, false); 220 assertFalse("enabled indicated", SecurityPolicyModelHelper.isEncryptSignature(b)); 221 222 SecurityPolicyModelHelper.enableIncludeTimestamp(bindingType, true); 224 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isIncludeTimestamp(b)); 225 SecurityPolicyModelHelper.enableIncludeTimestamp(bindingType, false); 226 assertFalse("enabled indicated", SecurityPolicyModelHelper.isIncludeTimestamp(b)); 227 228 SecurityPolicyModelHelper.enableSignEntireHeadersAndBody(bindingType, true); 230 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isSignEntireHeadersAndBody(b)); 231 SecurityPolicyModelHelper.enableSignEntireHeadersAndBody(bindingType, false); 232 assertFalse("enabled indicated", SecurityPolicyModelHelper.isSignEntireHeadersAndBody(b)); 233 234 SecurityPolicyModelHelper.enableEncryptBeforeSigning(bindingType, true); 236 assertTrue("Not enabled correctly", SecurityPolicyModelHelper.isEncryptBeforeSigning(b)); 237 SecurityPolicyModelHelper.enableEncryptBeforeSigning(bindingType, false); 238 assertFalse("enabled indicated", SecurityPolicyModelHelper.isEncryptBeforeSigning(b)); 239 240 SecurityPolicyModelHelper.setLayout(bindingType, ComboConstants.STRICT); 242 assertEquals("Message Layout", ComboConstants.STRICT, SecurityPolicyModelHelper.getMessageLayout(b)); 243 SecurityPolicyModelHelper.setLayout(bindingType, ComboConstants.LAX); 244 assertEquals("Message Layout", ComboConstants.LAX, SecurityPolicyModelHelper.getMessageLayout(b)); 245 SecurityPolicyModelHelper.setLayout(bindingType, ComboConstants.LAXTSFIRST); 246 assertEquals("Message Layout", ComboConstants.LAXTSFIRST, SecurityPolicyModelHelper.getMessageLayout(b)); 247 SecurityPolicyModelHelper.setLayout(bindingType, ComboConstants.LAXTSLAST); 248 assertEquals("Message Layout", ComboConstants.LAXTSLAST, SecurityPolicyModelHelper.getMessageLayout(b)); 249 250 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC128); 252 assertEquals("Algorithm Suite", ComboConstants.BASIC128, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 253 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC192); 254 assertEquals("Algorithm Suite", ComboConstants.BASIC192, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 255 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC256); 256 assertEquals("Algorithm Suite", ComboConstants.BASIC256, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 257 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.TRIPLEDES); 258 assertEquals("Algorithm Suite", ComboConstants.TRIPLEDES, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 259 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC256RSA15); 260 assertEquals("Algorithm Suite", ComboConstants.BASIC256RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 261 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC192RSA15); 262 assertEquals("Algorithm Suite", ComboConstants.BASIC192RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 263 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC128RSA15); 264 assertEquals("Algorithm Suite", ComboConstants.BASIC128RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 265 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.TRIPLEDESRSA15); 266 assertEquals("Algorithm Suite", ComboConstants.TRIPLEDESRSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 267 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC256SHA256); 268 assertEquals("Algorithm Suite", ComboConstants.BASIC256SHA256, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 269 270 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC192SHA256); 271 assertEquals("Algorithm Suite", ComboConstants.BASIC192SHA256, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 272 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC128SHA256); 273 assertEquals("Algorithm Suite", ComboConstants.BASIC128SHA256, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 274 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.TRIPLEDESSHA256); 275 assertEquals("Algorithm Suite", ComboConstants.TRIPLEDESSHA256, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 276 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC256SHA256RSA15); 277 assertEquals("Algorithm Suite", ComboConstants.BASIC256SHA256RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 278 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC192SHA256RSA15); 279 assertEquals("Algorithm Suite", ComboConstants.BASIC192SHA256RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 280 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.BASIC128SHA256RSA15); 281 assertEquals("Algorithm Suite", ComboConstants.BASIC128SHA256RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 282 AlgoSuiteModelHelper.setAlgorithmSuite(bindingType, ComboConstants.TRIPLEDESSHA256RSA15); 283 assertEquals("Algorithm Suite", ComboConstants.TRIPLEDESSHA256RSA15, AlgoSuiteModelHelper.getAlgorithmSuite(b)); 284 285 SecurityPolicyModelHelper.setSecurityBindingType(b, ComboConstants.ASYMMETRIC); 286 secBindingType = SecurityPolicyModelHelper.getSecurityBindingType(b); 287 assertEquals("Wrong SecurityBinding type indicated", ComboConstants.ASYMMETRIC, secBindingType); 288 289 SecurityPolicyModelHelper.setSecurityBindingType(b, ComboConstants.NOSECURITY); 290 secBindingType = SecurityPolicyModelHelper.getSecurityBindingType(b); 291 assertEquals("Wrong SecurityBinding type indicated", ComboConstants.NOSECURITY, secBindingType); 292 293 assertNull("Default Algorithm Suite", AlgoSuiteModelHelper.getAlgorithmSuite(b)); 295 assertNull("Default Message Layout", SecurityPolicyModelHelper.getMessageLayout(b)); 296 assertFalse("Default Include Timestamp", SecurityPolicyModelHelper.isIncludeTimestamp(b)); 297 assertFalse("Default WSS", SecurityPolicyModelHelper.isWss10(b)); 298 assertFalse("Default WSS", SecurityPolicyModelHelper.isWss11(b)); 299 assertFalse("Default Trust", SecurityPolicyModelHelper.isTrust10(b)); 300 301 model.endTransaction(); 302 303 TestUtil.dumpToFile(model.getBaseDocument(), new File ("C:\\SecurityPolicyService.wsdl")); 304 } 305 306 public String getTestResourcePath() { 307 return "../wsdlmodelext/resources/policy.xml"; 308 } 309 310 } 311 | Popular Tags |