Yuli Shlosberg | a4eeb11 | 2019-01-07 16:23:36 +0200 | [diff] [blame] | 1 | package org.onap.sdc.security; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | import org.onap.sdc.security.filters.SampleFilter; |
| 5 | |
| 6 | import javax.servlet.http.Cookie; |
| 7 | |
| 8 | import java.io.IOException; |
| 9 | |
| 10 | import static org.junit.Assert.*; |
| 11 | |
| 12 | public class AuthenticationCookieUtilsTest { |
| 13 | |
| 14 | private SampleFilter sessionValidationFilter = new SampleFilter(); |
| 15 | private ISessionValidationFilterConfiguration filterCfg = sessionValidationFilter.getFilterConfiguration(); |
| 16 | |
| 17 | @Test |
| 18 | public void vaildateThatCookieCurrentSessionTimeIncreased() throws IOException, CipherUtilException { |
| 19 | // original cookie, pojo and servlet cookie |
| 20 | AuthenticationCookie authenticationCookieOriginal = new AuthenticationCookie("kuku"); |
| 21 | Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal,filterCfg )); |
| 22 | // cookie with increased time, pojo and servlet cookie |
| 23 | Cookie cookieWithIncreasedTime = AuthenticationCookieUtils.updateSessionTime(cookieWithOriginalTime, filterCfg); |
| 24 | AuthenticationCookie authenticationCookieIncreasedTime = AuthenticationCookieUtils.getAuthenticationCookie(cookieWithIncreasedTime, filterCfg); |
| 25 | // validation |
| 26 | long currentSessionTimeOriginal = authenticationCookieOriginal.getCurrentSessionTime(); |
| 27 | long currentSessionTimeIncreased = authenticationCookieIncreasedTime.getCurrentSessionTime(); |
| 28 | assertTrue(currentSessionTimeOriginal < currentSessionTimeIncreased); |
| 29 | } |
| 30 | |
| 31 | @Test |
| 32 | public void validateSerializationEncriptionDeserializationDecryption() throws IOException, CipherUtilException { |
| 33 | // original cookie, pojo and servlet cookie |
| 34 | AuthenticationCookie authenticationCookieOriginal = new AuthenticationCookie("kuku"); |
| 35 | Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal,filterCfg )); |
| 36 | // cookie with increased time, pojo and servlet cookie |
| 37 | AuthenticationCookie decriptedAndDeserializedAuthenticationCookie = AuthenticationCookieUtils.getAuthenticationCookie(cookieWithOriginalTime,filterCfg); |
| 38 | assertTrue(authenticationCookieOriginal.equals(decriptedAndDeserializedAuthenticationCookie)); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | // @Test |
| 44 | // public void getEncryptedCookie() { |
| 45 | // } |
| 46 | // |
| 47 | // @Test |
| 48 | // public void getAuthenticationCookie() { |
| 49 | // } |
| 50 | // |
| 51 | // @Test |
| 52 | // public void isSessionExpired() { |
| 53 | // } |
| 54 | } |