public void GetSessionTest() { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); var guid = session.Guid; session = SessionStore.GetSession(guid); Assert.NotNull(session); }
public void SessionExpiryTest() { var session = SessionStore.CreateSession(TimeSpan.FromSeconds(1)); Thread.Sleep(TimeSpan.FromSeconds(2)); session = SessionStore.GetSession(session.Guid); Assert.Null(session); }
public void SessionImmediateTerminationTest() { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); var guid = session.Guid; Assert.True(session.IsValid()); Assert.True(SessionStore.SessionInMemory(guid)); SessionStore.TerminateSessionImmediate(guid); Assert.False(SessionStore.SessionInMemory(guid)); }
public void SessionTerminationTest() { SessionStore.DisposeInterval = TimeSpan.FromSeconds(3); var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); var guid = session.Guid; Assert.True(session.IsValid()); SessionStore.TerminateSession(guid); Thread.Sleep(TimeSpan.FromSeconds(3)); Assert.False(SessionStore.SessionInMemory(guid)); }
static void Main(string[] args) { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); session["TestAttr1"] = "potato"; var obj = new { Test = "potato1", Value = 5 }; session["TestAttr2"] = obj; Console.WriteLine(JsonConvert.SerializeObject(session)); Console.Read(); }
public void SessionAttributeMethodTest() { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); Assert.False(session.HasAttribute("test")); session.SetAttribute("test", null); Assert.True(session.HasAttribute("test")); Assert.True(session.IsNullOrEmpty("test")); session.SetAttribute("test", "potato"); Assert.False(session.IsNullOrEmpty("test")); Assert.Equal("potato", session.GetAttribute <string>("test")); }
public void SessionAttributeIndexerTest() { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); Assert.False(session.HasAttribute("test")); session["test"] = null; Assert.True(session.HasAttribute("test")); Assert.True(session.IsNullOrEmpty("test")); session["test"] = "potato"; Assert.False(session.IsNullOrEmpty("test")); Assert.Equal("potato", session["test"]); }
public void SessionDisposalTest() { SessionStore.DisposeInterval = TimeSpan.FromSeconds(1); var session = SessionStore.CreateSession(TimeSpan.FromSeconds(3)); Assert.True(session.IsValid()); Thread.Sleep(TimeSpan.FromSeconds(1)); session = SessionStore.GetSession(session.Guid); Assert.NotNull(session); Assert.True(session.IsValid()); Thread.Sleep(TimeSpan.FromSeconds(3)); Assert.False(session.IsValid()); session = SessionStore.GetSession(session.Guid); Assert.Null(session); }
public void CreateSessionTest() { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); Assert.NotNull(session); }
public void SessionIsValidTest() { var session = SessionStore.CreateSession(TimeSpan.FromDays(1)); Assert.True(session.IsValid()); }
public IActionResult Index() { if (Request.Query.Count == 0) { return(Redirect("https://andreihava.net/")); } if (Request.Query.ContainsKey("Email")) { var email = Request.Query.ContainsKey("Email") ? Request.Query["Email"].ToString() : string.Empty; if (string.IsNullOrEmpty(email)) { return(BadRequest("Email parameter was defined but didn't have a value!")); } var newReg = Request.Query.ContainsKey("NewAccount") && bool.Parse(Request.Query["NewAccount"].ToString()); var pendingActivation = Request.Query.ContainsKey("PendingActivation") && bool.Parse(Request.Query["PendingActivation"].ToString()); if (string.IsNullOrEmpty(email)) { return(View("Authentication", new AuthenticationIdentity())); } var identity = new AuthenticationIdentity { Email = email, NewAccount = newReg, PendingActivation = pendingActivation }; return(View("Authentication", identity)); } if (Request.Query.ContainsKey("AuthToken")) { Session session; AuthRequestPayload authRequest; var authToken = Request.Query.ContainsKey("AuthToken") ? Request.Query["AuthToken"].ToString() : string.Empty; if (string.IsNullOrEmpty(authToken)) { return(BadRequest("AuthToken parameter was defined but didn't have a value!")); } authRequest = AuthRequestPayload.Decode(authToken); if (Request.Cookies.ContainsKey("SID")) { var sid = Guid.Parse(Request.Cookies["SID"]); session = SessionStore.GetSession(sid); if (session == null || !session.IsValid()) { session = SessionStore.CreateSession(TimeSpan.FromHours(12)); } else { var authResponse = session.GetAttribute <AuthResponsePayload>("AuthPayload"); authResponse.RequestId = authRequest.RequestId; HttpHandler.Post(authRequest.ResponseUri, authResponse.Encode()).Wait(); return(Redirect(authRequest.RedirectUri.ToString())); } } else { session = SessionStore.CreateSession(TimeSpan.FromHours(12)); } session["AuthRequest"] = authRequest; Response.Cookies.Append("SID", session.Guid.ToString(), new CookieOptions() { Domain = Request.Host.Host, HttpOnly = true, SameSite = SameSiteMode.Strict, Expires = DateTimeOffset.UtcNow.AddHours(12) }); Response.Cookies.Append("RID", authRequest.RequestId.ToString(), new CookieOptions() { Domain = Request.Host.Host, HttpOnly = true, SameSite = SameSiteMode.Strict }); return(View("Authentication", new AuthenticationIdentity())); } return(BadRequest()); }