Ejemplo n.º 1
0
        public void Setup()
        {
            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            this.userid = peterAccount.Execute();

            var account2 = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = nonAdminEmail,
                EmailConfirm    = nonAdminEmail,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey2
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            this.nonAdminUserId = account2.Execute();
        }
Ejemplo n.º 2
0
        public void TestUnicode()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = unicodeEmailAddress,
                EmailConfirm    = unicodeEmailAddress,
                Firstname       = "§",
                Lastname        = "¼",
                Password        = "******",
                PasswordConfirm = "β",
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            peterAccount.Execute();

            using (var cn = Majorsilence.Vpn.Logic.InitializeSettings.DbFactory)
            {
                cn.Open();
                var data = cn.Query <Majorsilence.Vpn.Poco.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("¼"));
            }
        }
Ejemplo n.º 3
0
        public void CreateUser(string email, string emailconfirm, string password, string passwordconfirm,
                               string firstname, string lastname, string betakey)
        {
            try
            {
                var account = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                    new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
                {
                    Email           = email,
                    EmailConfirm    = emailconfirm,
                    Firstname       = firstname,
                    Lastname        = lastname,
                    Password        = password,
                    PasswordConfirm = passwordconfirm,
                    BetaKey         = betakey
                },
                    this.email
                    );
                account.Execute();

                this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
            }
            catch (Majorsilence.Vpn.Logic.Exceptions.InvalidDataException ide)
            {
                Majorsilence.Vpn.Logic.Helpers.Logging.Log(ide);
                this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            }
            catch (Exception ex)
            {
                Majorsilence.Vpn.Logic.Helpers.Logging.Log(ex);
                this.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
            }
        }
Ejemplo n.º 4
0
        public void IsNotAdmin()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            peterAccount.Execute();

            using (var cn = Majorsilence.Vpn.Logic.InitializeSettings.DbFactory)
            {
                cn.Open();
                var data = cn.Query <Majorsilence.Vpn.Poco.Users>("SELECT * FROM Users WHERE Email = @email", new { email = emailAddress });

                Assert.That(data.First().Admin, Is.False);
            }
        }
Ejemplo n.º 5
0
        public void RetreiveUserInfoTest()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = ""
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            var userid = peterAccount.Execute();

            Assert.That(AccountExists(emailAddress), Is.True);


            var info    = new Majorsilence.Vpn.Logic.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));
        }
Ejemplo n.º 6
0
        public void UpdateUserInfoInvalidEmailTest()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = ""
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            var userid = peterAccount.Execute();

            Assert.That(AccountExists(emailAddress), Is.True);


            var info    = new Majorsilence.Vpn.Logic.Accounts.UserInfo(userid);
            var profile = info.GetProfile();

            Assert.Throws <Majorsilence.Vpn.Logic.Exceptions.InvalidDataException>(() => info.UpdateProfile("", "Happy", "Dude"));
        }
Ejemplo n.º 7
0
        public void Setup()
        {
            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Bobby",
                Lastname        = "Smith",
                Password        = "******",
                PasswordConfirm = "Password54",
                BetaKey         = ""
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            this.userid = peterAccount.Execute();

            var region = new Majorsilence.Vpn.Logic.Admin.Regions();

            regionid = region.Insert("Test region", true);

            var vpnserver = new Majorsilence.Vpn.Logic.Admin.VpnServers();

            vpnseverid = vpnserver.Insert("localhost", 5678, "a fake vpnserver for testing", regionid, true);
        }
Ejemplo n.º 8
0
        public void Setup()
        {
            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = this.emailAddress,
                EmailConfirm    = this.emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = this.password,
                PasswordConfirm = this.password,
                BetaKey         = betaKey
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            peterAccount.Execute();
            System.Console.WriteLine("Created account");
            using (var cn = Majorsilence.Vpn.Logic.InitializeSettings.DbFactory)
            {
                cn.Open();
                var users = cn.Query <Majorsilence.Vpn.Poco.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 Majorsilence.Vpn.Logic.Exceptions.InvalidDataException("User for test not created");
                }
            }
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = this.emailAddress,
                EmailConfirm    = this.emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = this.password,
                PasswordConfirm = this.password,
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            this.userid = peterAccount.Execute();
        }
Ejemplo n.º 10
0
        public void ValidDataTest()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            peterAccount.Execute();

            Assert.That(AccountExists(emailAddress), Is.True);
        }
Ejemplo n.º 11
0
        public void DuplicateEmailTest()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            peterAccount.Execute();


            var peterAccount2 = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey2
            }
                , false, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            Assert.Throws <Majorsilence.Vpn.Logic.Exceptions.EmailAddressAlreadyUsedException>(() => peterAccount2.Execute());

            Assert.That(AccountExists(emailAddress), Is.True);
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            StripeConfiguration.SetApiKey(Majorsilence.Vpn.Logic.Helpers.SiteInfo.StripeAPISecretKey);

            Majorsilence.Vpn.Logic.Helpers.SslSecurity.Callback();

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            this.userid = peterAccount.Execute();


            CreateToken();
        }
Ejemplo n.º 13
0
        public void EmptyBetaKey()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = ""
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            Assert.Throws <Majorsilence.Vpn.Logic.Exceptions.InvalidBetaKeyException>(() => peterAccount.Execute());



            Assert.That(AccountExists(emailAddress), Is.False);
        }
Ejemplo n.º 14
0
        public void EmailMismatch()
        {
            Assert.That(AccountExists(emailAddress), Is.False);

            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = "*****@*****.**",
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = "******",
                PasswordConfirm = "Password1",
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.Email);

            Assert.Throws <Majorsilence.Vpn.Logic.Exceptions.EmailMismatchException>(() => peterAccount.Execute());
        }
Ejemplo n.º 15
0
        private void RetrieveLoginTokenAndAssert()
        {
            var peterAccount = new Majorsilence.Vpn.Logic.Accounts.CreateAccount(
                new Majorsilence.Vpn.Logic.Accounts.CreateAccountInfo()
            {
                Email           = emailAddress,
                EmailConfirm    = emailAddress,
                Firstname       = "Peter",
                Lastname        = "Gill",
                Password        = password,
                PasswordConfirm = password,
                BetaKey         = betaKey
            }
                , true, Majorsilence.Vpn.Logic.InitializeSettings.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 <Majorsilence.Vpn.Site.Helpers.ISessionVariables>();
                    mock.SetupAllProperties();

                    Majorsilence.Vpn.Site.Helpers.ISessionVariables sessionVars = mock.Object;
                    var controller = new Majorsilence.Vpn.Site.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

                    FakeControllerContext.SetContext(controller, 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 <Majorsilence.Vpn.Logic.DTO.ApiAuthResponse>(blah.Content);
                    Assert.That(string.IsNullOrEmpty(content.Token1), Is.EqualTo(false));
                    Assert.That(string.IsNullOrEmpty(content.Token2), Is.EqualTo(false));

                    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();
                }
        }