Пример #1
0
        public void CanRoundtripToken_TamperedTokenIsInvalid()
        {
            using (var keyMan = new KeyMan(TestConfig.ValidKey))
            {
                var token = keyMan.Encode(new Dictionary <string, string>
                {
                    { "username", "joe" }
                });

                var tamperedToken = TamperSomehow(token);

                Console.WriteLine($@"Token:

{token}

TAMPERED token:

{tamperedToken}
");

                var decodingResult = keyMan.Decode(tamperedToken);

                Assert.That(decodingResult.IsValid, Is.False);
            }
        }
Пример #2
0
        public void CanDetermineWhetherTokenIsExpired()
        {
            var expirationTimeInThePast = DateTimeOffset.Now.AddMinutes(-2).ToString("O");

            var properties = new Dictionary <string, string>
            {
                { KeyMan.Properties.ExpirationTime, expirationTimeInThePast }
            };

            var token = _keyMan.Encode(properties);

            var result = _keyMan.Decode(token);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.Details.HasValidSignature, Is.True);
            Assert.That(result.Details.IsExpired, Is.True);
        }
Пример #3
0
        public void AutomaticallyAssignsIssuedAt()
        {
            var token = _keyMan.Encode(new Dictionary <string, string>());

            var result = _keyMan.Decode(token);

            Assert.That(result.Properties.ContainsKey(KeyMan.Properties.IssuedAt));

            var issuedAt = DateTimeOffset.Parse(result.Properties[KeyMan.Properties.IssuedAt]);

            Assert.That(issuedAt, Is.GreaterThan(DateTimeOffset.Now.AddSeconds(-2)));
            Assert.That(issuedAt, Is.LessThan(DateTimeOffset.Now.AddSeconds(2)));
        }
Пример #4
0
        public void CanRoundtripToken()
        {
            using (var keyMan = new KeyMan(TestConfig.ValidKey))
            {
                var token = keyMan.Encode(new Dictionary <string, string>
                {
                    { "username", "joe" }
                });

                var decodingResult = keyMan.Decode(token);

                Assert.That(decodingResult.IsValid, Is.True);

                var decodedProperties = decodingResult.Properties;

                Assert.That(decodedProperties.ContainsKey("username"));
                Assert.That(decodedProperties["username"], Is.EqualTo("joe"));
            }
        }