Exemplo n.º 1
0
        public void Factory_WithPayload()
        {
            IEnqueueTokenPayload expectedPayload = Payload.Enqueue().WithKey("somekey").Generate();

            IEnqueueToken token = Token
                                  .Enqueue("ticketania")
                                  .WithPayload(expectedPayload)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            Assert.Equal(expectedPayload, token.Payload);
        }
Exemplo n.º 2
0
        public void Factory_WithEventId()
        {
            string expectedEventId = "myevent";

            IEnqueueToken token = Token
                                  .Enqueue("ticketania")
                                  .WithEventId(expectedEventId)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            Assert.Equal(expectedEventId, token.EventId);
        }
Exemplo n.º 3
0
        public void Factory_WithValidity_date()
        {
            DateTime expectedValidity = new DateTime(2030, 01, 01, 12, 00, 00);

            IEnqueueToken token = Token
                                  .Enqueue("ticketania")
                                  .WithValidity(expectedValidity)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            Assert.Equal(expectedValidity, token.Expires);
        }
Exemplo n.º 4
0
        public void Factory_WithValidity_long()
        {
            long expectedValidity = 3000;

            IEnqueueToken token = Token
                                  .Enqueue("ticketania")
                                  .WithValidity(expectedValidity)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            Assert.Equal(token.Issued.AddMilliseconds(expectedValidity), token.Expires);
        }
Exemplo n.º 5
0
        public void Factory_TokenIdentifierPrefix()
        {
            string        tokenIdentifierPrefix = "SomePrefix";
            IEnqueueToken token = Token
                                  .Enqueue("ticketania", tokenIdentifierPrefix)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            var tokenIdentifierParts = token.TokenIdentifier.Split("~");

            Assert.Equal(tokenIdentifierPrefix, tokenIdentifierParts[0]);
        }
Exemplo n.º 6
0
        public void Factory_WithIPAddress()
        {
            string        expectedIpAddress     = "1.5.8.9";
            string        expectedXForwardedFor = "45.67.2.4,34.56.3.2";
            IEnqueueToken token = Token
                                  .Enqueue("ticketania")
                                  .WithIpAddress(expectedIpAddress, expectedXForwardedFor)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            Assert.Equal(expectedIpAddress, token.IpAddress);
            Assert.Equal(expectedXForwardedFor, token.XForwardedFor);
        }
Exemplo n.º 7
0
        public void Factory_simple()
        {
            DateTime      startTime          = DateTime.UtcNow;
            string        expectedCustomerId = "ticketania";
            IEnqueueToken token = Token
                                  .Enqueue(expectedCustomerId)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");
            DateTime endTime = DateTime.UtcNow;

            Assert.Equal(expectedCustomerId, token.CustomerId);
            Assert.NotNull(token.TokenIdentifier);
            Assert.Equal(TokenVersion.QT1, token.TokenVersion);
            Assert.Equal(EncryptionType.AES256, token.Encryption);
            Assert.True(startTime <= token.Issued);
            Assert.True(endTime >= token.Issued);
            Assert.Equal(token.Expires, DateTime.MaxValue);
            Assert.Null(token.EventId);
            Assert.Null(token.Payload);
        }
Exemplo n.º 8
0
        public void Factory_WithPayload_WithKey_WithRelativeQuality()
        {
            string expectedEventId    = "myevent";
            string expectedCustomerId = "ticketania";
            long   expectedValidity   = 1100;

            IEnqueueTokenPayload expectedPayload = Payload
                                                   .Enqueue()
                                                   .WithKey("somekey")
                                                   .Generate();

            IEnqueueToken token = Token
                                  .Enqueue(expectedCustomerId)
                                  .WithPayload(expectedPayload)
                                  .WithEventId(expectedEventId)
                                  .WithValidity(expectedValidity)
                                  .Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6");

            Assert.Equal(expectedCustomerId, token.CustomerId);
            Assert.Equal(expectedEventId, token.EventId);
            Assert.Equal(expectedValidity, (token.Expires - token.Issued).TotalMilliseconds);
            Assert.Equal(expectedPayload, token.Payload);
        }