This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3_0_x-fixes
in repository https://gitbox.apache.org/repos/asf/ws-wss4j.git


The following commit(s) were added to refs/heads/3_0_x-fixes by this push:
     new 0ae03dd99 Fail negative policy tests when nothing throws (#770)
0ae03dd99 is described below

commit 0ae03dd990364934afdab11b134d103b3128dd67
Author: Sharang Gupta <[email protected]>
AuthorDate: Thu Nov 5 11:23:15 2026 +0000

    Fail negative policy tests when nothing throws (#770)
    
    Six negative tests in EncryptedPartsTest, SignedPartsTest and
    TokenProtectionTest checked the policy violation only in the catch
    block, so they passed if the enforcer accepted the message. Add the
    fail() their sibling tests already have.
---
 .../java/org/apache/wss4j/policy/stax/test/EncryptedPartsTest.java    | 1 +
 .../test/java/org/apache/wss4j/policy/stax/test/SignedPartsTest.java  | 1 +
 .../java/org/apache/wss4j/policy/stax/test/TokenProtectionTest.java   | 4 ++++
 3 files changed, 6 insertions(+)

diff --git 
a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/EncryptedPartsTest.java
 
b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/EncryptedPartsTest.java
index 7d197d55e..c7bdd9a18 100644
--- 
a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/EncryptedPartsTest.java
+++ 
b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/EncryptedPartsTest.java
@@ -154,6 +154,7 @@ public class EncryptedPartsTest extends 
AbstractPolicyTestBase {
         
encryptedPartSecurityEvent.setElementPath(WSSConstants.SOAP_11_BODY_PATH);
         try {
             policyEnforcer.registerSecurityEvent(encryptedPartSecurityEvent);
+            fail("Exception expected");
         } catch (WSSecurityException e) {
             assertTrue(e.getCause() instanceof PolicyViolationException);
             assertEquals(e.getCause().getMessage(),
diff --git 
a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/SignedPartsTest.java
 
b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/SignedPartsTest.java
index 6dd4b9176..915a5eba1 100644
--- 
a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/SignedPartsTest.java
+++ 
b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/SignedPartsTest.java
@@ -160,6 +160,7 @@ public class SignedPartsTest extends AbstractPolicyTestBase 
{
         signedPartSecurityEvent.setElementPath(WSSConstants.SOAP_11_BODY_PATH);
         try {
             policyEnforcer.registerSecurityEvent(signedPartSecurityEvent);
+            fail("Exception expected");
         } catch (WSSecurityException e) {
             assertTrue(e.getCause() instanceof PolicyViolationException);
             assertEquals(e.getCause().getMessage(),
diff --git 
a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/TokenProtectionTest.java
 
b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/TokenProtectionTest.java
index c984aa153..86f3434a2 100644
--- 
a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/TokenProtectionTest.java
+++ 
b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/TokenProtectionTest.java
@@ -216,6 +216,7 @@ public class TokenProtectionTest extends 
AbstractPolicyTestBase {
         operationSecurityEvent.setOperation(WSDL_DEFINITIONS);
         try {
             policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+            fail("Exception expected");
         } catch (WSSecurityException e) {
             assertTrue(e.getCause() instanceof PolicyViolationException);
             assertEquals(e.getCause().getMessage(),
@@ -431,6 +432,7 @@ public class TokenProtectionTest extends 
AbstractPolicyTestBase {
         operationSecurityEvent.setOperation(WSDL_DEFINITIONS);
         try {
             policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+            fail("Exception expected");
         } catch (WSSecurityException e) {
             assertTrue(e.getCause() instanceof PolicyViolationException);
             assertEquals(e.getCause().getMessage(),
@@ -493,6 +495,7 @@ public class TokenProtectionTest extends 
AbstractPolicyTestBase {
 
         try {
             policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+            fail("Exception expected");
         } catch (WSSecurityException e) {
             assertTrue(e.getCause() instanceof PolicyViolationException);
             assertEquals(e.getCause().getMessage(),
@@ -625,6 +628,7 @@ public class TokenProtectionTest extends 
AbstractPolicyTestBase {
 
         try {
             policyEnforcer.registerSecurityEvent(operationSecurityEvent);
+            fail("Exception expected");
         } catch (WSSecurityException e) {
             assertTrue(e.getCause() instanceof PolicyViolationException);
             assertEquals(e.getCause().getMessage(),

Reply via email to