public void AllowEmptyStringUid()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", "" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);
        }
        public void AllowMaxLengthUid()
        {
            var payload = new Dictionary<string, object>
            {
                //                10        20        30        40        50        60        70        80        90       100       110       120       130       140       150       160       170       180       190       200       210       220       230       240       250   256
                { "uid", "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);
        }
Пример #3
0
 public string GetFirebaseToken(string user, string uid, string data)
 {
     var tokenGenerator = new TokenGenerator(_firebaseSecret);
     var authPayload = new Dictionary<string, object>()
     {
         {"uid", uid},
         {"user", user},
         {"data", data}
     };
     var option = new TokenOptions(new DateTime(2015, 1, 1), DateTime.Now.AddSeconds(15));
     string token = tokenGenerator.CreateToken(authPayload, option);
     return token;
 }
        public string FirebaseTokenGenerator(string chave, string uid, string some, string data)
        {
            var tokenGenerator = new TokenGenerator(chave);
            var authPayload = new Dictionary<string, object>()
                {
                  { "uid", uid },
                  { "some", some },
                  { "data", data }
                };
            string token = tokenGenerator.CreateToken(authPayload);

            return token;
        }
        public void AllowNoUidWithAdmin()
        {
            var tokenOptions = new TokenOptions(null, null, true, false);

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(null, tokenOptions);
            var payload1 = new Dictionary<string, object>();
            var token1 = tokenGenerator.CreateToken(payload1, tokenOptions);
            var payload2 = new Dictionary<string, object>
            {
                { "foo", "bar" }
            };
            var token2 = tokenGenerator.CreateToken(payload2, tokenOptions);
        }
        public void BasicInspectTest()
        {
            var customData = "0123456789~!@#$%^&*()_+-=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./;'[]\\<>?\"{}|";
            var payload = new Dictionary<string, object>
            {
                { "uid", "1" },
                { "abc", customData }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var tokenOptions = new TokenOptions(DateTime.Now, DateTime.Now, true, true);

            var token = tokenGenerator.CreateToken(payload, tokenOptions);
            var decoded = JWT.JsonWebToken.DecodeToObject(token, FIREBASE_SUPER_SECRET_KEY) as Dictionary<string, object>;
            Assert.IsTrue(decoded.ContainsKey("v") && (decoded["v"] is int) && (int.Parse(decoded["v"].ToString()) == 0));
            Assert.IsTrue(decoded.ContainsKey("d") && (decoded["d"] as Dictionary<string, object>).ContainsKey("abc"));
            Assert.IsTrue(decoded.ContainsKey("exp") && (decoded["exp"] is int));
            Assert.IsTrue(decoded.ContainsKey("iat") && (decoded["iat"] is int));
            Assert.IsTrue(decoded.ContainsKey("nbf") && (decoded["nbf"] is int));
            Assert.IsTrue(decoded.ContainsKey("admin") && (decoded["admin"] is bool));
            Assert.IsTrue(decoded.ContainsKey("debug") && (decoded["debug"] is bool));
        }
        public void CheckBasicStructureHasCorrectNumberOfFragments()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", "1" },
                { "abc", "0123456789~!@#$%^&*()_+-=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./;'[]\\<>?\"{}|" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);

            String[] tokenFragments = token.Split('.');

            Assert.IsTrue(tokenFragments.Length == 3, "Token has the proper number of fragments: jwt metadata, payload, and signature");
        }
        public void RequireUidStringInPayload()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", 1 }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);
        }
        public void RequireUidInPayload()
        {
            var payload = new Dictionary<string, object>
            {
                { "abc", "0123456789~!@#$%^&*()_+-=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./;'[]\\<>?\"{}|" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);
        }
        public void DisallowTokensTooLong()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", "blah" },
                { "longVar", "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345612345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234561234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);
        }
        public void DisallowInvalidUidWithAdmin2()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", null }
            };

            var tokenOptions = new TokenOptions(null, null, true, false);

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload, tokenOptions);
        }
        public void CheckResultProperlyDoesNotHavePadding()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", "1" },
                { "abc", "0123456789~!@#$%^&*()_+-=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./;'[]\\<>?\"{}|" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);

            Assert.IsTrue(token.IndexOf('=') < 0);
        }
        public void CheckIfResultHasWhiteSpace()
        {
            var payload = new Dictionary<string, object>
            {
                { "uid", "1" },
                { "a", "apple" },
                { "b", "banana" },
                { "c", "carrot" },
                { "number", Double.MaxValue },
                { "abc", "0123456789~!@#$%^&*()_+-=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./;'[]\\<>?\"{}|" },
                { "herp1", "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.?" }
            };

            var tokenGenerator = new TokenGenerator(FIREBASE_SUPER_SECRET_KEY);
            var token = tokenGenerator.CreateToken(payload);

            var pattern = new Regex(@"\s");
            var hasWhiteSpace = pattern.IsMatch(token);

            Assert.IsFalse(hasWhiteSpace, "Token has white space");
        }
        public void CheckIfBasicLength()
        {
            var payload = new Dictionary<string, object>();

            var tokenGenerator = new TokenGenerator("x");
            var token = tokenGenerator.CreateToken(payload);
        }