Tomasz Golabek | c8fcbbc | 2019-07-09 08:42:59 +0200 | [diff] [blame^] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 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 |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 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========================================================= |
| 19 | */ |
| 20 | |
Yuli Shlosberg | a4eeb11 | 2019-01-07 16:23:36 +0200 | [diff] [blame] | 21 | package org.onap.sdc.security; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | import org.onap.sdc.security.filters.SampleFilter; |
| 25 | |
| 26 | import javax.servlet.http.Cookie; |
| 27 | |
| 28 | import java.io.IOException; |
| 29 | |
| 30 | import static org.junit.Assert.*; |
| 31 | |
| 32 | public class AuthenticationCookieUtilsTest { |
| 33 | |
| 34 | private SampleFilter sessionValidationFilter = new SampleFilter(); |
| 35 | private ISessionValidationFilterConfiguration filterCfg = sessionValidationFilter.getFilterConfiguration(); |
| 36 | |
| 37 | @Test |
| 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); |
| 45 | // validation |
| 46 | long currentSessionTimeOriginal = authenticationCookieOriginal.getCurrentSessionTime(); |
| 47 | long currentSessionTimeIncreased = authenticationCookieIncreasedTime.getCurrentSessionTime(); |
| 48 | assertTrue(currentSessionTimeOriginal < currentSessionTimeIncreased); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 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)); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | // @Test |
| 64 | // public void getEncryptedCookie() { |
| 65 | // } |
| 66 | // |
| 67 | // @Test |
| 68 | // public void getAuthenticationCookie() { |
| 69 | // } |
| 70 | // |
| 71 | // @Test |
| 72 | // public void isSessionExpired() { |
| 73 | // } |
Tomasz Golabek | c8fcbbc | 2019-07-09 08:42:59 +0200 | [diff] [blame^] | 74 | } |