jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1372328 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java test/java/org/apache/jackrabbit/oak/jcr/ValueFactoryTest.java
Date Mon, 13 Aug 2012 09:02:23 GMT
Author: angela
Date: Mon Aug 13 09:02:22 2012
New Revision: 1372328

URL: http://svn.apache.org/viewvc?rev=1372328&view=rev
Log:
OAK-238 ValueFactory: Missing identifier validation when creating (weak)reference value from
String

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValueFactoryTest.java
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java?rev=1372328&r1=1372327&r2=1372328&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
Mon Aug 13 09:02:22 2012
@@ -37,6 +37,7 @@ import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.util.Calendar;
+import java.util.UUID;
 
 /**
  * Implementation of {@link ValueFactory} interface based on the
@@ -185,6 +186,17 @@ public class ValueFactoryImpl implements
                     cv = factory.createValue(value, type);
                     break;
 
+                case PropertyType.REFERENCE:
+                case PropertyType.WEAKREFERENCE:
+                    // TODO: move to identifier/uuid management utility instead of relying
on impl specific uuid-format here.
+                    try {
+                        UUID.fromString(value);
+                    } catch (IllegalArgumentException e) {
+                        throw new ValueFormatException(e);
+                    }
+                    cv = factory.createValue(value, type);
+                    break;
+
                 case PropertyType.BINARY:
                     cv = factory.createValue(new ByteArrayInputStream(value.getBytes("UTF-8")));
                     break;

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValueFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValueFactoryTest.java?rev=1372328&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValueFactoryTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ValueFactoryTest.java
Mon Aug 13 09:02:22 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.apache.jackrabbit.oak.jcr;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * ValueFactoryTest...
+ */
+public class ValueFactoryTest extends AbstractRepositoryTest {
+
+    private static final String TEST_NODE = "test_node";
+
+    private ValueFactory valueFactory;
+
+    @Before
+    public void setup() throws RepositoryException {
+        Session session = getSession();
+        valueFactory = session.getValueFactory();
+    }
+
+    // TODO: this tests should be moved to the TCK. retrieving "invalidIdentifier" from the
config.
+
+    @Test
+    public void testReferenceValue() {
+        try {
+            valueFactory.createValue("invalidIdentifier", PropertyType.REFERENCE);
+            fail("Conversion to REFERENCE value must validate identifier string ");
+        } catch (ValueFormatException e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testWeakReferenceValue() {
+        try {
+            valueFactory.createValue("invalidIdentifier", PropertyType.WEAKREFERENCE);
+            fail("Conversion to WEAK_REFERENCE value must validate identifier string ");
+        } catch (ValueFormatException e) {
+            // success
+        }
+    }
+
+}
\ No newline at end of file



Mime
View raw message