You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2026/10/14 08:14:56 UTC

(ws-wss4j) branch 3_0_x-fixes updated: More test codeql fixes (#754)

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 22d0667a6 More test codeql fixes (#754)
22d0667a6 is described below

commit 22d0667a69900f144bf196d5d7977ff2d025def3
Author: Colm O hEigeartaigh <co...@users.noreply.github.com>
AuthorDate: Wed Oct 14 09:10:02 2026 +0100

    More test codeql fixes (#754)
---
 .../wss4j/common/attachment/CRLFOutputStreamTest.java    |  4 ++--
 .../wss4j/common/util/CommaDelimiterRfc2253NameTest.java |  5 +++--
 .../wss4j/policy/stax/test/AbstractPolicyTestBase.java   | 16 +++++++++-------
 .../wss4j/policy/stax/test/TokenProtectionTest.java      | 12 ------------
 .../org/apache/wss4j/stax/test/AbstractTestBase.java     |  8 --------
 5 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/ws-security-common/src/test/java/org/apache/wss4j/common/attachment/CRLFOutputStreamTest.java b/ws-security-common/src/test/java/org/apache/wss4j/common/attachment/CRLFOutputStreamTest.java
index 6c6c47690..2bc99d5d6 100644
--- a/ws-security-common/src/test/java/org/apache/wss4j/common/attachment/CRLFOutputStreamTest.java
+++ b/ws-security-common/src/test/java/org/apache/wss4j/common/attachment/CRLFOutputStreamTest.java
@@ -101,10 +101,10 @@ public class CRLFOutputStreamTest {
         for (int i = 0; i < res.length; i++) {
             byte re = res[i];
             if (re == '\r') {
-                if (res[i + 1] != '\n') {
+                if (i + 1 == res.length || res[i + 1] != '\n') {
                     throw new Exception("Missing \\n in\n" + createEscapedString(res) + "\n input string: " + createEscapedString(testString.toByteArray()));
                 }
-            } else if (re == '\n' && res[i - 1] != '\r') {
+            } else if (re == '\n' && (i == 0 || res[i - 1] != '\r')) {
                 throw new Exception("Missing \\r in\n" + createEscapedString(res) + "\n input string: " + createEscapedString(testString.toByteArray()));
             }
         }
diff --git a/ws-security-common/src/test/java/org/apache/wss4j/common/util/CommaDelimiterRfc2253NameTest.java b/ws-security-common/src/test/java/org/apache/wss4j/common/util/CommaDelimiterRfc2253NameTest.java
index 896a8d87c..bdfa1a14f 100644
--- a/ws-security-common/src/test/java/org/apache/wss4j/common/util/CommaDelimiterRfc2253NameTest.java
+++ b/ws-security-common/src/test/java/org/apache/wss4j/common/util/CommaDelimiterRfc2253NameTest.java
@@ -120,10 +120,11 @@ class CommaDelimiterRfc2253NameTest {
 
 	private KeyStore loadDefaultKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
 		String filename = System.getProperty("java.home") + "/lib/security/cacerts".replace('/', File.separatorChar);
-		FileInputStream is = new FileInputStream(filename);
 		KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
 		String password = "changeit";
-		keystore.load(is, password.toCharArray());
+		try (FileInputStream is = new FileInputStream(filename)) {
+			keystore.load(is, password.toCharArray());
+		}
 		return keystore;
 	}
 
diff --git a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/AbstractPolicyTestBase.java b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/AbstractPolicyTestBase.java
index c1f79f1a5..da0273bec 100644
--- a/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/AbstractPolicyTestBase.java
+++ b/ws-security-policy-stax/src/test/java/org/apache/wss4j/policy/stax/test/AbstractPolicyTestBase.java
@@ -178,14 +178,16 @@ public class AbstractPolicyTestBase extends AbstractTestBase {
     }
 
     protected String loadResourceAsString(String resource, Charset encoding) throws IOException {
-        InputStreamReader inputStreamReader = new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(resource), encoding);
-        StringBuilder stringBuilder = new StringBuilder();
-        int read = 0;
-        char[] buffer = new char[1024];
-        while ((read = inputStreamReader.read(buffer)) != -1) {
-            stringBuilder.append(buffer, 0, read);
+        try (InputStreamReader inputStreamReader =
+                 new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(resource), encoding)) {
+            StringBuilder stringBuilder = new StringBuilder();
+            int read = 0;
+            char[] buffer = new char[1024];
+            while ((read = inputStreamReader.read(buffer)) != -1) {
+                stringBuilder.append(buffer, 0, read);
+            }
+            return stringBuilder.toString();
         }
-        return stringBuilder.toString();
     }
 
     public static SamlAssertionWrapper createSamlAssertionWrapper(SAMLCallback samlCallback) throws WSSecurityException {
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 dcb017b28..c984aa153 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
@@ -527,10 +527,6 @@ public class TokenProtectionTest extends AbstractPolicyTestBase {
         ekPath.addAll(WSSConstants.SOAP_11_WSSE_SECURITY_HEADER_PATH);
         ekPath.add(WSSConstants.TAG_xenc_EncryptedKey);
 
-        List<QName> sigPath = new ArrayList<>();
-        sigPath.addAll(WSSConstants.SOAP_11_WSSE_SECURITY_HEADER_PATH);
-        sigPath.add(WSSConstants.TAG_dsig_Signature);
-
         X509SecurityTokenImpl x509SecurityToken = getX509Token(WSSecurityTokenConstants.X509V3Token);
         x509SecurityToken.addTokenUsage(WSSecurityTokenConstants.TOKENUSAGE_MAIN_SIGNATURE);
         x509SecurityToken.setElementPath(bstPath);
@@ -594,10 +590,6 @@ public class TokenProtectionTest extends AbstractPolicyTestBase {
         ekPath.addAll(WSSConstants.SOAP_11_WSSE_SECURITY_HEADER_PATH);
         ekPath.add(WSSConstants.TAG_xenc_EncryptedKey);
 
-        List<QName> sigPath = new ArrayList<>();
-        sigPath.addAll(WSSConstants.SOAP_11_WSSE_SECURITY_HEADER_PATH);
-        sigPath.add(WSSConstants.TAG_dsig_Signature);
-
         X509SecurityTokenImpl x509SecurityToken = getX509Token(WSSecurityTokenConstants.X509V3Token);
         x509SecurityToken.addTokenUsage(WSSecurityTokenConstants.TOKENUSAGE_MAIN_SIGNATURE);
         x509SecurityToken.setElementPath(bstPath);
@@ -667,10 +659,6 @@ public class TokenProtectionTest extends AbstractPolicyTestBase {
         ekPath.addAll(WSSConstants.SOAP_11_WSSE_SECURITY_HEADER_PATH);
         ekPath.add(WSSConstants.TAG_xenc_EncryptedKey);
 
-        List<QName> sigPath = new ArrayList<>();
-        sigPath.addAll(WSSConstants.SOAP_11_WSSE_SECURITY_HEADER_PATH);
-        sigPath.add(WSSConstants.TAG_dsig_Signature);
-
         X509SecurityTokenImpl x509SecurityToken = getX509Token(WSSecurityTokenConstants.X509V3Token);
         x509SecurityToken.addTokenUsage(WSSecurityTokenConstants.TOKENUSAGE_MAIN_SIGNATURE);
         x509SecurityToken.setElementPath(bstPath);
diff --git a/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java b/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
index a6d9939e3..0fd619888 100644
--- a/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
+++ b/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
@@ -693,12 +693,4 @@ public abstract class AbstractTestBase {
             }
         }
     }
-
-    public static Double getJavaSpecificationVersion() {
-        String jsv = System.getProperty("java.specification.version");
-        if (jsv != null) {
-            return Double.parseDouble(jsv);
-        }
-        return 0.0d;
-    }
 }
\ No newline at end of file