类io.vertx.core.http.Cookie源码实例Demo

下面列出了怎么用io.vertx.core.http.Cookie的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: servicecomb-samples   文件: ApiDispatcher.java
protected void onRequest(RoutingContext context) {
  Map<String, String> pathParams = context.pathParams();
  String microserviceName = pathParams.get("param0");
  String path = "/" + pathParams.get("param1");

  EdgeInvocation invoker = new EdgeInvocation() {
    // Authentication. Notice: adding context must after setContext or will override by network
    protected void setContext() throws Exception {
      super.setContext();
      // get session id from header and cookie for debug reasons
      String sessionId = context.request().getHeader("session-id");
      if (sessionId != null) {
        this.invocation.addContext("session-id", sessionId);
      } else {
        Cookie sessionCookie = context.cookieMap().get("session-id");
        if (sessionCookie != null) {
          this.invocation.addContext("session-id", sessionCookie.getValue());
        }
      }
    }
  };
  invoker.init(microserviceName, context, path, httpServerFilters);
  invoker.edgeInvoke();
}
 
源代码2 项目: servicecomb-samples   文件: ApiDispatcher.java
protected void onRequest(RoutingContext context) {
  Map<String, String> pathParams = context.pathParams();
  String microserviceName = pathParams.get("param0");
  String path = "/" + pathParams.get("param1");

  EdgeInvocation invoker = new EdgeInvocation() {
    // Authentication. Notice: adding context must after setContext or will override by network
    protected void setContext() throws Exception {
      super.setContext();
      // get session id from header and cookie for debug reasons
      String sessionId = context.request().getHeader("session-id");
      if (sessionId != null) {
        this.invocation.addContext("session-id", sessionId);
      } else {
        Cookie sessionCookie = context.cookieMap().get("session-id");
        if (sessionCookie != null) {
          this.invocation.addContext("session-id", sessionCookie.getValue());
        }
      }
    }
  };
  invoker.init(microserviceName, context, path, httpServerFilters);
  invoker.edgeInvoke();
}
 
源代码3 项目: vertx-vaadin   文件: VertxVaadinRequestUT.java
@Test
public void shouldDelegateGetCookies() {
    Cookie cookie1 = Cookie.cookie("cookie1", "value1")
        .setDomain("domain").setHttpOnly(true)
        .setMaxAge(90L).setPath("path").setSecure(true);
    Cookie cookie2 = Cookie.cookie("cookie2", "value2");
    when(routingContext.cookieCount()).thenReturn(0).thenReturn(2);
    when(routingContext.cookieMap()).thenReturn(Stream.of(cookie1, cookie2).collect(Collectors.toMap(Cookie::getName, identity())));
    assertThat(vaadinRequest.getCookies()).isNull();
    javax.servlet.http.Cookie[] cookies = vaadinRequest.getCookies();
    assertThat(cookies).hasSize(2);
    assertThat(cookies[0]).extracting("name", "value", "domain", "httpOnly", "maxAge", "path", "secure")
        .containsExactly(cookie1.getName(), cookie1.getValue(), cookie1.getDomain(), true, 90, "path", true);
    assertThat(cookies[1]).extracting("name", "value", "domain", "httpOnly", "maxAge", "path", "secure")
        .containsExactly(cookie2.getName(), cookie2.getValue(), null, false, -1, null, false);
}
 
源代码4 项目: prebid-server-java   文件: UidsCookieService.java
/**
 * Creates a {@link Cookie} with 'uids' as a name and encoded JSON string representing supplied {@link UidsCookie}
 * as a value.
 */
public Cookie toCookie(UidsCookie uidsCookie) {
    UidsCookie modifiedUids = uidsCookie;
    byte[] cookieBytes = uidsCookie.toJson().getBytes();

    while (maxCookieSizeBytes > 0 && cookieBytes.length > maxCookieSizeBytes) {
        final String familyName = modifiedUids.getCookieUids().getUids().entrySet().stream()
                .reduce(UidsCookieService::getClosestExpiration)
                .map(Map.Entry::getKey)
                .orElse(null);
        modifiedUids = modifiedUids.deleteUid(familyName);
        cookieBytes = modifiedUids.toJson().getBytes();
    }

    final Cookie cookie = Cookie
            .cookie(COOKIE_NAME, Base64.getUrlEncoder().encodeToString(cookieBytes))
            .setPath("/")
            .setMaxAge(ttlSeconds);

    if (StringUtils.isNotBlank(hostCookieDomain)) {
        cookie.setDomain(hostCookieDomain);
    }

    return cookie;
}
 
