コード例 #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
ファイル: TokenCompression.cs プロジェクト: rebus-org/Tiket
        void CheckSize(int numberOfProperties)
        {
            var properties = Enumerable.Range(0, numberOfProperties)
                             .Select(i => $"key-{i}")
                             .ToDictionary(a => a, a => "just a value");

            var token = _keyMan.Encode(properties);

            Console.WriteLine($"{numberOfProperties.ToString().PadLeft(5)}: {token.Length} - {token}");
        }
コード例 #4
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)));
        }
コード例 #5
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"));
            }
        }