Example #1
0
        public void ShouldGenerateCacheKeyForKeydId()
        {
            var keyId = Guid.NewGuid().ToString();

            var encryptionContext = new Dictionary <string, string>()
            {
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
            };

            var sut = new CacheKeyGenerator();
            var key = sut.Generate(new DataKeyIdentifier(keyId, encryptionContext));

            key.ShouldBe(string.Join("", keyId, encryptionContext.Keys.ElementAt(0), encryptionContext.Values.ElementAt(0), encryptionContext.Keys.ElementAt(1), encryptionContext.Values.ElementAt(1)));
        }
Example #2
0
        public void ShouldGenerateCacheKeyForCiphertextBlob()
        {
            var ciphertextBlob = new byte[] { 1, 2, 3, 4 };

            var encryptionContext = new Dictionary <string, string>()
            {
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
                { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() },
            };

            var sut = new CacheKeyGenerator();
            var key = sut.Generate(new DecryptIdentifier(ciphertextBlob, encryptionContext));

            key.ShouldBe(string.Join("", Convert.ToBase64String(ciphertextBlob), encryptionContext.Keys.ElementAt(0), encryptionContext.Values.ElementAt(0), encryptionContext.Keys.ElementAt(1), encryptionContext.Values.ElementAt(1)));
        }
        public void TestGenerateMethod(string url, string expected)
        {
            var          logger        = new FakeLogger();
            var          extractor     = new DomainNameExtractor(logger);
            var          serializer    = new FakeDomainSerializer();
            var          byConvention  = new ByConvention(logger, serializer);
            var          validator     = new TenantValidator(logger, serializer, byConvention);
            const string defaultTenant = "localhost";


            var locator = new TenantLocator(logger, extractor, byConvention, validator, serializer);
            var uri     = new Uri(url);
            var keyGen  = new CacheKeyGenerator(uri, locator, defaultTenant);

            string result = keyGen.Generate();

            Assert.Equal(expected, result);
        }