2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.security;
23 import org.junit.Test;
24 import org.onap.sdc.security.filters.SampleFilter;
26 import javax.servlet.http.Cookie;
28 import java.io.IOException;
30 import static org.junit.Assert.*;
32 public class AuthenticationCookieUtilsTest {
34 private SampleFilter sessionValidationFilter = new SampleFilter();
35 private ISessionValidationFilterConfiguration filterCfg = sessionValidationFilter.getFilterConfiguration();
38 public void vaildateThatCookieCurrentSessionTimeIncreased() throws IOException, CipherUtilException {
39 // original cookie, pojo and servlet cookie
40 AuthenticationCookie authenticationCookieOriginal = new AuthenticationCookie("kuku");
41 Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal,filterCfg ));
42 // cookie with increased time, pojo and servlet cookie
43 Cookie cookieWithIncreasedTime = AuthenticationCookieUtils.updateSessionTime(cookieWithOriginalTime, filterCfg);
44 AuthenticationCookie authenticationCookieIncreasedTime = AuthenticationCookieUtils.getAuthenticationCookie(cookieWithIncreasedTime, filterCfg);
46 long currentSessionTimeOriginal = authenticationCookieOriginal.getCurrentSessionTime();
47 long currentSessionTimeIncreased = authenticationCookieIncreasedTime.getCurrentSessionTime();
48 assertTrue(currentSessionTimeOriginal < currentSessionTimeIncreased);
52 public void validateSerializationEncriptionDeserializationDecryption() throws IOException, CipherUtilException {
53 // original cookie, pojo and servlet cookie
54 AuthenticationCookie authenticationCookieOriginal = new AuthenticationCookie("kuku");
55 Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal,filterCfg ));
56 // cookie with increased time, pojo and servlet cookie
57 AuthenticationCookie decriptedAndDeserializedAuthenticationCookie = AuthenticationCookieUtils.getAuthenticationCookie(cookieWithOriginalTime,filterCfg);
58 assertTrue(authenticationCookieOriginal.equals(decriptedAndDeserializedAuthenticationCookie));
64 // public void getEncryptedCookie() {
68 // public void getAuthenticationCookie() {
72 // public void isSessionExpired() {