@Test
public void shouldReturnNonEmptyUidsCookie() {
    // given
    // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}}
    given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie(
            "uids",
            "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ==")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie).isNotNull();
    assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("J5VLCWQP-26-CWFT");
    assertThat(uidsCookie.uidFrom(ADNXS)).isEqualTo("12345");
}
 
@Test
public void shouldReturnUidsCookieWithOptoutTrueIfUidsCookieIsPresentAndOptoutCookieHasExpectedValue() {
    // given
    final Map<String, Cookie> cookies = new HashMap<>();
    // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}}
    cookies.put("uids", Cookie.cookie("uids",
            "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ=="));
    cookies.put(OPT_OUT_COOKIE_NAME, Cookie.cookie(OPT_OUT_COOKIE_NAME, OPT_OUT_COOKIE_VALUE));

    given(routingContext.cookieMap()).willReturn(cookies);

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.allowsSync()).isFalse();
    assertThat(uidsCookie.uidFrom(RUBICON)).isNull();
    assertThat(uidsCookie.uidFrom(ADNXS)).isNull();
}
 
@Test
public void shouldReturnUidsCookieWithOptoutFalseIfOptoutCookieHasNotExpectedValue() {
    // given
    final Map<String, Cookie> cookies = new HashMap<>();
    // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}}
    cookies.put("uids", Cookie.cookie("uids",
            "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ=="));
    cookies.put(OPT_OUT_COOKIE_NAME, Cookie.cookie(OPT_OUT_COOKIE_NAME, "dummy"));

    given(routingContext.cookieMap()).willReturn(cookies);

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.allowsSync()).isTrue();
    assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("J5VLCWQP-26-CWFT");
    assertThat(uidsCookie.uidFrom(ADNXS)).isEqualTo("12345");
}
 
@Test
public void shouldReturnRubiconCookieValueFromHostCookieWhenUidValueIsPresentButDiffers() {
    // given
    uidsCookieService = new UidsCookieService(
            "trp_optout", "true", "rubicon", "khaos", "cookie-domain", 90, MAX_COOKIE_SIZE_BYTES, jacksonMapper);

    final Map<String, Cookie> cookies = new HashMap<>();
    // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}}
    cookies.put("uids", Cookie.cookie("uids",
            "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ=="));
    cookies.put("khaos", Cookie.cookie("khaos", "abc123"));

    given(routingContext.cookieMap()).willReturn(cookies);

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("abc123");
}
 
@Test
public void shouldSkipFacebookSentinelFromUidsCookie() throws JsonProcessingException {
    // given
    final Map<String, UidWithExpiry> uidsWithExpiry = new HashMap<>();
    uidsWithExpiry.put(RUBICON, UidWithExpiry.live("J5VLCWQP-26-CWFT"));
    uidsWithExpiry.put("audienceNetwork", UidWithExpiry.live("0"));
    final Uids uids = Uids.builder().uids(uidsWithExpiry).build();
    final String encodedUids = encodeUids(uids);

    given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie("uids", encodedUids)));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie).isNotNull();
    assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("J5VLCWQP-26-CWFT");
    assertThat(uidsCookie.uidFrom("audienceNetwork")).isNull();
}
 
源代码10 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldCreateUidsFromLegacyUidsIfUidsAreMissed() {
    // given
    // this uids cookie value stands for
    // {"uids":{"rubicon":"J5VLCWQP-26-CWFT"},"tempUIDs":{}},"bday":"2017-08-15T19:47:59.523908376Z"}
    given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie(
            "uids",
            "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIn0sInRlbXBVSURzIjp7fX0sImJkYXkiOiIyMDE3LTA"
                    + "4LTE1VDE5OjQ3OjU5LjUyMzkwODM3NloifQ==")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie).isNotNull();
    assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("J5VLCWQP-26-CWFT");
}
 
