public void Setup() { var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = this.emailAddress, EmailConfirm = this.emailAddress, Firstname = "Peter", Lastname = "Gill", Password = this.password, PasswordConfirm = this.password, BetaKey = betaKey } , false, LibLogic.Setup.Email); peterAccount.Execute(); System.Console.WriteLine("Created account"); using (var cn = LibLogic.Setup.DbFactory) { cn.Open(); var users = cn.Query <LibPoco.Users>("SELECT * FROM Users WHERE Email = @Email", new { Email = emailAddress }); System.Console.WriteLine("user count " + users.Count()); if (users.Count() == 1) { userid = users.First().Id; } else { throw new LibLogic.Exceptions.InvalidDataException("User for test not created"); } } }
public void RetreiveUserInfoTest() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = "" } , false, LibLogic.Setup.Email); var userid = peterAccount.Execute(); Assert.That(AccountExists(emailAddress), Is.True); var info = new LibLogic.Accounts.UserInfo(userid); var profile = info.GetProfile(); Assert.That("Peter", Is.EqualTo(profile.FirstName)); Assert.That("Gill", Is.EqualTo(profile.LastName)); Assert.That(emailAddress, Is.EqualTo(profile.Email)); Assert.That(false, Is.EqualTo(profile.Admin)); Assert.That(false, Is.EqualTo(profile.IsBetaUser)); }
public void Setup() { var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey } , true, LibLogic.Setup.Email); this.userid = peterAccount.Execute(); var account2 = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = nonAdminEmail, EmailConfirm = nonAdminEmail, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey2 } , false, LibLogic.Setup.Email); this.nonAdminUserId = account2.Execute(); }
public void IsNotAdmin() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey } , false, LibLogic.Setup.Email); peterAccount.Execute(); using (var cn = LibLogic.Setup.DbFactory) { cn.Open(); var data = cn.Query <LibPoco.Users>("SELECT * FROM Users WHERE Email = @email", new { email = emailAddress }); Assert.That(data.First().Admin, Is.False); } }
public void UpdateUserInfoInvalidEmailTest() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = "" } , false, LibLogic.Setup.Email); var userid = peterAccount.Execute(); Assert.That(AccountExists(emailAddress), Is.True); var info = new LibLogic.Accounts.UserInfo(userid); var profile = info.GetProfile(); info.UpdateProfile("", "Happy", "Dude"); }
public void TestUnicode() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = unicodeEmailAddress, EmailConfirm = unicodeEmailAddress, Firstname = "§", Lastname = "¼", Password = "******", PasswordConfirm = "β", BetaKey = betaKey } , true, LibLogic.Setup.Email); peterAccount.Execute(); using (var cn = LibLogic.Setup.DbFactory) { cn.Open(); var data = cn.Query <LibPoco.Users>("SELECT * FROM Users WHERE Email = @email", new { email = unicodeEmailAddress }); Assert.That(data.First().IsBetaUser, Is.True); Assert.That(data.First().Admin, Is.True); Assert.That(data.First().FirstName, Is.EqualTo("§")); Assert.That(data.First().LastName, Is.EqualTo("¼")); } }
public void Setup() { var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Bobby", Lastname = "Smith", Password = "******", PasswordConfirm = "Password54", BetaKey = "" } , false, LibLogic.Setup.Email); this.userid = peterAccount.Execute(); var region = new LibLogic.Admin.Regions(); regionid = region.Insert("Test region", true); var vpnserver = new LibLogic.Admin.VpnServers(); vpnseverid = vpnserver.Insert("localhost", 5678, "a fake vpnserver for testing", regionid, true); }
public void Setup() { var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = this.emailAddress, EmailConfirm = this.emailAddress, Firstname = "Peter", Lastname = "Gill", Password = this.password, PasswordConfirm = this.password, BetaKey = betaKey } , true, LibLogic.Setup.Email); this.userid = peterAccount.Execute(); }
public void CreateUser() { try { string password = Helpers.GlobalHelper.RequestEncodedParam("password"); string confirmPassword = Helpers.GlobalHelper.RequestEncodedParam("passwordconfirm"); string email = Helpers.GlobalHelper.RequestEncodedParam("email"); string confirmEmail = Helpers.GlobalHelper.RequestEncodedParam("emailconfirm"); string firstname = Helpers.GlobalHelper.RequestEncodedParam("firstname"); string lastname = Helpers.GlobalHelper.RequestEncodedParam("lastname"); string betakey = Helpers.GlobalHelper.RequestEncodedParam("betakey"); var emailFake = new LibLogic.Email.LiveEmail(); var account = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = email, EmailConfirm = confirmEmail, Firstname = firstname, Lastname = lastname, Password = password, PasswordConfirm = confirmPassword, BetaKey = betakey }, emailFake ); account.Execute(); this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.OK; } catch (LibLogic.Exceptions.InvalidDataException ide) { LibLogic.Helpers.Logging.Log(ide); this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; this.HttpContext.Response.Write(ide.Message); } catch (Exception ex) { LibLogic.Helpers.Logging.Log(ex); this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; } }
public void EmailAddressMissing() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = "", EmailConfirm = "", Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey } , true, LibLogic.Setup.Email); peterAccount.Execute(); }
public void EmailMismatch() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = "*****@*****.**", Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey } , true, LibLogic.Setup.Email); peterAccount.Execute(); }
public void InvalidBetaKey() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = "A Fake Beta Key" } , true, LibLogic.Setup.Email); peterAccount.Execute(); Assert.That(AccountExists(emailAddress), Is.False); }
public void DuplicateEmailTest() { Assert.That(AccountExists(emailAddress), Is.False); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey } , false, LibLogic.Setup.Email); peterAccount.Execute(); var peterAccount2 = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey2 } , false, LibLogic.Setup.Email); peterAccount2.Execute(); Assert.That(AccountExists(emailAddress), Is.True); }
public void Setup() { StripeConfiguration.SetApiKey(LibLogic.Helpers.SiteInfo.StripeAPISecretKey); LibLogic.Helpers.SslSecurity.Callback(); var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = "******", PasswordConfirm = "Password1", BetaKey = betaKey } , true, LibLogic.Setup.Email); this.userid = peterAccount.Execute(); CreateToken(); }
private void RetrieveLoginTokenAndAssert() { var peterAccount = new LibLogic.Accounts.CreateAccount( new LibLogic.Accounts.CreateAccountInfo() { Email = emailAddress, EmailConfirm = emailAddress, Firstname = "Peter", Lastname = "Gill", Password = password, PasswordConfirm = password, BetaKey = betaKey } , true, LibLogic.Setup.Email); userid = peterAccount.Execute(); // in an actual desktop app this will need to be setup as static var cookieContainer = new System.Net.CookieContainer(); using (var handler = new System.Net.Http.HttpClientHandler() { CookieContainer = cookieContainer }) using (var client = new System.Net.Http.HttpClient(handler)) { var byteArray = System.Text.Encoding.UTF8.GetBytes(string.Format("{0}:{1}", emailAddress, password)); var headerAuth = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Authorization = headerAuth; var mock = new Mock <VpnSite.Helpers.ISessionVariables>(); mock.SetupAllProperties(); VpnSite.Helpers.ISessionVariables sessionVars = mock.Object; var controller = new VpnSite.Controllers.ApiV2Controller(sessionVars); var header = new NameValueCollection(); header.Add("Authorization", headerAuth.ToString()); // See http://stephenwalther.com/archive/2008/07/01/asp-net-mvc-tip-12-faking-the-controller-context controller.ControllerContext = new MvcFakes.FakeControllerContext(controller, null, null, null, null, null, null, header); var blah = controller.Auth(); //controller.Auth(); System.Console.WriteLine(blah.Content); // mock.VerifySet(framework => framework.IsAdmin = true); Assert.That(sessionVars.LoggedIn, Is.EqualTo(true)); Assert.That(sessionVars.Username, Is.EqualTo(emailAddress)); Assert.That(sessionVars.UserId, Is.EqualTo(userid)); Assert.That(sessionVars.IsAdmin, Is.EqualTo(true)); Assert.That(controller.Response.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.OK)); var content = Newtonsoft.Json.JsonConvert.DeserializeObject <LibLogic.DTO.ApiAuthResponse>(blah.Content); Assert.IsNotNullOrEmpty(content.Token1); Assert.IsNotNullOrEmpty(content.Token2); Assert.That(content.Token1ExpireUtc, Is.GreaterThan(DateTime.UtcNow)); Assert.That(content.Token1ExpireUtc, Is.LessThan(DateTime.UtcNow.AddDays(1))); Assert.That(content.Token2ExpireUtc, Is.GreaterThan(DateTime.UtcNow.AddDays(1))); Assert.That(content.Token2ExpireUtc, Is.LessThan(DateTime.UtcNow.AddDays(2))); token1 = content.Token1; token2 = content.Token2; // See http://haacked.com/archive/2007/06/19/unit-tests-web-code-without-a-web-server-using-httpsimulator.aspx/ // var responseString = response.Content.ReadAsStringAsync(); } }