Exemple #1
0
        public void GenerateToken_WithPayload()
        {
            string expectedSignedToken =
                "eyJ0eXAiOiJRVDEiLCJlbmMiOiJBRVMyNTYiLCJpc3MiOjE1MzQ3MjMyMDAwMDAsImV4cCI6MTUzOTEyOTYwMDAwMCwidGkiOiJhMjFkNDIzYS00M2ZkLTQ4MjEtODRmYS00MzkwZjZhMmZkM2UiLCJjIjoidGlja2V0YW5pYSIsImUiOiJteWV2ZW50In0.0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZc_CQdD63hJre3Sedu0-9zIs.aZgzkJm57etFaXjjME_-9LjOgPNTTqkp1aJ057HuEiU";

            IEnqueueTokenPayload payload = Payload
                                           .Enqueue()
                                           .WithKey("somekey")
                                           .WithRelativeQuality(0.45678663514)
                                           .WithCustomData("color", "blue")
                                           .WithCustomData("size", "medium")
                                           .Generate();

            EnqueueToken token = new EnqueueToken(
                "a21d423a-43fd-4821-84fa-4390f6a2fd3e",
                "ticketania",
                "myevent",
                new DateTime(2018, 08, 20, 0, 0, 0, DateTimeKind.Utc),
                new DateTime(2018, 10, 10, 0, 0, 0, DateTimeKind.Utc),
                null,
                null,
                payload);

            token.Generate("5ebbf794-1665-4d48-80d6-21ac34be7faedf9e10b3-551a-4682-bb77-fee59d6355d6", false);

            string actualSignedToken = token.Token;

            Assert.Equal(expectedSignedToken, actualSignedToken);
        }
Exemple #2
0
 internal EnqueueToken(string tokenIdentifier, string customerId, string eventId, DateTime issued, DateTime?expires, string ipAddress, string xForwardedFor, IEnqueueTokenPayload payload)
 {
     TokenIdentifier = tokenIdentifier;
     CustomerId      = customerId;
     EventId         = eventId;
     Issued          = issued;
     Expires         = expires ?? DateTime.MaxValue;
     Payload         = payload;
     IpAddress       = ipAddress;
     XForwardedFor   = xForwardedFor;
 }
Exemple #3
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);
        }
        public void serialize_customdata_escaped()
        {
            String expectedJson = "{\"cd\":{\"ke\\\"y1\":\"Va\\\"lue1\"}}";

            IEnqueueTokenPayload instance = Payload
                                            .Enqueue()
                                            .WithCustomData("ke\"y1", "Va\"lue1")
                                            .Generate();
            String actualJson = Encoding.UTF8.GetString(((EnqueueTokenPayload)instance).Serialize());

            Assert.Equal(expectedJson, actualJson);
        }
        public void serialize_relativequality()
        {
            String expectedJson = "{\"r\":0.456}";

            IEnqueueTokenPayload instance = Payload
                                            .Enqueue()
                                            .WithRelativeQuality(0.456)
                                            .Generate();
            String actualJson = Encoding.UTF8.GetString(((EnqueueTokenPayload)instance).Serialize());

            Assert.Equal(expectedJson, actualJson);
        }
        public void serialize_key_escaped()
        {
            String expectedJson = "{\"k\":\"my\\\"Key\"}";

            IEnqueueTokenPayload instance = Payload
                                            .Enqueue()
                                            .WithKey("my\"Key")
                                            .Generate();
            String actualJson = Encoding.UTF8.GetString(((EnqueueTokenPayload)instance).Serialize());

            Assert.Equal(expectedJson, actualJson);
        }
        public void serialize_key_relativequality_onecustomdata()
        {
            String expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\"}}";

            IEnqueueTokenPayload instance = Payload
                                            .Enqueue()
                                            .WithKey("myKey")
                                            .WithRelativeQuality(0.456)
                                            .WithCustomData("key1", "Value1")
                                            .Generate();
            String actualJson = Encoding.UTF8.GetString(((EnqueueTokenPayload)instance).Serialize());

            Assert.Equal(expectedJson, actualJson);
        }
        public void factory_customdata()
        {
            String expectedCustomDataValue = "value";
            IEnqueueTokenPayload instance  = Payload
                                             .Enqueue()
                                             .WithCustomData("key", expectedCustomDataValue)
                                             .Generate();
            String actualKey             = instance.Key;
            Double?actualRelativeQuality = instance.RelativeQuality;
            String actualCustomData      = instance.CustomData["key"];

            Assert.Null(actualKey);
            Assert.Null(actualRelativeQuality);
            Assert.Equal(expectedCustomDataValue, actualCustomData);
        }
        public void factory_relativequality()
        {
            Double expectedRelativeQuality = 0.456;
            IEnqueueTokenPayload instance  = Payload
                                             .Enqueue()
                                             .WithRelativeQuality(expectedRelativeQuality)
                                             .Generate();
            String actualKey             = instance.Key;
            Double?actualRelativeQuality = instance.RelativeQuality;
            var    actualCustomData      = instance.CustomData;

            Assert.Null(actualKey);
            Assert.Equal(expectedRelativeQuality, actualRelativeQuality);
            Assert.NotNull(actualCustomData);
            Assert.Equal(0, actualCustomData.Count);
        }
        public void factory_key()
        {
            String expectedKey            = "myKey";
            IEnqueueTokenPayload instance = Payload
                                            .Enqueue()
                                            .WithKey(expectedKey)
                                            .Generate();
            String actualKey        = instance.Key;
            var    actualCustomData = instance.CustomData;

            Assert.Equal(expectedKey, actualKey);
            Assert.Null(instance.RelativeQuality);
            Assert.NotNull(actualCustomData);
            Assert.Equal(0, actualCustomData.Count);

            Assert.False(instance.CustomData.ContainsKey("key"));
        }
        public void factory_key_relativequality_customdata()
        {
            String expectedKey             = "myKey";
            Double expectedRelativeQuality = 0.456;
            String expectedCustomDataValue = "Value";
            IEnqueueTokenPayload instance  = Payload
                                             .Enqueue()
                                             .WithKey(expectedKey)
                                             .WithRelativeQuality(expectedRelativeQuality)
                                             .WithCustomData("key", expectedCustomDataValue)
                                             .Generate();
            String actualKey             = instance.Key;
            Double?actualRelativeQuality = instance.RelativeQuality;
            String actualCustomData      = instance.CustomData["key"];

            Assert.Equal(expectedKey, actualKey);
            Assert.Equal(expectedRelativeQuality, actualRelativeQuality);
            Assert.Equal(expectedCustomDataValue, actualCustomData);
        }
Exemple #12
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);
        }
Exemple #13
0
        public EnqueueTokenGenerator WithPayload(IEnqueueTokenPayload payload)
        {
            this._token = EnqueueToken.AddPayload(this._token, payload);

            return(this);
        }
Exemple #14
0
 internal static EnqueueToken AddPayload(EnqueueToken token, IEnqueueTokenPayload payload)
 {
     return(new EnqueueToken(token.TokenIdentifier, token.CustomerId, token.EventId, token.Issued, token.Expires, token.IpAddress, token.XForwardedFor, payload));
 }