1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.wss4j.policy.tests;
20
21 import org.apache.neethi.*;
22 import org.apache.wss4j.policy.SP12Constants;
23 import org.apache.wss4j.policy.SPConstants;
24 import org.apache.wss4j.policy.model.AlgorithmSuite;
25 import org.junit.jupiter.api.Test;
26
27 import java.util.Iterator;
28 import java.util.List;
29
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertFalse;
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33
34 public class AlgorithmSuiteTest extends AbstractTestBase {
35
36 @Test
37 public void testAlgorithmSuite() throws Exception {
38 String fileName = "AlgorithmSuite.xml";
39 String policyFile = loadPolicyFile("policy/model/sp12/" + fileName);
40 String serializedPolicyReferenceFile = loadPolicyFile("policy/model/sp12/serialized/" + fileName);
41 String normalizedPolicyReferenceFile = loadPolicyFile("policy/model/sp12/normalized/" + fileName);
42 Policy policy = loadPolicy(policyFile);
43 String serializedPolicy = serializePolicy(policy);
44 assertXMLisEqual(serializedPolicy, serializedPolicyReferenceFile);
45
46 Iterator<List<Assertion>> alternativeIterator = policy.getAlternatives();
47 int count = 0;
48 while (alternativeIterator.hasNext()) {
49 List<Assertion> alternative = alternativeIterator.next();
50 assertEquals(1, alternative.size());
51 assertTrue(alternative.get(0) instanceof AlgorithmSuite);
52 AlgorithmSuite algorithmSuite = (AlgorithmSuite) alternative.get(0);
53 assertFalse(algorithmSuite.isNormalized());
54 assertTrue(algorithmSuite.isIgnorable());
55 assertTrue(algorithmSuite.isOptional());
56 assertEquals(Constants.TYPE_ASSERTION, algorithmSuite.getType());
57 assertEquals(SP12Constants.ALGORITHM_SUITE, algorithmSuite.getName());
58 assertEquals(algorithmSuite.getAlgorithmSuiteType().getEncryption(), SPConstants.TRIPLE_DES);
59 assertEquals(AlgorithmSuite.C14NType.InclusiveC14N, algorithmSuite.getC14n());
60 assertEquals(AlgorithmSuite.SOAPNormType.SOAPNormalization10, algorithmSuite.getSoapNormType());
61 assertEquals(AlgorithmSuite.STRType.STRTransform10, algorithmSuite.getStrType());
62 assertEquals(AlgorithmSuite.XPathType.AbsXPath, algorithmSuite.getXPathType());
63 count++;
64 }
65 assertEquals(1, count);
66
67 policy = policy.normalize(true);
68 serializedPolicy = serializePolicy(policy);
69 assertXMLisEqual(serializedPolicy, normalizedPolicyReferenceFile);
70
71 alternativeIterator = policy.getAlternatives();
72 List<Assertion> alternative = alternativeIterator.next();
73 assertEquals(0, alternative.size());
74
75 List<PolicyComponent> policyComponents = policy.getPolicyComponents();
76 assertEquals(1, policyComponents.size());
77 PolicyOperator policyOperator = (PolicyOperator) policyComponents.get(0);
78 policyComponents = policyOperator.getPolicyComponents();
79 assertEquals(2, policyComponents.size());
80 All all = (All) policyComponents.get(0);
81 List<PolicyComponent> policyComponentsAll = all.getAssertions();
82 assertEquals(0, policyComponentsAll.size());
83
84 all = (All) policyComponents.get(1);
85 policyComponentsAll = all.getAssertions();
86 assertEquals(1, policyComponentsAll.size());
87
88 Iterator<PolicyComponent> policyComponentIterator = policyComponentsAll.iterator();
89 AlgorithmSuite algorithmSuite = (AlgorithmSuite) policyComponentIterator.next();
90 assertTrue(algorithmSuite.isNormalized());
91 assertTrue(algorithmSuite.isIgnorable());
92 assertFalse(algorithmSuite.isOptional());
93 assertEquals(Constants.TYPE_ASSERTION, algorithmSuite.getType());
94 assertEquals(SP12Constants.ALGORITHM_SUITE, algorithmSuite.getName());
95 assertEquals(algorithmSuite.getAlgorithmSuiteType().getEncryption(), SPConstants.TRIPLE_DES);
96 assertEquals(AlgorithmSuite.C14NType.InclusiveC14N, algorithmSuite.getC14n());
97 assertEquals(AlgorithmSuite.SOAPNormType.SOAPNormalization10, algorithmSuite.getSoapNormType());
98 assertEquals(AlgorithmSuite.STRType.STRTransform10, algorithmSuite.getStrType());
99 assertEquals(AlgorithmSuite.XPathType.AbsXPath, algorithmSuite.getXPathType());
100 }
101 }