Beispiel #1
0
 def dispatch_request(self):
     form = WalletForm(request.form)
     if request.method == 'POST' and form.validate():
         newwallet = Wallet(**form.data)
         session.add(newwallet)
         session.commit()
         flash("%s: Wallet added" % newwallet.label)
         return redirect(url_for("wallet.wallet_list"))
     return render_template("wallet/wallet/add.html", form=form)
Beispiel #2
0
 def dispatch_request(self):
     form = WalletForm(request.form)
     if request.method == 'POST' and form.validate():
         newwallet = Wallet(**form.data)
         session.add(newwallet)
         session.commit()
         flash("%s: Wallet added" % newwallet.label)
         return redirect(url_for("wallet.wallet_list"))
     return render_template("wallet/wallet/add.html", form=form)
Beispiel #3
0
 def dispatch_request(self):
     settings = Setting.query.filter(Setting.name != 'otpsecret').all()
     form = EditForm(request.form)
     if request.method == 'POST' and form.validate():
         setting = Setting(form.name.data, form.value_decrypted.data)
         session.add(setting)
         session.commit()
         return redirect(url_for('settings.list'))
     return render_template('settings/list.html', settings=settings,
                            form=form)
Beispiel #4
0
 def test_setval_int(self):
     key = 'test_setval_int'
     value = '94'
     newsetting = Setting(key, value)
     session.add(newsetting)
     session.commit()
     setting = session.query(Setting).get(key)
     self.assertEqual(
         setting.value_decrypted,
         value,
         "Setting incorrectly saved",
     )
Beispiel #5
0
 def test_setval_string(self):
     key = 'test_setval_stringX'
     value = u'test_setval_string'
     newsetting = Setting(key, value)
     session.add(newsetting)
     session.commit()
     setting = Setting.query.get(key)
     self.assertEqual(
         setting.value_decrypted,
         value,
         "Setting incorrectly saved",
     )
Beispiel #6
0
 def test_setval_int(self):
     key = 'test_setval_int'
     value = '94'
     newsetting = Setting(key, value)
     session.add(newsetting)
     session.commit()
     setting = session.query(Setting).get(key)
     self.assertEqual(
         setting.value_decrypted,
         value,
         "Setting incorrectly saved",
     )
Beispiel #7
0
 def test_setval_string(self):
     key = 'test_setval_stringX'
     value = u'test_setval_string'
     newsetting = Setting(key, value)
     session.add(newsetting)
     session.commit()
     setting = Setting.query.get(key)
     self.assertEqual(
         setting.value_decrypted,
         value,
         "Setting incorrectly saved",
     )
Beispiel #8
0
 def test_setval_dupe(self):
     newsetting = Setting('testkey', u'teststring')
     session.add(newsetting)
     session.commit()
     newsetting = Setting('testkey', u'teststring')
     session.add(newsetting)
     dupe = False
     try:
         session.commit()
         dupe = True
     except IntegrityError:
         session.rollback()
     self.assertFalse(
         dupe,
         "Could set the same key twice",
     )
Beispiel #9
0
 def test_setval_dupe(self):
     newsetting = Setting('testkey', u'teststring')
     session.add(newsetting)
     session.commit()
     newsetting = Setting('testkey', u'teststring')
     session.add(newsetting)
     dupe = False
     try:
         session.commit()
         dupe = True
     except IntegrityError:
         session.rollback()
     self.assertFalse(
         dupe,
         "Could set the same key twice",
     )
Beispiel #10
0
 def get_secret(self):
     """
     Cryptographically-secure 10 byte random key, presented to the user as
     a base32 16-character string.
     """
     name = 'otpsecret'
     setting = session.query(Setting).get(name)
     if setting:
         ret = False
     else:
         secret = get_random_bytes(10)
         code = b32encode(secret)
         setting = Setting(name, code)
         session.add(setting)
         session.commit()
         ret = code
     return ret
Beispiel #11
0
 def setUpClass(cls):
     setting_name = Setting('name', u'Bob')
     setting_mail = Setting('mail', u'*****@*****.**')
     setting_number = Setting('number', 66)
     session.add(setting_name)
     session.add(setting_mail)
     session.add(setting_number)
     session.commit()
Beispiel #12
0
 def setUpClass(cls):
     setting_name = Setting('name', u'Bob')
     setting_mail = Setting('mail', u'*****@*****.**')
     setting_number = Setting('number', 66)
     session.add(setting_name)
     session.add(setting_mail)
     session.add(setting_number)
     session.commit()
Beispiel #13
0
    def test_wallet_dupes(self):
        """
        Rather pointless to test the ORM itself, but I had gotten
        this wrong initially.
        """
        newwallet0 = self.get_wallet(0)
        session.add(newwallet0)
        session.commit()

        dupe = False
        newwallet1 = self.get_wallet(1)
        try:
            session.add(newwallet1)
            session.commit()
            dupe = True
        except IntegrityError:
            session.rollback()
        self.assertFalse(
            dupe,
            'Unique DB constraint was ignored',
        )
        session.delete(newwallet0)
        session.commit()
Beispiel #14
0
    def test_wallet_dupes(self):
        """
        Rather pointless to test the ORM itself, but I had gotten
        this wrong initially.
        """
        newwallet0 = self.get_wallet(0)
        session.add(newwallet0)
        session.commit()

        dupe = False
        newwallet1 = self.get_wallet(1)
        try:
            session.add(newwallet1)
            session.commit()
            dupe = True
        except IntegrityError:
            session.rollback()
        self.assertFalse(
            dupe,
            'Unique DB constraint was ignored',
        )
        session.delete(newwallet0)
        session.commit()
Beispiel #15
0
def setUpModule():
    init_db()
    ctx = app.test_request_context()
    ctx.push()
    wallet1 = Wallet(
        'box1',
        'admin1',
        '123',
        'localhost',
        19001,
        False,
        True,
    )
    wallet2 = Wallet(
        'box2',
        'admin2',
        '123',
        'localhost',
        19011,
        False,
        True,
    )
    session.add(wallet1)
    session.add(wallet2)
    session.commit()
    # DONTFIXME encryption should be done through the webapp
    # Actually, no, this can't be done as it makes the daemon stop..
    # Unless we let this code restart it...
    conn = get_connection(wallet2)
    info = conn.getinfo()
    if not hasattr(info, 'unlocked_until'):
        conn.encryptwallet(pp)
    else:
        # Unlock and refill the keypool
        conn.walletpassphrase(pp, 1)
        conn.keypoolrefill()
Beispiel #16
0
def setUpModule():
    init_db()
    ctx = app.test_request_context()
    ctx.push()
    wallet1 = Wallet(
        'box1',
        'admin1',
        '123',
        'localhost',
        19001,
        False,
        True,
    )
    wallet2 = Wallet(
        'box2',
        'admin2',
        '123',
        'localhost',
        19011,
        False,
        True,
    )
    session.add(wallet1)
    session.add(wallet2)
    session.commit()
    # DONTFIXME encryption should be done through the webapp
    # Actually, no, this can't be done as it makes the daemon stop..
    # Unless we let this code restart it...
    conn = get_connection(wallet2)
    info = conn.getinfo()
    if not hasattr(info, 'unlocked_until'):
        conn.encryptwallet(pp)
    else:
        # Unlock and refill the keypool
        conn.walletpassphrase(pp, 1)
        conn.keypoolrefill()