Security issues fixes
[dmaap/messagerouter/msgrtr.git] / src / test / java / com / att / nsa / cambria / service / impl / AdminServiceImplemTest.java
index b2db07e..df486d5 100644 (file)
@@ -25,23 +25,51 @@ package com.att.nsa.cambria.service.impl;
 import static org.junit.Assert.*;\r
 \r
 import java.io.IOException;\r
+import java.util.Date;\r
 \r
 import com.att.nsa.cambria.beans.DMaaPContext;\r
+import com.att.nsa.cambria.embed.EmbedConfigurationReader;\r
+import com.att.nsa.cambria.utils.ConfigurationReader;\r
 import com.att.nsa.configs.ConfigDbException;\r
+import com.att.nsa.drumlin.till.data.sha1HmacSigner;\r
 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
 \r
-import org.junit.After;\r
-import org.junit.Before;\r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
 import org.junit.Test;\r
+import org.springframework.mock.web.MockHttpServletRequest;\r
+import org.springframework.mock.web.MockHttpServletResponse;\r
 \r
 public class AdminServiceImplemTest {\r
+       \r
+       private static  DMaaPContext context = new DMaaPContext();\r
+       \r
+       private static EmbedConfigurationReader embedConfigurationReader = new EmbedConfigurationReader();\r
+\r
+       @BeforeClass\r
+       public static void setUp() throws Exception {\r
+\r
+               final long nowMs = System.currentTimeMillis();\r
+               Date date = new Date(nowMs + 10000);\r
+\r
+               final String serverCalculatedSignature = sha1HmacSigner.sign(date.toString(), "password");\r
+               MockHttpServletRequest request = new MockHttpServletRequest();\r
+               request.addHeader("X-Auth", "admin:" + serverCalculatedSignature);\r
+\r
+               //NsaSimpleApiKey apiKey = new NsaSimpleApiKey("admin", "password");\r
+       //      PowerMockito.when(baseNsaApiDbImpl.loadApiKey("b/7ouTn9FfEw2PQwL0ov/Q==")).thenReturn(apiKey);\r
 \r
-       @Before\r
-       public void setUp() throws Exception {\r
+               request.addHeader("X-Date", date);\r
+               request.addHeader("Date", date);\r
+               MockHttpServletResponse response = new MockHttpServletResponse();\r
+               context.setRequest(request);\r
+               context.setResponse(response);\r
+               context.setConfigReader(embedConfigurationReader.buildConfigurationReader());\r
        }\r
 \r
-       @After\r
-       public void tearDown() throws Exception {\r
+       @AfterClass\r
+       public static void tearDown() throws Exception {\r
+               embedConfigurationReader.tearDown();\r
        }\r
 \r
        \r
@@ -51,7 +79,7 @@ public class AdminServiceImplemTest {
                \r
                AdminServiceImpl adminServiceImpl = new AdminServiceImpl();\r
                try {\r
-                       adminServiceImpl.showConsumerCache(new DMaaPContext());\r
+                       adminServiceImpl.showConsumerCache(context);\r
                } catch (IOException | AccessDeniedException e) {\r
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
@@ -73,7 +101,7 @@ public class AdminServiceImplemTest {
                \r
                AdminServiceImpl adminServiceImpl = new AdminServiceImpl();\r
                try {\r
-                       adminServiceImpl.dropConsumerCache(new DMaaPContext());\r
+                       adminServiceImpl.dropConsumerCache(context);\r
                } catch (IOException | AccessDeniedException e) {\r
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
@@ -95,7 +123,7 @@ public class AdminServiceImplemTest {
                \r
                AdminServiceImpl adminServiceImpl = new AdminServiceImpl();\r
                try {\r
-                       adminServiceImpl.getBlacklist(new DMaaPContext());\r
+                       adminServiceImpl.getBlacklist(context);\r
                } catch (IOException | AccessDeniedException e) {\r
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
@@ -117,7 +145,7 @@ public class AdminServiceImplemTest {
                \r
                AdminServiceImpl adminServiceImpl = new AdminServiceImpl();\r
                try {\r
-                       adminServiceImpl.addToBlacklist(new DMaaPContext(), "120.120.120.120");\r
+                       adminServiceImpl.addToBlacklist(context, "120.120.120.120");\r
                } catch (IOException | AccessDeniedException | ConfigDbException e) {\r
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r
@@ -139,7 +167,7 @@ public class AdminServiceImplemTest {
                \r
                AdminServiceImpl adminServiceImpl = new AdminServiceImpl();\r
                try {\r
-                       adminServiceImpl.addToBlacklist(new DMaaPContext(), "120.120.120.120");\r
+                       adminServiceImpl.addToBlacklist(context, "120.120.120.120");\r
                } catch (IOException | AccessDeniedException | ConfigDbException e) {\r
                        // TODO Auto-generated catch block\r
                        e.printStackTrace();\r