Exemplo n.º 1
0
        public void PrependsClearText(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();

            var token = sutProvider.Sut.Protect(tokenable);

            Assert.StartsWith(sutProvider.GetDependency <string>("clearTextPrefix"), token);
        }
Exemplo n.º 2
0
        public void EncryptsToken(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();
            var prefix      = sutProvider.GetDependency <string>("clearTextPrefix");

            var token = sutProvider.Sut.Protect(tokenable);

            Assert.NotEqual(new Token(token).RemovePrefix(prefix), tokenable.ToToken());
        }
Exemplo n.º 3
0
        public void TokenValid_FalseIfUnprotectFails(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();
            var token       = sutProvider.Sut.Protect(tokenable) + "fail decryption";

            var result = sutProvider.Sut.TokenValid(token);

            Assert.False(result);
        }
Exemplo n.º 4
0
        public void CanRoundTripTokenables(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();

            var token = sutProvider.Sut.Protect(tokenable);
            var recoveredTokenable = sutProvider.Sut.Unprotect(token);

            AssertHelper.AssertPropertyEqual(tokenable, recoveredTokenable);
        }
Exemplo n.º 5
0
        public void TryUnprotect_FalseIfUnprotectFails(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();
            var token       = sutProvider.Sut.Protect(tokenable) + "fail decryption";

            var result = sutProvider.Sut.TryUnprotect(token, out var data);

            Assert.False(result);
            Assert.Null(data);
        }
Exemplo n.º 6
0
        public void ThrowsIfUnprotectFails(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();

            var token = sutProvider.Sut.Protect(tokenable);

            token += "stuff to make sure decryption fails";

            Assert.Throws <CryptographicException>(() => sutProvider.Sut.Unprotect(token));
        }
Exemplo n.º 7
0
        public void TokenValid_TrueIfSuccess(TestTokenable tokenable)
        {
            tokenable.ForceInvalid = false;
            var sutProvider = GetSutProvider();
            var token       = sutProvider.Sut.Protect(tokenable);

            var result = sutProvider.Sut.TokenValid(token);

            Assert.True(result);
        }
Exemplo n.º 8
0
        public void TryUnprotect_TrueIfSuccess(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();
            var token       = sutProvider.Sut.Protect(tokenable);

            var result = sutProvider.Sut.TryUnprotect(token, out var data);

            Assert.True(result);
            AssertHelper.AssertPropertyEqual(tokenable, data);
        }
Exemplo n.º 9
0
        public void TokenValid_FalseIfTokenInvalid(TestTokenable tokenable)
        {
            var sutProvider = GetSutProvider();

            tokenable.ForceInvalid = true;
            var token = sutProvider.Sut.Protect(tokenable);

            var result = sutProvider.Sut.TokenValid(token);

            Assert.False(result);
        }