public void Verify_ForExpiredToken_ReturnsError() { var parser = new JwtParser(); string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJhZmFsLmdyYWR6aWVAZmluZ28ucGwiLCJpc3MiOiJMZWduaWNhSVQiLCJBcHBJZCI6IjEiLCJuYmYiOjE0ODE3MTc0MTcsImV4cCI6MTQ4MTcyMTAxNywiaWF0IjoxNDgxNzE3NDE3fQ.ZPzu-eaoaY7CxyQmJwvfk18vd9sO5guOwbfjsKK1Qcg"; VerifyResultModel result = parser.Verify(token); Assert.Equal(false, result.IsValid); Assert.Equal(null, result.ExpiryDate); }
public void Verify_ForFreshToken_ReturnsOk() { var parser = new JwtParser(); AcquireTokenModel tokenModel = parser.AcquireToken("*****@*****.**", 1); VerifyResultModel result = parser.Verify(tokenModel.Token); Assert.Equal(true, result.IsValid); Assert.NotNull(result.ExpiryDate); }
public void Verify_ForTokenParametersData() { var parser = new JwtParser(); string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6IjEyM0B0ZXN0LnBsIiwiaXNzIjoiTGVnbmljYUlUIiwiYXBwSWQiOiIxIiwicm9sZSI6IlVzZXIiLCJuYmYiOjE0ODQxNDAwMjgsImV4cCI6MTQ4NDE0MDA4OCwiaWF0IjoxNDg0MTQwMDI4fQ.fZXSj3jZIQ8u2aoAzv6fDW0_c7BBb5oVr2oVDytnTek"; VerifyResultModel result = parser.Verify(token, true); var email = result.Email; var appId = result.AppId; Assert.Equal("*****@*****.**", email); Assert.Equal(1, appId); }
public JsonResult Verify(VerifyTokenModel model) { if (!ModelState.IsValid) { var errorResult = ModelState.GetErrorModel(); return(Json(errorResult)); } var parser = new JwtParser(); var verifiyResult = parser.Verify(model.Token); var result = new ResultModel <bool>(verifiyResult.IsValid); return(Json(result)); }
public void Verify_ForFreshToken_ReturnsCorrectExpiryDate() { var mockedDateTimeProvider = new Mock <IDateTimeProvider>(); var dateFormat = "yyyy-MM-dd HH:mm"; var dateNow = DateTime.UtcNow; // we are using mocked IDateTimeProvider to make sure we are refering to same "now" mockedDateTimeProvider.Setup(p => p.GetNow()).Returns(dateNow); var parser = new JwtParser(mockedDateTimeProvider.Object); var dateNowFutureString = dateNow.AddDays(parser.GetExpiredDays()).ToString(dateFormat); AcquireTokenModel tokenModel = parser.AcquireToken("*****@*****.**", 1); VerifyResultModel result = parser.Verify(tokenModel.Token); string expiryDateString = null; if (result.ExpiryDate != null) { expiryDateString = result.ExpiryDate.Value.ToString(dateFormat); } Assert.Equal(dateNowFutureString, expiryDateString); }