Exemple #1
0
    def setUp(self):
        self.db_fd, twofa.app.config['DATABASE'] = tempfile.mkstemp()
        twofa.app.testing = True
        twofa.app.config['WTF_CSRF_METHODS'] = []  # This is the magic
        twofa.app.config['WTF_CSRF_ENABLED'] = False
        self.app = twofa.app.test_client()
        with twofa.app.app_context():
            twofa.init_db()

        self.user = User(username='******',
                         password='******',
                         email='*****@*****.**',
                         authy_id='fake_id')
        db_session.add(self.user)
        db_session.commit()
Exemple #2
0
    def test_account_as_authentified(self):
        # Arrange
        user = User('*****@*****.**',
                    'fakepassword',
                    'Alice',
                    33,
                    600112233,
                    123,
                    authy_status='approved')
        db.session.add(user)
        db.session.commit()
        db.session.refresh(user)
        with self.client.session_transaction() as sess:
            sess['user_id'] = user.id

        # Act
        resp = self.client.get('/account')

        # Assert
        self.assertEqual(resp.status_code, 302)
Exemple #3
0
    def test_account_as_logged_in(self):
        # Arrange
        user = User('*****@*****.**',
                    'fakepassword',
                    'Alice',
                    33,
                    600112233,
                    123,
                    authy_status='unverified')
        db.session.add(user)
        db.session.commit()
        db.session.refresh(user)
        with self.client.session_transaction() as sess:
            sess['user_id'] = user.id

        # Act
        resp = self.client.get('/account')

        # Assert
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.location, 'http://localhost/login')
    def test_account_as_authentified(self):
        # Arrange
        user = User(
            "*****@*****.**",
            "fakepassword",
            "Alice",
            33,
            600112233,
            123,
            authy_status="approved",
        )
        db.session.add(user)
        db.session.commit()
        db.session.refresh(user)
        with self.client.session_transaction() as sess:
            sess["user_id"] = user.id

        # Act
        resp = self.client.get("/account")

        # Assert
        self.assertEqual(resp.status_code, 302)
    def test_account_as_logged_in(self):
        # Arrange
        user = User(
            "*****@*****.**",
            "fakepassword",
            "Alice",
            33,
            600112233,
            123,
            authy_status="unverified",
        )
        db.session.add(user)
        db.session.commit()
        db.session.refresh(user)
        with self.client.session_transaction() as sess:
            sess["user_id"] = user.id

        # Act
        resp = self.client.get("/account")

        # Assert
        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp.location, "http://localhost/login")
 def setUp(self):
     self.app = create_app("testing")
     self.user = User("*****@*****.**", "fakepassword", "Alice", 33,
                      600112233, 123)
     db.create_all()
class UserTestCase(unittest.TestCase):
    def setUp(self):
        self.app = create_app("testing")
        self.user = User("*****@*****.**", "fakepassword", "Alice", 33,
                         600112233, 123)
        db.create_all()

    def tearDown(self):
        db.session.remove()
        db.drop_all()

    def test_has_authy_app(self):
        # Arrange

        # Act
        with patch("twofa.models.authy_user_has_app", return_value=True):
            has_authy_app = self.user.has_authy_app

        # Assert
        self.assertTrue(has_authy_app)

    def test_hasnt_authy_app(self):
        # Arrange

        # Act
        with patch("twofa.models.authy_user_has_app", return_value=False):
            has_authy_app = self.user.has_authy_app

        # Assert
        self.assertFalse(has_authy_app)

    def test_password_is_unreadable(self):
        # Arrange

        # Act / Assert
        with self.assertRaises(AttributeError):
            self.user.password

    def test_password_setter(self):
        # Arrange
        old_password_hash = self.user.password_hash
        password = "******"

        # Act
        self.user.password = password

        # Assert
        self.assertNotEqual(password, self.user.password_hash)
        self.assertNotEqual(old_password_hash, self.user.password_hash)

    def test_verify_password(self):
        # Arrange
        password = "******"
        unused_password = "******"
        self.user.password = password

        # Act
        ret_good_password = self.user.verify_password(password)
        ret_bad_password = self.user.verify_password(unused_password)

        # Assert
        self.assertTrue(ret_good_password)
        self.assertFalse(ret_bad_password)

    def test_send_one_touch_request(self):
        # Arrange

        # Act
        with patch("twofa.models.send_authy_one_touch_request") as fake_send:
            self.user.send_one_touch_request()

        # Assert
        fake_send.assert_called_with(self.user.authy_id, self.user.email)
 def setUp(self):
     self.app = create_app('testing')
     self.client = self.app.test_client()
     self.user = User('*****@*****.**', 'fakepassword', 'test', 33,
                      '611223344', 1234)
     db.create_all()
Exemple #9
0
 def setUp(self):
     self.app = create_app("testing")
     self.client = self.app.test_client()
     self.user = User("*****@*****.**", "fakepassword", "test", 33,
                      "611223344", 1234)
     db.create_all()
Exemple #10
0
 def setUp(self):
     self.app = create_app('testing')
     self.user = User('*****@*****.**', 'fakepassword', 'Alice', 33,
                      600112233, 123)
     db.create_all()