test_class.file: cosmic-common/src/test/java/com/cloud/utils/HttpUtilsTest.java
test_class.identifier: HttpUtilsTest
test_case.body: @Test
      public void validateSessionKeyTest() {
          HttpSession session = null;
          Map<String, Object[]> params = null;
          String sessionKeyString = null;
          Cookie[] cookies = null;
          final String sessionKeyValue = "randomUniqueSessionID";
  
          // session and sessionKeyString null test
          assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
          sessionKeyString = "sessionkey";
          assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
  
          // param and cookie null test
          session = new MockHttpSession();
          session.setAttribute(sessionKeyString, sessionKeyValue);
          assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
  
          // param null, cookies not null test
          params = null;
          cookies = new Cookie[]{new Cookie(sessionKeyString, sessionKeyValue)};
          assertFalse(HttpUtils.validateSessionKey(session, params, cookies, "randomString"));
          assertTrue(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
  
          // param not null, cookies null test
          params = new HashMap<>();
          params.put(sessionKeyString, new String[]{"randomString"});
          cookies = null;
          assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
          params.put(sessionKeyString, new String[]{sessionKeyValue});
          assertTrue(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
  
          // both param and cookies not null test
          params = new HashMap<>();
          cookies = new Cookie[]{new Cookie(sessionKeyString, sessionKeyValue)};
          params.put(sessionKeyString, new String[]{"incorrectValue"});
          assertFalse(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
          params.put(sessionKeyString, new String[]{sessionKeyValue});
          assertTrue(HttpUtils.validateSessionKey(session, params, cookies, sessionKeyString));
      }
test_case.class_method_signature: HttpUtilsTest.validateSessionKeyTest()
test_case.full_signature: @Test public void validateSessionKeyTest()
test_case.identifier: validateSessionKeyTest
test_case.invocations: assertFalse validateSessionKey assertFalse validateSessionKey setAttribute assertFalse validateSessionKey assertFalse validateSessionKey assertTrue validateSessionKey put assertFalse validateSessionKey put assertTrue validateSessionKey put assertFalse validateSessionKey put assertTrue validateSessionKey
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void validateSessionKeyTest()
focal_class.declarator: s_logger = LoggerFactory.getLogger(HttpUtils.class)
focal_class.modifier: public static final
focal_class.original_string: public static final Logger s_logger = LoggerFactory.getLogger(HttpUtils.class);
focal_class.type: Logger
focal_class.var_name: s_logger
focal_class.declarator: UTF_8 = "UTF-8"
focal_class.modifier: public static final
focal_class.original_string: public static final String UTF_8 = "UTF-8";
focal_class.type: String
focal_class.var_name: UTF_8
focal_class.declarator: RESPONSE_TYPE_JSON = "json"
focal_class.modifier: public static final
focal_class.original_string: public static final String RESPONSE_TYPE_JSON = "json";
focal_class.type: String
focal_class.var_name: RESPONSE_TYPE_JSON
focal_class.declarator: RESPONSE_TYPE_XML = "xml"
focal_class.modifier: public static final
focal_class.original_string: public static final String RESPONSE_TYPE_XML = "xml";
focal_class.type: String
focal_class.var_name: RESPONSE_TYPE_XML
focal_class.declarator: JSON_CONTENT_TYPE = "application/json; charset=UTF-8"
focal_class.modifier: public static final
focal_class.original_string: public static final String JSON_CONTENT_TYPE = "application/json; charset=UTF-8";
focal_class.type: String
focal_class.var_name: JSON_CONTENT_TYPE
focal_class.declarator: XML_CONTENT_TYPE = "text/xml; charset=UTF-8"
focal_class.modifier: public static final
focal_class.original_string: public static final String XML_CONTENT_TYPE = "text/xml; charset=UTF-8";
focal_class.type: String
focal_class.var_name: XML_CONTENT_TYPE
focal_class.file: cosmic-common/src/main/java/com/cloud/utils/HttpUtils.java
focal_class.identifier: HttpUtils
focal_class.class_method_signature: HttpUtils.writeHttpResponse(final HttpServletResponse resp, final String response,
                                           final Integer responseCode, final String responseType, final String jsonContentType)
focal_class.full_signature: public static void writeHttpResponse(final HttpServletResponse resp, final String response,
                                           final Integer responseCode, final String responseType, final String jsonContentType)
focal_class.identifier: writeHttpResponse
focal_class.modifiers: public static
focal_class.parameters: (final HttpServletResponse resp, final String response,
                                           final Integer responseCode, final String responseType, final String jsonContentType)
focal_class.return: void
focal_class.signature: void writeHttpResponse(final HttpServletResponse resp, final String response,
                                           final Integer responseCode, final String responseType, final String jsonContentType)
focal_class.class_method_signature: HttpUtils.addSecurityHeaders(final HttpServletResponse resp)
focal_class.full_signature: public static void addSecurityHeaders(final HttpServletResponse resp)
focal_class.identifier: addSecurityHeaders
focal_class.modifiers: public static
focal_class.parameters: (final HttpServletResponse resp)
focal_class.return: void
focal_class.signature: void addSecurityHeaders(final HttpServletResponse resp)
focal_class.class_method_signature: HttpUtils.validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_class.full_signature: public static boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_class.identifier: validateSessionKey
focal_class.modifiers: public static
focal_class.parameters: (final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_class.return: boolean
focal_class.signature: boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_class.class_method_signature: HttpUtils.findCookie(final Cookie[] cookies, final String key)
focal_class.full_signature: public static String findCookie(final Cookie[] cookies, final String key)
focal_class.identifier: findCookie
focal_class.modifiers: public static
focal_class.parameters: (final Cookie[] cookies, final String key)
focal_class.return: String
focal_class.signature: String findCookie(final Cookie[] cookies, final String key)
focal_method.body: public static boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString) {
          if (session == null || sessionKeyString == null) {
              return false;
          }
          final String sessionKey = (String) session.getAttribute(sessionKeyString);
          final String sessionKeyFromCookie = HttpUtils.findCookie(cookies, sessionKeyString);
          String[] sessionKeyFromParams = null;
          if (params != null) {
              sessionKeyFromParams = (String[]) params.get(sessionKeyString);
          }
          if ((sessionKey == null)
                  || (sessionKeyFromParams == null && sessionKeyFromCookie == null)
                  || (sessionKeyFromParams != null && !sessionKey.equals(sessionKeyFromParams[0]))
                  || (sessionKeyFromCookie != null && !sessionKey.equals(sessionKeyFromCookie))) {
              return false;
          }
          return true;
      }
focal_method.class_method_signature: HttpUtils.validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_method.full_signature: public static boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_method.identifier: validateSessionKey
focal_method.invocations: getAttribute findCookie get equals equals
focal_method.modifiers: public static
focal_method.parameters: (final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)
focal_method.return: boolean
focal_method.signature: boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString)