Пример #1
0
    public void AffinitizeRequest_CookieConfigSpecified_UseIt()
    {
        var policy = new CookieSessionAffinityPolicy(
            AffinityTestHelper.GetDataProtector().Object,
            new ManualClock(),
            AffinityTestHelper.GetLogger <CookieSessionAffinityPolicy>().Object);
        var context = new DefaultHttpContext();

        policy.AffinitizeResponse(context, new ClusterState("cluster"), _config, _destinations[1]);

        var affinityCookieHeader = context.Response.Headers["Set-Cookie"];

        Assert.Equal("My.Affinity=ZGVzdC1C; max-age=3600; domain=mydomain.my; path=/some; secure; samesite=lax", affinityCookieHeader);
    }
Пример #2
0
    public void FindAffinitizedDestination_AffinityKeyIsSetOnRequest_Success()
    {
        var policy = new CookieSessionAffinityPolicy(
            AffinityTestHelper.GetDataProtector().Object,
            new ManualClock(),
            AffinityTestHelper.GetLogger <CookieSessionAffinityPolicy>().Object);
        var context = new DefaultHttpContext();
        var affinitizedDestination = _destinations[1];

        context.Request.Headers["Cookie"] = GetCookieWithAffinity(affinitizedDestination);
        var cluster = new ClusterState("cluster");

        var affinityResult = policy.FindAffinitizedDestinations(context, cluster, _config, _destinations);

        Assert.Equal(AffinityStatus.OK, affinityResult.Status);
        Assert.Equal(1, affinityResult.Destinations.Count);
        Assert.Same(affinitizedDestination, affinityResult.Destinations[0]);
    }
Пример #3
0
    public void FindAffinitizedDestination_AffinityKeyIsNotSetOnRequest_ReturnKeyNotSet()
    {
        var policy = new CookieSessionAffinityPolicy(
            AffinityTestHelper.GetDataProtector().Object,
            new ManualClock(),
            AffinityTestHelper.GetLogger <CookieSessionAffinityPolicy>().Object);

        Assert.Equal(SessionAffinityConstants.Policies.Cookie, policy.Name);

        var context = new DefaultHttpContext();

        context.Request.Headers["Cookie"] = new[] { $"Some-Cookie=ZZZ" };
        var cluster = new ClusterState("cluster");

        var affinityResult = policy.FindAffinitizedDestinations(context, cluster, _config, _destinations);

        Assert.Equal(AffinityStatus.AffinityKeyNotSet, affinityResult.Status);
        Assert.Null(affinityResult.Destinations);
    }
Пример #4
0
    public void AffinitizedRequest_AffinityKeyIsExtracted_DoNothing()
    {
        var policy = new CookieSessionAffinityPolicy(
            AffinityTestHelper.GetDataProtector().Object,
            new ManualClock(),
            AffinityTestHelper.GetLogger <CookieSessionAffinityPolicy>().Object);
        var context = new DefaultHttpContext();
        var affinitizedDestination = _destinations[0];

        context.Request.Headers["Cookie"] = GetCookieWithAffinity(affinitizedDestination);
        var cluster = new ClusterState("cluster");

        var affinityResult = policy.FindAffinitizedDestinations(context, cluster, _config, _destinations);

        Assert.Equal(AffinityStatus.OK, affinityResult.Status);

        policy.AffinitizeResponse(context, cluster, _config, affinitizedDestination);

        Assert.False(context.Response.Headers.ContainsKey("Cookie"));
    }