You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2014/06/24 02:23:04 UTC

svn commit: r1604966 - in /ofbiz/trunk/framework/entity: entitydef/entitymodel_test.xml src/org/ofbiz/entity/test/EntityCryptoTestSuite.java testdef/entitytests.xml

Author: doogie
Date: Tue Jun 24 00:23:04 2014
New Revision: 1604966

URL: http://svn.apache.org/r1604966
Log:
Start creating test cases for the entity engine crypto feature.

Added:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java
Modified:
    ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml
    ofbiz/trunk/framework/entity/testdef/entitytests.xml

Modified: ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml?rev=1604966&r1=1604965&r2=1604966&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml (original)
+++ ofbiz/trunk/framework/entity/entitydef/entitymodel_test.xml Tue Jun 24 00:23:04 2014
@@ -186,4 +186,28 @@ under the License.
         <key-map field-name="testingId"/>
       </relation>
     </view-entity>
+
+    <!-- =========================================================
+    The testing entity is a basic entity with a type
+    ========================================================= -->
+    <entity entity-name="TestingCrypto"
+        package-name="org.ofbiz.entity.test"
+        title="Testing Crypto Entity">
+        <field name="testingCryptoId" type="id-ne"/>
+        <field name="testingCryptoTypeId" type="id-ne"/>
+        <field name="unencryptedValue" type="description"/>
+        <field name="encryptedValue" type="description" encrypt="true"/>
+        <prim-key field="testingCryptoId"/>
+    </entity>
+    <view-entity entity-name="TestingCryptoRawView"
+            package-name="org.ofbiz.entity.test"
+            title="TestingCrypto Raw View">
+      <member-entity entity-alias="TC" entity-name="TestingCrypto"/>
+      <alias-all entity-alias="TC"/>
+      <alias name="rawEncryptedValue">
+        <complex-alias operator="+">
+          <complex-alias-field entity-alias="TC" field="encryptedValue"/>
+        </complex-alias>
+      </alias>
+    </view-entity>
 </entitymodel>

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java?rev=1604966&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityCryptoTestSuite.java Tue Jun 24 00:23:04 2014
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.entity.test;
+
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.testtools.EntityTestCase;
+
+public class EntityCryptoTestSuite extends EntityTestCase {
+    public EntityCryptoTestSuite(String name) {
+        super(name);
+    }
+
+    public void testCryptoEncryption() throws Exception {
+        // clear out all values
+        delegator.removeByAnd("TestingCrypto", UtilMisc.toMap("testingCryptoTypeId", "BASIC"));
+
+        String nanoTime = "" + System.nanoTime();
+
+        // Ensure that null values are passed thru unencrypted.
+        delegator.create("TestingCrypto", UtilMisc.toMap("testingCryptoId", "1", "testingCryptoTypeId", "BASIC"));
+        GenericValue entity = delegator.findOne("TestingCrypto", UtilMisc.toMap("testingCryptoId", "1"), false);
+        assertNull(entity.getString("unencryptedValue"));
+        assertNull(entity.getString("encryptedValue"));
+        GenericValue view = delegator.findOne("TestingCryptoRawView", UtilMisc.toMap("testingCryptoId", "1"), false);
+        assertNull(view.getString("unencryptedValue"));
+        assertNull(view.getString("encryptedValue"));
+        assertNull(view.getString("rawEncryptedValue"));
+
+        // Verify that encryption is taking place
+        entity.setString("unencryptedValue", nanoTime);
+        entity.setString("encryptedValue", nanoTime);
+        entity.store();
+        view.refresh();
+        assertEquals(nanoTime, view.getString("unencryptedValue"));
+        assertEquals(nanoTime, view.getString("encryptedValue"));
+
+        String initialValue = view.getString("rawEncryptedValue");
+        assertFalse(nanoTime.equals(initialValue));
+
+        // Verify that the same value stored repeatedly gives different raw encrypted values.
+        entity.setString("encryptedValue", nanoTime);
+        entity.store();
+        entity.refresh(); // this is a bug; store() ends up setting the encrypted value *into* the entity
+        assertEquals(nanoTime, entity.getString("unencryptedValue"));
+        assertEquals(nanoTime, entity.getString("encryptedValue"));
+
+        view.refresh();
+        assertEquals(nanoTime, view.getString("unencryptedValue"));
+        assertEquals(nanoTime, view.getString("encryptedValue"));
+
+        String updatedValue = view.getString("rawEncryptedValue");
+        assertFalse(nanoTime.equals(updatedValue));
+        assertFalse(initialValue.equals(updatedValue));
+    }
+}

Modified: ofbiz/trunk/framework/entity/testdef/entitytests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/testdef/entitytests.xml?rev=1604966&r1=1604965&r2=1604966&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/testdef/entitytests.xml (original)
+++ ofbiz/trunk/framework/entity/testdef/entitytests.xml Tue Jun 24 00:23:04 2014
@@ -22,6 +22,7 @@ under the License.
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
     <test-case case-name="entity-tests"><junit-test-suite class-name="org.ofbiz.entity.test.EntityTestSuite"/></test-case>
+    <test-case case-name="entity-crypto-tests"><junit-test-suite class-name="org.ofbiz.entity.test.EntityCryptoTestSuite"/></test-case>
     <test-case case-name="entity-util-properties-tests">
         <simple-method-test location="component://entity/script/org/ofbiz/entity/test/EntityUtilPropertiesTests.xml"/>
     </test-case>