源代码11 项目: prebid-server-java   文件: OptoutHandlerTest.java
@Before
public void setUp() {
    given(routingContext.request()).willReturn(httpRequest);
    given(routingContext.response()).willReturn(httpResponse);

    given(httpRequest.getFormAttribute("g-recaptcha-response")).willReturn("recaptcha1");

    given(httpResponse.putHeader(any(CharSequence.class), anyString())).willReturn(httpResponse);
    given(httpResponse.setStatusCode(anyInt())).willReturn(httpResponse);

    given(googleRecaptchaVerifier.verify(anyString())).willReturn(Future.succeededFuture());

    given(uidsCookieService.toCookie(any())).willReturn(Cookie.cookie("cookie", "value"));
    given(uidsCookieService.parseFromRequest(any()))
            .willReturn(new UidsCookie(Uids.builder().uids(emptyMap()).build(), jacksonMapper));

    optoutHandler = new OptoutHandler(googleRecaptchaVerifier, uidsCookieService,
            OptoutHandler.getOptoutRedirectUrl("http://external/url"), "http://optout/url", "http://optin/url");
}
 
源代码12 项目: prebid-server-java   文件: SetuidHandlerTest.java
@Before
public void setUp() {
    final Map<Integer, PrivacyEnforcementAction> vendorIdToGdpr = singletonMap(null,
            PrivacyEnforcementAction.allowAll());
    given(tcfDefinerService.resultForVendorIds(anySet(), any(), any(), any(), any(), any()))
            .willReturn(Future.succeededFuture(TcfResponse.of(true, vendorIdToGdpr, null)));

    given(routingContext.request()).willReturn(httpRequest);
    given(routingContext.response()).willReturn(httpResponse);

    given(httpResponse.headers()).willReturn(new CaseInsensitiveHeaders());

    given(uidsCookieService.toCookie(any())).willReturn(Cookie.cookie("test", "test"));
    given(bidderCatalog.names()).willReturn(new HashSet<>(asList("rubicon", "audienceNetwork")));
    given(bidderCatalog.isActive(any())).willReturn(true);
    given(bidderCatalog.usersyncerByName(any())).willReturn(
            new Usersyncer(RUBICON, null, null, null, false));

    final Clock clock = Clock.fixed(Instant.now(), ZoneId.systemDefault());
    final TimeoutFactory timeoutFactory = new TimeoutFactory(clock);
    setuidHandler = new SetuidHandler(2000, uidsCookieService, applicationSettings,
            bidderCatalog, tcfDefinerService, null, false, analyticsReporter, metrics, timeoutFactory);
}
 
源代码13 项目: prebid-server-java   文件: SetuidHandlerTest.java
@Test
public void shouldRespondWithoutCookieIfGdprProcessingPreventsCookieSetting() {
    // given
    final PrivacyEnforcementAction privacyEnforcementAction = PrivacyEnforcementAction.restrictAll();
    given(tcfDefinerService.resultForVendorIds(anySet(), any(), any(), any(), any(), any()))
            .willReturn(Future.succeededFuture(
                    TcfResponse.of(true, singletonMap(null, privacyEnforcementAction), null)));

    given(uidsCookieService.parseFromRequest(any()))
            .willReturn(new UidsCookie(Uids.builder().uids(emptyMap()).build(), jacksonMapper));

    given(httpRequest.getParam("bidder")).willReturn(RUBICON);

    given(httpResponse.setStatusCode(anyInt())).willReturn(httpResponse);

    // when
    setuidHandler.handle(routingContext);

    // then
    verify(routingContext, never()).addCookie(any(Cookie.class));
    verify(httpResponse).setStatusCode(eq(200));
    verify(httpResponse).end(eq("The gdpr_consent param prevents cookies from being saved"));
}
 
源代码14 项目: prebid-server-java   文件: SetuidHandlerTest.java
@Test
public void shouldRespondWithBadRequestStatusIfGdprProcessingFailsWithInvalidRequestException() {
    // given
    given(tcfDefinerService.resultForVendorIds(anySet(), any(), any(), any(), any(), any()))
            .willReturn(Future.failedFuture(new InvalidRequestException("gdpr exception")));

    given(uidsCookieService.parseFromRequest(any()))
            .willReturn(new UidsCookie(Uids.builder().uids(emptyMap()).build(), jacksonMapper));

    given(httpRequest.getParam("bidder")).willReturn(RUBICON);

    given(httpResponse.setStatusCode(anyInt())).willReturn(httpResponse);

    // when
    setuidHandler.handle(routingContext);

    // then
    verify(routingContext, never()).addCookie(any(Cookie.class));
    verify(httpResponse).setStatusCode(eq(400));
    verify(httpResponse).end(eq("GDPR processing failed with error: gdpr exception"));
}
 
源代码15 项目: prebid-server-java   文件: SetuidHandlerTest.java
@Test
public void shouldRespondWithInternalServerErrorStatusIfGdprProcessingFailsWithUnexpectedException() {
    // given
    given(tcfDefinerService.resultForVendorIds(anySet(), any(), any(), any(), any(), any()))
            .willReturn(Future.failedFuture("unexpected error"));

    given(uidsCookieService.parseFromRequest(any()))
            .willReturn(new UidsCookie(Uids.builder().uids(emptyMap()).build(), jacksonMapper));

    given(httpRequest.getParam("bidder")).willReturn(RUBICON);

    given(httpResponse.setStatusCode(anyInt())).willReturn(httpResponse);

    // when
    setuidHandler.handle(routingContext);

    // then
    verify(httpResponse, never()).sendFile(any());
    verify(routingContext, never()).addCookie(any(Cookie.class));
    verify(httpResponse).setStatusCode(eq(500));
    verify(httpResponse).end(eq("Unexpected GDPR processing error"));
}
 
源代码16 项目: rest.vertx   文件: ClassFactoryTest.java
@Test
void constructViaContext() throws ClassFactoryException {

    RoutingContext context = Mockito.mock(RoutingContext.class);
    HttpServerRequest request = Mockito.mock(HttpServerRequest.class);

    Mockito.when(context.request()).thenReturn(request);
    Mockito.when(request.getParam("path")).thenReturn("SomePath");
    Mockito.when(request.getHeader("MyHeader")).thenReturn("true");
    Mockito.when(request.query()).thenReturn("query=1");
    Mockito.when(request.getCookie("chocolate")).thenReturn(Cookie.cookie("chocolate", "tasty"));

    MyComplexBean instance = (MyComplexBean)ClassFactory.newInstanceOf(MyComplexBean.class, context);
    assertNotNull(instance);
    assertEquals("Header: true, Path: SomePath, Query: 1, Cookie: tasty, Matrix: null", instance.toString());
}
 
源代码17 项目: rest.vertx   文件: ClassFactoryTest.java
@Test
void constructViaContextFail() throws ClassFactoryException {

    RoutingContext context = Mockito.mock(RoutingContext.class);
    HttpServerRequest request = Mockito.mock(HttpServerRequest.class);

    Mockito.when(context.request()).thenReturn(request);
    Mockito.when(request.getParam("path")).thenReturn("SomePath");
    Mockito.when(request.getHeader("MyHeader")).thenReturn("BLA"); // invalid type
    Mockito.when(request.query()).thenReturn("query=A"); // invalid type
    Mockito.when(request.getCookie("chocolate")).thenReturn(Cookie.cookie("chocolate", "tasty"));

    ClassFactoryException ex = assertThrows(ClassFactoryException.class, () -> ClassFactory.newInstanceOf(MyComplexBean.class, context));
    assertEquals("Failed to instantiate class, with constructor: " +
                    "com.zandero.rest.test.data.MyComplexBean(String arg0=SomePath, boolean arg1=BLA, int arg2=A, String arg3=tasty). " +
                    "Failed to convert value: 'A', to primitive type: int",
            ex.getMessage());
}
 
源代码18 项目: vertx-web   文件: CSRFHandlerImpl.java
private String generateAndStoreToken(RoutingContext ctx) {
  byte[] salt = new byte[32];
  random.nextBytes(salt);

  String saltPlusToken = BASE64.encodeToString(salt) + "." + System.currentTimeMillis();
  String signature = BASE64.encodeToString(mac.doFinal(saltPlusToken.getBytes()));

  final String token = saltPlusToken + "." + signature;
  // a new token was generated add it to the cookie
  ctx.addCookie(
    Cookie.cookie(cookieName, token)
      .setPath(cookiePath)
      .setHttpOnly(httpOnly)
      // it's not an option to change the same site policy
      .setSameSite(CookieSameSite.STRICT));

  return token;
}
 
