Exemple #1
0
        public void AffinitizeRequest_AffinityOptionSettingNotFound_Throw()
        {
            var provider = new ProviderStub(GetDataProtector().Object, AffinityTestHelper.GetLogger <BaseSessionAffinityProvider <string> >().Object);
            var options  = GetOptionsWithUnknownSetting();

            Assert.Throws <ArgumentException>(() => provider.AffinitizeRequest(new DefaultHttpContext(), options, new DestinationInfo("dest-A")));
        }
Exemple #2
0
        public void AffinitizeRequest_AffinitiDisabled_DoNothing()
        {
            var dataProtector = GetDataProtector();
            var provider      = new ProviderStub(dataProtector.Object, AffinityTestHelper.GetLogger <BaseSessionAffinityProvider <string> >().Object);

            Assert.Throws <InvalidOperationException>(() => provider.AffinitizeRequest(new DefaultHttpContext(), new SessionAffinityOptions(), new DestinationInfo("id")));
        }
Exemple #3
0
        public void AffinitizeRequest_RequestIsAffinitized_DoNothing()
        {
            var dataProtector = GetDataProtector();
            var provider      = new ProviderStub(dataProtector.Object, AffinityTestHelper.GetLogger <BaseSessionAffinityProvider <string> >().Object);
            var context       = new DefaultHttpContext();

            provider.DirectlySetExtractedKeyOnContext(context, "ExtractedKey");
            provider.AffinitizeRequest(context, _defaultOptions, new DestinationInfo("id"));
            Assert.Null(provider.LastSetEncryptedKey);
            dataProtector.Verify(p => p.Protect(It.IsAny <byte[]>()), Times.Never);
        }
Exemple #4
0
        public void AffinitizeRequest_RequestIsNotAffinitized_SetAffinityKey()
        {
            var dataProtector = GetDataProtector();
            var provider      = new ProviderStub(dataProtector.Object, AffinityTestHelper.GetLogger <BaseSessionAffinityProvider <string> >().Object);
            var destination   = new DestinationInfo("dest-A");

            provider.AffinitizeRequest(new DefaultHttpContext(), _defaultOptions, destination);
            Assert.Equal("ZGVzdC1B", provider.LastSetEncryptedKey);
            var keyBytes = Encoding.UTF8.GetBytes(destination.DestinationId);

            dataProtector.Verify(p => p.Protect(It.Is <byte[]>(b => b.SequenceEqual(keyBytes))), Times.Once);
        }