diff --git a/src/test/java/org/owasp/esapi/reference/crypto/EncryptedPropertiesUtilsTest.java b/src/test/java/org/owasp/esapi/reference/crypto/EncryptedPropertiesUtilsTest.java index 0f6704881..240e28867 100644 --- a/src/test/java/org/owasp/esapi/reference/crypto/EncryptedPropertiesUtilsTest.java +++ b/src/test/java/org/owasp/esapi/reference/crypto/EncryptedPropertiesUtilsTest.java @@ -89,15 +89,27 @@ private final File getTempPropertiesFile() throws IOException { Object prop2 = EncryptedPropertiesUtils.addProperty(props, KEY2, VALUE2); assertNull("Expected null but returned: " + prop2, prop2); - //store the file - EncryptedPropertiesUtils.storeProperties(encryptedFile.getAbsolutePath(), props, "Encrypted Properties File generated by EncryptedPropertiesUtilsTest"); - - //try reading in the resulting file - ReferenceEncryptedProperties loadedProps = new ReferenceEncryptedProperties(); - loadedProps.load(new FileReader(encryptedFile.getAbsolutePath())); - - assertEquals(VALUE1, loadedProps.getProperty(KEY1)); - assertEquals(VALUE2, loadedProps.getProperty(KEY2)); + // Probing for support of storeProperties due to Java 11 and GH #721 + boolean supported = true; + try { + //store the file + EncryptedPropertiesUtils.storeProperties(encryptedFile.getAbsolutePath(), props, "Encrypted Properties File generated by EncryptedPropertiesUtilsTest"); + } + catch ( UnsupportedOperationException ex ) { + supported = false; + } + + if ( supported ) { + //try reading in the resulting file + ReferenceEncryptedProperties loadedProps = new ReferenceEncryptedProperties(); + loadedProps.load(new FileReader(encryptedFile.getAbsolutePath())); + + assertEquals(VALUE1, loadedProps.getProperty(KEY1)); + assertEquals(VALUE2, loadedProps.getProperty(KEY2)); + } + else { + System.out.println("Skipping testCreateNew... storeProperties is not supported."); + } } /** @@ -113,7 +125,7 @@ private final File getTempPropertiesFile() throws IOException { File encryptedFile = getTempPropertiesFile(); File plainTextFile = getTempPropertiesFile(); - //write an initial plaintext properties file + //write an initial plaintext properties file Properties props = new Properties(); props.setProperty(KEY3, VALUE3); props.setProperty(KEY4, VALUE4); @@ -127,15 +139,27 @@ private final File getTempPropertiesFile() throws IOException { assertEquals(VALUE3, props.getProperty(KEY3)); assertEquals(VALUE4, props.getProperty(KEY4)); - //store the file - EncryptedPropertiesUtils.storeProperties(encryptedFile.getAbsolutePath(), props, "Encrypted Properties File generated by EncryptedPropertiesUtilsTest"); - - //try reading in the resulting file - ReferenceEncryptedProperties loadedProps = new ReferenceEncryptedProperties(); - loadedProps.load(new FileReader(encryptedFile.getAbsolutePath())); - - assertEquals(VALUE3, loadedProps.getProperty(KEY3)); - assertEquals(VALUE4, loadedProps.getProperty(KEY4)); + // Probing for support of storeProperties due to Java 11 and GH #721 + boolean supported = true; + try { + //store the file + EncryptedPropertiesUtils.storeProperties(encryptedFile.getAbsolutePath(), props, "Encrypted Properties File generated by EncryptedPropertiesUtilsTest"); + } + catch ( UnsupportedOperationException ex ) { + supported = false; + } + + if ( supported ) { + //try reading in the resulting file + ReferenceEncryptedProperties loadedProps = new ReferenceEncryptedProperties(); + loadedProps.load(new FileReader(encryptedFile.getAbsolutePath())); + + assertEquals(VALUE3, loadedProps.getProperty(KEY3)); + assertEquals(VALUE4, loadedProps.getProperty(KEY4)); + } + else { + System.out.println("Skipping testLoadPlaintextAndEncrypt... storeProperties is not supported."); + } } /** @@ -161,16 +185,28 @@ private final File getTempPropertiesFile() throws IOException { assertEquals(VALUE1, props.getProperty(KEY1)); assertEquals(VALUE2, props.getProperty(KEY2)); - //store the file - EncryptedPropertiesUtils.storeProperties(encryptedFile2.getAbsolutePath(), props, "Encrypted Properties File generated by EncryptedPropertiesUtilsTest"); - - //try reading in the resulting file - ReferenceEncryptedProperties loadedProps = new ReferenceEncryptedProperties(); - loadedProps.load(new FileReader(encryptedFile2.getAbsolutePath())); - - //test the values read in - assertEquals(VALUE1, loadedProps.getProperty(KEY1)); - assertEquals(VALUE2, loadedProps.getProperty(KEY2)); + // Probing for support of storeProperties due to Java 11 and GH #721 + boolean supported = true; + try { + //store the file + EncryptedPropertiesUtils.storeProperties(encryptedFile2.getAbsolutePath(), props, "Encrypted Properties File generated by EncryptedPropertiesUtilsTest"); + } + catch ( UnsupportedOperationException ex ) { + supported = false; + } + + if ( supported ) { + //try reading in the resulting file + ReferenceEncryptedProperties loadedProps = new ReferenceEncryptedProperties(); + loadedProps.load(new FileReader(encryptedFile2.getAbsolutePath())); + + //test the values read in + assertEquals(VALUE1, loadedProps.getProperty(KEY1)); + assertEquals(VALUE2, loadedProps.getProperty(KEY2)); + } + else { + System.out.println("Skipping testLoadEncryptedAndAdd... storeProperties is not supported."); + } } } diff --git a/src/test/java/org/owasp/esapi/reference/crypto/ReferenceEncryptedPropertiesTest.java b/src/test/java/org/owasp/esapi/reference/crypto/ReferenceEncryptedPropertiesTest.java index 386e439f8..a7ac9c477 100644 --- a/src/test/java/org/owasp/esapi/reference/crypto/ReferenceEncryptedPropertiesTest.java +++ b/src/test/java/org/owasp/esapi/reference/crypto/ReferenceEncryptedPropertiesTest.java @@ -154,50 +154,63 @@ else if(key.equals("two")) boolean sawSeuss = false; ReferenceEncryptedProperties toStore = new ReferenceEncryptedProperties(); - toStore.setProperty("one", "two"); - toStore.setProperty("two", "three"); - toStore.setProperty("seuss.schneier", "one fish, twofish, red fish, blowfish"); - toStore.store(baos, "testStore"); - bais = new ByteArrayInputStream(baos.toByteArray()); - toLoad.load(bais); + // Probing for support of store due to Java 11 and GH #721 + boolean supported = true; + try { + toStore.setProperty("one", "two"); + toStore.setProperty("two", "three"); + toStore.setProperty("seuss.schneier", "one fish, twofish, red fish, blowfish"); + toStore.store(baos, "testStore"); + } + catch ( UnsupportedOperationException ex ) { + supported = false; + } - for(Iterator i=toLoad.keySet().iterator();i.hasNext();) - { - String key = (String)i.next(); + if ( supported ) { + bais = new ByteArrayInputStream(baos.toByteArray()); + toLoad.load(bais); - assertNotNull("key returned from keySet() iterator was null", key); - if(key.equals("one")) - if(sawOne) - fail("Key one seen more than once."); - else - { - sawOne = true; - assertEquals("Key one's value was not two", "two", toLoad.getProperty("one")); - } - else if(key.equals("two")) - if(sawTwo) - fail("Key two seen more than once."); - else - { - sawTwo = true; - assertEquals("Key two's value was not three", "three", toLoad.getProperty("two")); - } - else if(key.equals("seuss.schneier")) - if(sawSeuss) - fail("Key seuss.schneier seen more than once."); + for(Iterator i=toLoad.keySet().iterator();i.hasNext();) + { + String key = (String)i.next(); + + assertNotNull("key returned from keySet() iterator was null", key); + if(key.equals("one")) + if(sawOne) + fail("Key one seen more than once."); else { - sawSeuss = true; - assertEquals("Key seuss.schneier's value was not expected value", - "one fish, twofish, red fish, blowfish", - toStore.getProperty("seuss.schneier")); + sawOne = true; + assertEquals("Key one's value was not two", "two", toLoad.getProperty("one")); } - else - fail("Unset key " + key + " returned from keySet().iterator()"); + else if(key.equals("two")) + if(sawTwo) + fail("Key two seen more than once."); + else + { + sawTwo = true; + assertEquals("Key two's value was not three", "three", toLoad.getProperty("two")); + } + else if(key.equals("seuss.schneier")) + if(sawSeuss) + fail("Key seuss.schneier seen more than once."); + else + { + sawSeuss = true; + assertEquals("Key seuss.schneier's value was not expected value", + "one fish, twofish, red fish, blowfish", + toStore.getProperty("seuss.schneier")); + } + else + fail("Unset key " + key + " returned from keySet().iterator()"); + } + assertTrue("Key one was never seen", sawOne); + assertTrue("Key two was never seen", sawTwo); + } + else { + System.out.println("Skipping testStoreLoad... store is not supported."); } - assertTrue("Key one was never seen", sawOne); - assertTrue("Key two was never seen", sawTwo); } /** @@ -205,7 +218,7 @@ else if(key.equals("seuss.schneier")) */ @Test public void testStoreLoadWithReader() throws Exception { -/* + /* //create an EncryptedProperties to store ReferenceEncryptedProperties toStore = new ReferenceEncryptedProperties(); toStore.setProperty("one", "two"); @@ -263,7 +276,7 @@ else if(key.equals("seuss.schneier")) } assertTrue("Key one was never seen", sawOne); assertTrue("Key two was never seen", sawTwo); -*/ + */ } /**