aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/provider
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2023-10-20 13:23:33 +0530
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2023-10-20 13:24:11 +0530
commitcb9bd650a1ba6c1c2f5c7dd410f640b9b6f876c7 (patch)
tree18ae49eb64806a3687d388d24a35276361759d3e /sdnr/wt/data-provider/provider
parent70cc4c4295376e4af9cb9009a6ee5ddc389d61d9 (diff)
Extend user settings API
Extend user settings API Issue-ID: CCSDK-3947 Change-Id: Ic0e7783abb2b084142c5bc2d36dc31810f6ca9cf Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/provider')
-rw-r--r--sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java2
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java58
-rw-r--r--sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json7
3 files changed, 64 insertions, 3 deletions
diff --git a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
index 92bccce6f..1346e7e44 100644
--- a/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
+++ b/sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/UserdataHttpServlet.java
@@ -47,7 +47,7 @@ public class UserdataHttpServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(UserdataHttpServlet.class);
- private static final String REGEX = "^\\/userdata[\\/]?([a-zA-Z0-9]+)?$";
+ private static final String REGEX = "^\\/userdata[\\/]?([a-zA-Z0-9\\.]+)?$";
private static final Pattern PATTERN = Pattern.compile(REGEX);
private static final String JWT_PAYLOAD_USERNAME_PROPERTYKEY = "sub";
private static HtUserdataManager dbUserManager;
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java
index ce4044780..79c4dd185 100644
--- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java
+++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java
@@ -21,10 +21,12 @@
*/
package org.onap.ccsdk.features.sdnr.wt.dataprovider.test;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
import org.apache.sshd.common.util.io.IoUtils;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
@@ -36,6 +38,8 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
public class TestUserdata {
private static final String USERNAME = "admin132";
+ private static final String USERNAME2 = "admin133";
+
private static HtDatabaseClient dbRawProvider;
private static HtUserdataManagerImpl userDbProvider;
@@ -45,6 +49,7 @@ public class TestUserdata {
HostInfo[] hosts = HostInfoForTest.get();
dbRawProvider = HtDatabaseClient.getClient(hosts);
userDbProvider = new HtUserdataManagerImpl(dbRawProvider);
+
}
public static void trySleep(long ms) {
@@ -89,6 +94,55 @@ public class TestUserdata {
JSONAssert.assertEquals(mergedContent, userdata, false);
}
+ @Test
+ public void test2() {
+ String fullContent = "";
+ boolean success = false;
+ try {
+ fullContent = getFileContent("/userdata/full.json");
+ success = userDbProvider.setUserdata(USERNAME2, fullContent);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertTrue("problem writing data into db",success);
+
+ trySleep(2000);
+ // read with complex key
+ String userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling");
+ JSONAssert.assertEquals("{\"theme\": \"dark\"}", userdata, false);
+ userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.startupPosition.longitude");
+ assertEquals("\"13.35\"", userdata);
+ userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.tileOpacity");
+ assertEquals("\"26\"", userdata);
+
+ // write with complex key => forbidden
+ success = userDbProvider.setUserdata(USERNAME2,"networkMap.styling.theme",null);
+ assertFalse(success);
+ success = userDbProvider.setUserdata(USERNAME2,"networkMap.themes.key","\"abc\"");
+ assertFalse(success);
+ // write with complex key => allowed
+ success = userDbProvider.setUserdata(USERNAME2,"networkMap.styling.theme","\"test\"");
+ assertTrue(success);
+ userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling.theme");
+ assertEquals("\"test\"",userdata);
+ success = userDbProvider.setUserdata(USERNAME2,"networkMap.styling.theme","{\"test\":\"abc\"}");
+ assertTrue(success);
+ userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling.theme");
+ assertEquals("{\"test\":\"abc\"}",userdata);
+
+ // delete with complex key => forbidden
+ success = userDbProvider.removeUserdata(USERNAME2,"networkMap.styling.theme2");
+ assertFalse(success);
+ // delete with complex key => allowed
+ success = userDbProvider.removeUserdata(USERNAME2,"networkMap.styling.theme");
+ assertTrue(success);
+ userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling");
+ assertEquals("{}",userdata);
+
+
+ }
+
private static String getFileContent(String filename) throws IOException {
return String.join("\n", IoUtils.readAllLines(TestUserdata.class.getResourceAsStream(filename)));
}
diff --git a/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json b/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
index c5b41ec21..4206ddc31 100644
--- a/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
+++ b/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
@@ -8,6 +8,13 @@
"zoom": "10",
"longitude": "13.35"
},
+ "themes": [
+ {
+ "key": "light",
+ "padding": 10,
+ "mainColor": "#ff0000"
+ }
+ ],
"tileOpacity": "26"
}
} \ No newline at end of file