源代码19 项目: vertx-spring-boot   文件: CookieConverter.java
public static Cookie toCookie(ResponseCookie responseCookie) {
    Cookie cookie = Cookie.cookie(responseCookie.getName(), responseCookie.getValue())
        .setDomain(responseCookie.getDomain())
        .setPath(responseCookie.getPath())
        .setHttpOnly(responseCookie.isHttpOnly())
        .setSecure(responseCookie.isSecure());

    if (!responseCookie.getMaxAge().isNegative()) {
        cookie.setMaxAge(responseCookie.getMaxAge().getSeconds());
    }

    return cookie;
}
 
@Test
public void shouldInitCookies() {
    Map<String, Cookie> originalCookies = new HashMap<>(2);
    originalCookies.put("cookie1", Cookie.cookie("cookie1", "value1"));
    originalCookies.put("cookie2", Cookie.cookie("cookie2", "value2"));

    given(mockRoutingContext.cookieMap()).willReturn(originalCookies);

    assertThat(vertxServerHttpRequest.initCookies()).containsOnly(
        new AbstractMap.SimpleEntry<>("cookie1", Collections.singletonList(new HttpCookie("cookie1", "value1"))),
        new AbstractMap.SimpleEntry<>("cookie2", Collections.singletonList(new HttpCookie("cookie2", "value2")))
    );
}
 
源代码21 项目: prebid-server-java   文件: OptoutHandler.java
private void sendResponse(RoutingContext context, Cookie cookie, String url) {
    context.response()
            .putHeader(HttpUtil.LOCATION_HEADER, url)
            .putHeader(HttpUtil.SET_COOKIE_HEADER, HttpUtil.toSetCookieHeaderValue(cookie))
            .setStatusCode(HttpResponseStatus.MOVED_PERMANENTLY.code())
            .end();
}
 
源代码22 项目: prebid-server-java   文件: SetuidHandler.java
private void respondWithCookie(RoutingContext context, String bidder, UidsCookie uidsCookie) {
    final String uid = context.request().getParam(UID_PARAM);
    final UidsCookie updatedUidsCookie;
    boolean successfullyUpdated = false;

    if (StringUtils.isBlank(uid)) {
        updatedUidsCookie = uidsCookie.deleteUid(bidder);
    } else if (UidsCookie.isFacebookSentinel(bidder, uid)) {
        // At the moment, Facebook calls /setuid with a UID of 0 if the user isn't logged into Facebook.
        // They shouldn't be sending us a sentinel value... but since they are, we're refusing to save that ID.
        updatedUidsCookie = uidsCookie;
    } else {
        updatedUidsCookie = uidsCookie.updateUid(bidder, uid);
        successfullyUpdated = true;
        metrics.updateUserSyncSetsMetric(bidder);
    }

    final Cookie cookie = uidsCookieService.toCookie(updatedUidsCookie);
    addCookie(context, cookie);

    final int status = HttpResponseStatus.OK.code();

    // Send pixel file to response if "format=img"
    final String format = context.request().getParam(FORMAT_PARAM);
    if (StringUtils.equals(format, IMG_FORMAT_PARAM)) {
        context.response().sendFile(PIXEL_FILE_PATH);
    } else {
        respondWith(context, status, null);
    }

    analyticsReporter.processEvent(SetuidEvent.builder()
            .status(status)
            .bidder(bidder)
            .uid(uid)
            .success(successfullyUpdated)
            .build());
}
 
源代码23 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldReturnNonNullUidsCookieIfUidsCookieIsNonBase64() {
    // given
    given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie("uids", "abcde")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie).isNotNull();
}
 
源代码24 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldReturnNonNullUidsCookieIfUidsCookieIsNonJson() {
    // given
    // this uids cookie value stands for "abcde"
    given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie("uids", "bm9uLWpzb24=")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie).isNotNull();
}
 
