Example #1
0
        public void TestPositive()
        {
            string payload      = jwt.GetPayload(token);
            bool   verification = jwt.DoVerify(token, "HS256", claimslevel1, options);

            True(verification, jwt);
        }
        public void TestMalformedPayload()
        {
            string res = jwt.GetPayload(token);

            Assert.IsTrue(SecurityUtils.compareStrings(res, ""));
            Assert.IsTrue(jwt.HasError());
        }
        public void TestGetPayload()
        {
            string payload = "{\"sub\":\"subject1\",\"aud\":\"audience1\",\"hola1\":\"hola1\",\"iss\":\"GXSA\",\"hola2\":\"hola2\",\"jti\":\""
                             + ID + "\"}";
            string payload1 = "{\"hola1\":\"hola1\",\"hola2\":\"hola2\",\"iss\":\"GXSA\",\"sub\":\"subject1\",\"aud\":\"audience1\",\"jti\":\""
                              + ID + "\"}";
            string payload2 = "{\"sub\":\"subject1\",\"aud\":\"audience1\",\"hola1\":\"hola1\",\"iss\":\"GXSA\",\"hola2\":\"hola2\",\"jti\":\""
                              + ID + "\"}";

            string tPayload = jwt.GetPayload(token);

            Assert.IsTrue(SecurityUtils.compareStrings(payload, tPayload) || SecurityUtils.compareStrings(payload1, tPayload) ||
                          SecurityUtils.compareStrings(payload2, tPayload));
        }
        public virtual void SetUp()
        {
            jwt     = new JWTCreator();
            options = new JWTOptions();
            keyGen  = new SymmetricKeyGenerator();
            claims  = new PrivateClaims();

            options.AddCustomTimeValidationClaim("exp", "2020/07/20 17:56:51", "20");
            options.AddCustomTimeValidationClaim("iat", "2020/07/20 17:56:51", "20");
            options.AddCustomTimeValidationClaim("nbf", "2020/07/20 17:56:51", "20");
            claims.setClaim("hola1", "hola1");
            string hexaKey = keyGen.doGenerateKey("GENERICRANDOM", 256);

            options.SetSecret(hexaKey);
            string token = jwt.DoCreate("HS256", claims, options);

            payload = jwt.GetPayload(token);


            expected = "{\"hola1\":\"hola1\",\"exp\":1595267811,\"iat\":1595267811,\"nbf\":1595267811}";
        }