aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/test/java/com/juick')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index abeb7424..9f573e82 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -17,6 +17,7 @@
package com.juick.server.tests;
+import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
@@ -59,6 +60,7 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
@@ -82,6 +84,7 @@ import java.io.*;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.sql.Timestamp;
import java.time.Instant;
@@ -1225,4 +1228,31 @@ public class ServerTests {
server.addConnectionIn(test);
assertThat(getStatus.get().getInbound().size(), is(1));
}
+ @Test
+ public void credentialsShouldNeverBeSerialized() throws Exception {
+ int uid = userService.createUser("yyy", "xxxx");
+ User yyy = userService.getUserByUID(uid).get();
+ assertThat(yyy.getCredentials(), is("xxxx"));
+ ObjectMapper jsonMapper = new ObjectMapper();
+ jsonMapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
+ String jsonUser = jsonMapper.writeValueAsString(yyy);
+ Map<String, Object> user = JsonPath.read(jsonUser, "$");
+ // only uid and name
+ assertThat(user.keySet().size(), is(2));
+
+ JAXBContext context = JAXBContext
+ .newInstance(User.class);
+ Marshaller m = context.createMarshaller();
+
+ StringWriter sw = new StringWriter();
+ m.marshal(yyy, sw);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(new ByteArrayInputStream(sw.toString().getBytes(StandardCharsets.UTF_8)));
+ Element juickNode = doc.getDocumentElement();
+ NamedNodeMap attrs = juickNode.getAttributes();
+ // uid, name, xmlns, xmlns:user
+ assertThat(attrs.getLength(), is(4));
+ }
}