blob: c03bf9c65d2877fde81425baa750b9a4cad8f039 [file] [log] [blame]
Yuli Shlosberga4eeb112019-01-07 16:23:36 +02001package org.onap.sdc.security;
2
3import org.junit.Test;
4import org.onap.sdc.security.filters.SampleFilter;
5
6import javax.servlet.http.Cookie;
7
8import java.io.IOException;
9
10import static org.junit.Assert.*;
11
12public 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}