源代码25 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldReturnUidsCookieWithOptoutTrueIfUidsCookieIsMissingAndOptoutCookieHasExpectedValue() {
    // given
    given(routingContext.cookieMap()).willReturn(
            singletonMap(OPT_OUT_COOKIE_NAME, Cookie.cookie(OPT_OUT_COOKIE_NAME, OPT_OUT_COOKIE_VALUE)));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.allowsSync()).isFalse();
}
 
源代码26 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldReturnUidsCookieWithOptoutFalseIfOptoutCookieNameNotSpecified() {
    // given
    uidsCookieService = new UidsCookieService(
            null, "true", null, null, "cookie-domain", 90, MAX_COOKIE_SIZE_BYTES, jacksonMapper);
    given(routingContext.cookieMap()).willReturn(
            singletonMap(OPT_OUT_COOKIE_NAME, Cookie.cookie("trp_optout", "true")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.allowsSync()).isTrue();
}
 
源代码27 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldReturnUidsCookieWithOptoutFalseIfOptoutCookieValueNotSpecified() {
    // given
    uidsCookieService = new UidsCookieService(
            "trp_optout", null, null, null, "cookie-domain", 90, MAX_COOKIE_SIZE_BYTES, jacksonMapper);
    given(routingContext.cookieMap()).willReturn(
            singletonMap(OPT_OUT_COOKIE_NAME, Cookie.cookie("trp_optout", "true")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.allowsSync()).isTrue();
}
 
源代码28 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void shouldReturnRubiconCookieValueFromHostCookieWhenUidValueIsAbsent() {
    // given
    uidsCookieService = new UidsCookieService(
            "trp_optout", "true", "rubicon", "khaos", "cookie-domain", 90, MAX_COOKIE_SIZE_BYTES, jacksonMapper);
    given(routingContext.cookieMap()).willReturn(singletonMap("khaos", Cookie.cookie("khaos", "abc123")));

    // when
    final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext);

    // then
    assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("abc123");
}
 
源代码29 项目: vertx-web   文件: CookieHandlerTest.java
@Test
public void testCookieFields() throws Exception {
  Cookie cookie = Cookie.cookie("foo", "bar");
  assertEquals("foo", cookie.getName());
  assertEquals("bar", cookie.getValue());
  assertEquals("foo=bar", cookie.encode());
  assertNull(cookie.getPath());
  cookie.setPath("/somepath");
  assertEquals("/somepath", cookie.getPath());
  assertEquals("foo=bar; Path=/somepath", cookie.encode());
  assertNull(cookie.getDomain());
  cookie.setDomain("foo.com");
  assertEquals("foo.com", cookie.getDomain());
  assertEquals("foo=bar; Path=/somepath; Domain=foo.com", cookie.encode());
  long maxAge = 30 * 60;
  cookie.setMaxAge(maxAge);


  long now = System.currentTimeMillis();
  String encoded = cookie.encode();
  int startPos = encoded.indexOf("Expires=");
  int endPos = encoded.indexOf(';', startPos);
  String expiresDate = encoded.substring(startPos + 8, endPos);
  Date d = new Date(Utils.parseRFC1123DateTime(expiresDate));
  assertTrue(d.getTime() - now >= maxAge);

  cookie.setMaxAge(Long.MIN_VALUE);
  cookie.setSecure(true);
  assertEquals("foo=bar; Path=/somepath; Domain=foo.com; Secure", cookie.encode());
  cookie.setHttpOnly(true);
  assertEquals("foo=bar; Path=/somepath; Domain=foo.com; Secure; HTTPOnly", cookie.encode());
}
 
源代码30 项目: prebid-server-java   文件: UidsCookieServiceTest.java
@Test
public void toCookieShouldReturnCookieWithExpectedDomain() {
    // when
    final UidsCookie uidsCookie = new UidsCookie(
            Uids.builder().uids(new HashMap<>()).build(), jacksonMapper);
    final Cookie cookie = uidsCookieService.toCookie(uidsCookie);

    // then
    assertThat(cookie.getDomain()).isEqualTo(HOST_COOKIE_DOMAIN);
}
 
 类所在包
 类方法
 同包方法