3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #142743 from symphorien/ihm-5-dev-2

python3.pkgs.ihatemoney: 4.2 -> 5.1.1
This commit is contained in:
Guillaume Girol 2021-10-31 19:32:40 +00:00 committed by GitHub
commit 9545fade8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 224 additions and 339 deletions

View file

@ -556,6 +556,17 @@ Superuser created successfully.
<link xlink:href="options.html#opt-services.geoipupdate.enable">services.geoipupdate</link>.
</para>
</listitem>
<listitem>
<para>
<literal>ihatemoney</literal> has been updated to version
5.1.1
(<link xlink:href="https://github.com/spiral-project/ihatemoney/blob/5.1.1/CHANGELOG.rst">release
notes</link>). If you serve ihatemoney by HTTP rather than
HTTPS, you must set
<link xlink:href="options.html#opt-services.ihatemoney.secureCookie">services.ihatemoney.secureCookie</link>
to <literal>false</literal>.
</para>
</listitem>
<listitem>
<para>
PHP 7.3 is no longer supported due to upstream not supporting

View file

@ -204,6 +204,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- `services.geoip-updater` was broken and has been replaced by [services.geoipupdate](options.html#opt-services.geoipupdate.enable).
- `ihatemoney` has been updated to version 5.1.1 ([release notes](https://github.com/spiral-project/ihatemoney/blob/5.1.1/CHANGELOG.rst)). If you serve ihatemoney by HTTP rather than HTTPS, you must set [services.ihatemoney.secureCookie](options.html#opt-services.ihatemoney.secureCookie) to `false`.
- PHP 7.3 is no longer supported due to upstream not supporting this version for the entire lifecycle of the 21.11 release.
- Those making use of `buildBazelPackage` will need to regenerate the fetch hashes (preferred), or set `fetchConfigured = false;`.

View file

@ -33,11 +33,14 @@ let
then "sqlite:////var/lib/ihatemoney/ihatemoney.sqlite"
else "postgresql:///${db}"}'
SQLALCHEMY_TRACK_MODIFICATIONS = False
MAIL_DEFAULT_SENDER = ("${cfg.defaultSender.name}", "${cfg.defaultSender.email}")
MAIL_DEFAULT_SENDER = (r"${cfg.defaultSender.name}", r"${cfg.defaultSender.email}")
ACTIVATE_DEMO_PROJECT = ${toBool cfg.enableDemoProject}
ADMIN_PASSWORD = "${toString cfg.adminHashedPassword /*toString null == ""*/}"
ADMIN_PASSWORD = r"${toString cfg.adminHashedPassword /*toString null == ""*/}"
ALLOW_PUBLIC_PROJECT_CREATION = ${toBool cfg.enablePublicProjectCreation}
ACTIVATE_ADMIN_DASHBOARD = ${toBool cfg.enableAdminDashboard}
SESSION_COOKIE_SECURE = ${toBool cfg.secureCookie}
ENABLE_CAPTCHA = ${toBool cfg.enableCaptcha}
LEGAL_LINK = r"${toString cfg.legalLink}"
${cfg.extraConfig}
'';
@ -79,9 +82,20 @@ in
description = "The email of the sender of ihatemoney emails";
};
};
secureCookie = mkOption {
type = types.bool;
default = true;
description = "Use secure cookies. Disable this when ihatemoney is served via http instead of https";
};
enableDemoProject = mkEnableOption "access to the demo project in ihatemoney";
enablePublicProjectCreation = mkEnableOption "permission to create projects in ihatemoney by anyone";
enableAdminDashboard = mkEnableOption "ihatemoney admin dashboard";
enableCaptcha = mkEnableOption "a simplistic captcha for some forms";
legalLink = mkOption {
type = types.nullOr types.str;
default = null;
description = "The URL to a page explaining legal statements about your service, eg. GDPR-related information.";
};
extraConfig = mkOption {
type = types.str;
default = "";

View file

@ -191,7 +191,7 @@ in
i3wm = handleTest ./i3wm.nix {};
icingaweb2 = handleTest ./icingaweb2.nix {};
iftop = handleTest ./iftop.nix {};
ihatemoney = handleTest ./ihatemoney.nix {};
ihatemoney = handleTest ./ihatemoney {};
incron = handleTest ./incron.nix {};
influxdb = handleTest ./influxdb.nix {};
initrd-network-openvpn = handleTest ./initrd-network-openvpn {};

View file

@ -1,22 +1,36 @@
{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../.. { inherit system config; }
pkgs ? import ../../.. { inherit system config; }
}:
let
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
inherit (import ../../lib/testing-python.nix { inherit system pkgs; }) makeTest;
f = backend: makeTest {
name = "ihatemoney-${backend}";
machine = { lib, ... }: {
machine = { nodes, lib, ... }: {
services.ihatemoney = {
enable = true;
enablePublicProjectCreation = true;
secureCookie = false;
inherit backend;
uwsgiConfig = {
http = ":8000";
};
};
boot.cleanTmpDir = true;
# for exchange rates
security.pki.certificateFiles = [ ./server.crt ];
networking.extraHosts = "127.0.0.1 api.exchangerate.host";
services.nginx = {
enable = true;
virtualHosts."api.exchangerate.host" = {
addSSL = true;
# openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 1000000 -nodes -subj '/CN=api.exchangerate.host'
sslCertificate = ./server.crt;
sslCertificateKey = ./server.key;
locations."/".return = "200 '${builtins.readFile ./rates.json}'";
};
};
# ihatemoney needs a local smtp server otherwise project creation just crashes
services.opensmtpd = {
enable = true;
@ -30,11 +44,13 @@ let
testScript = ''
machine.wait_for_open_port(8000)
machine.wait_for_unit("uwsgi.service")
machine.wait_until_succeeds("curl http://localhost:8000")
machine.wait_until_succeeds("curl --fail https://api.exchangerate.host")
machine.wait_until_succeeds("curl --fail http://localhost:8000")
assert '"yay"' in machine.succeed(
"curl -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay@example.com'"
result = machine.succeed(
"curl --fail -X POST http://localhost:8000/api/projects -d 'name=yay&id=yay&password=yay&contact_email=yay@example.com&default_currency=XXX'"
)
assert '"yay"' in result, repr(result)
owner, timestamp = machine.succeed(
"stat --printf %U:%G___%Y /var/lib/ihatemoney/secret_key"
).split("___")
@ -47,13 +63,13 @@ let
machine.wait_for_unit("uwsgi.service")
with subtest("check that the database is really persistent"):
machine.succeed("curl --basic -u yay:yay http://localhost:8000/api/projects/yay")
machine.succeed("curl --fail --basic -u yay:yay http://localhost:8000/api/projects/yay")
with subtest("check that the secret key is really persistent"):
timestamp2 = machine.succeed("stat --printf %Y /var/lib/ihatemoney/secret_key")
assert timestamp == timestamp2
assert "ihatemoney" in machine.succeed("curl http://localhost:8000")
assert "ihatemoney" in machine.succeed("curl --fail http://localhost:8000")
'';
};
in {

View file

@ -0,0 +1,39 @@
{
"rates": {
"CAD": 1.3420055134,
"HKD": 7.7513783598,
"ISK": 135.9407305307,
"PHP": 49.3762922123,
"DKK": 6.4126464507,
"HUF": 298.9145416954,
"CZK": 22.6292212267,
"GBP": 0.7838128877,
"RON": 4.1630771881,
"SEK": 8.8464851826,
"IDR": 14629.5658166782,
"INR": 74.8328738801,
"BRL": 5.2357856651,
"RUB": 71.8416609235,
"HRK": 6.4757064094,
"JPY": 106.2715368711,
"THB": 31.7203652653,
"CHF": 0.9243625086,
"EUR": 0.8614748449,
"MYR": 4.2644727774,
"BGN": 1.6848725017,
"TRY": 6.8483804273,
"CNY": 7.0169710544,
"NOK": 9.213731909,
"NZD": 1.5080978635,
"ZAR": 16.7427636113,
"USD": 1,
"MXN": 22.4676085458,
"SGD": 1.3855099931,
"AUD": 1.4107512061,
"ILS": 3.4150585803,
"KRW": 1203.3339076499,
"PLN": 3.794452102
},
"base": "USD",
"date": "2020-07-24"
}

View file

@ -0,0 +1,28 @@
-----BEGIN CERTIFICATE-----
MIIEvjCCAqYCCQDkTQrENPCZjjANBgkqhkiG9w0BAQsFADAgMR4wHAYDVQQDDBVh
cGkuZXhjaGFuZ2VyYXRlLmhvc3QwIBcNMjEwNzE0MTI1MzQ0WhgPNDc1OTA2MTEx
MjUzNDRaMCAxHjAcBgNVBAMMFWFwaS5leGNoYW5nZXJhdGUuaG9zdDCCAiIwDQYJ
KoZIhvcNAQEBBQADggIPADCCAgoCggIBAL5zpwUYa/ySqvJ/PUnXYsl1ww5SNGJh
NujCRxC0Gw+5t5O7USSHRdz7Eb2PNFMa7JR+lliLAWdjHfqPXJWmP10X5ebvyxeQ
TJkR1HpDSY6TQQlJvwr/JNGryyoQYjXvnyeyVu4TS3U0TTI631OonDAj+HbFIs9L
gr/HfHzFmxRVLwaJ7hebanihc5RzoWTxgswiOwYQu5AivXQqcvUIxELeT7CxWwiw
be/SlalDgoezB/poqaa215FUuN2av+nTn+swH3WOi9kwePLgVKn9BnDMwyh8et13
y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TU
3hyX78yROMcZto0pVzxgQrYz31yQ5ocy9WcOYbPbQ5gdlnBEv8d7umNY1siz2wkI
NaEkKVO0D0jFtk37s/YqJpCsXg/B7yc=
-----END PRIVATE KEY-----

View file

@ -0,0 +1,36 @@
{ lib
, buildPythonPackage
, fetchPypi
, flask
, six
, pytestCheckHook
}:
buildPythonPackage rec {
pname = "flask-talisman";
version = "0.8.1";
src = fetchPypi {
inherit pname version;
sha256 = "11gjgqkpj2yqydb0pfhjyx56iy4l9szgz33vg5d7bw8vqp02wl2x";
};
buildInputs = [
flask
];
propagatedBuildInputs = [
six
];
nativeBuildInputs = [
pytestCheckHook
];
meta = with lib; {
description = "HTTP security headers for Flask";
homepage = "https://github.com/wntrblm/flask-talisman";
license = licenses.asl20;
maintainers = [ lib.maintainers.symphorien ];
};
}

View file

@ -1,14 +1,13 @@
{ buildPythonPackage
, lib
, fetchFromGitHub
, isPy27
, nixosTests
, fetchpatch
, fetchPypi
, alembic
, aniso8601
, Babel
, blinker
, cachetools
, click
, dnspython
, email_validator
@ -19,6 +18,7 @@
, flask_migrate
, flask-restful
, flask_sqlalchemy
, flask-talisman
, flask_wtf
, debts
, idna
@ -28,6 +28,7 @@
, markupsafe
, python-dateutil
, pytz
, requests
, six
, sqlalchemy
, sqlalchemy-utils
@ -43,17 +44,6 @@
# ihatemoney is not really a library. It will only ever be imported
# by the interpreter of uwsgi. So overrides for its depencies are fine.
let
# fixed in next release, but patches don't apply
# https://github.com/spiral-project/ihatemoney/issues/567
pinned_wtforms = wtforms.overridePythonAttrs (old: rec {
pname = "WTForms";
version = "2.2.1";
src = fetchPypi {
inherit pname version;
sha256 = "0q9vkcq6jnnn618h27lx9sas6s9qlg2mv8ja6dn0hy38gwzarnqc";
};
});
# sqlalchemy-continuum requires sqlalchemy < 1.4
pinned_sqlalchemy = sqlalchemy.overridePythonAttrs (
old: rec {
@ -70,43 +60,20 @@ in
buildPythonPackage rec {
pname = "ihatemoney";
version = "4.2";
version = "5.1.1";
src = fetchFromGitHub {
owner = "spiral-project";
repo = pname;
rev = version;
sha256 = "0d4vc6m0jkwlz9ly0hcjghccydvqbldh2jb8yzf94jrgkd5fd7k1";
src = fetchPypi {
inherit pname version;
sha256 = "0gsqba9qbs1dpmfys8qpiahy4pbn4khcc6mgmdnhssmkjsb94sx6";
};
disabled = isPy27;
patches = [
# fix migration on postgresql
# remove on next release
(fetchpatch {
url = "https://github.com/spiral-project/ihatemoney/commit/6129191b26784b895e203fa3eafb89cee7d88b71.patch";
sha256 = "0yc24gsih9x3pnh2mhj4v5i71x02dq93a9jd2r8b1limhcl4p1sw";
})
(fetchpatch {
name = "CVE-2020-15120.patch";
url = "https://github.com/spiral-project/ihatemoney/commit/8d77cf5d5646e1d2d8ded13f0660638f57e98471.patch";
sha256 = "0y855sk3qsbpq7slj876k2ifa1lccc2dccag98pkyaadpz5gbabv";
})
# backported from current master
# remove dependency on flask-script, which removed support on some features ihm used to need
./remove_flask_script.patch
];
postPatch = ''
# remove draconian pinning
sed -i 's/==.*$//' setup.cfg
'';
propagatedBuildInputs = [
aniso8601
Babel
blinker
cachetools
click
dnspython
email_validator
@ -125,7 +92,8 @@ buildPythonPackage rec {
}
)
flask-restful
(flask_wtf.override { wtforms = pinned_wtforms; })
flask-talisman
flask_wtf
idna
itsdangerous
jinja2
@ -133,6 +101,7 @@ buildPythonPackage rec {
markupsafe
python-dateutil
pytz
requests
six
(
(
@ -158,7 +127,7 @@ buildPythonPackage rec {
)
)
werkzeug
pinned_wtforms
wtforms
psycopg2
debts
];
@ -168,10 +137,10 @@ buildPythonPackage rec {
pytestCheckHook
];
pytestFlagsArray = [ "--pyargs ihatemoney.tests.tests" ];
disabledTests = [
"test_notifications" # requires running service.
"test_invite" # requires running service.
"test_invitation_email_failure" # requires dns resolution
];
passthru.tests = {

View file

@ -1,284 +0,0 @@
commit 4d831ba2316d54f4916fb9d1160ec7a3856b47d4
Author: Glandos <bugs-github@antipoul.fr>
Date: Sun Jun 6 14:30:52 2021 +0200
remove usage of Flask-Script
Use flask.cli instead with compatibility layer for existing commands,
such as "runserver".
cherry-pick from 74e222f1a1cbfc2fac102fefc1115e9d0a6586dc
diff --git a/Makefile b/Makefile
index a681709..90ab1bb 100644
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,7 @@ update: remove-install-stamp install ## Update the dependencies
.PHONY: serve
serve: install ## Run the ihatemoney server
@echo 'Running ihatemoney on http://localhost:5000'
- $(PYTHON) -m ihatemoney.manage runserver
+ $(PYTHON) -m ihatemoney.manage run
.PHONY: test
test: install-dev ## Run the tests
diff --git a/docs/installation.rst b/docs/installation.rst
index 4994499..4df70a2 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -59,7 +59,7 @@ Test it
Once installed, you can start a test server::
- ihatemoney runserver
+ ihatemoney run
And point your browser at `http://localhost:5000 <http://localhost:5000>`_.
diff --git a/ihatemoney/manage.py b/ihatemoney/manage.py
index a192844..805a07f 100755
--- a/ihatemoney/manage.py
+++ b/ihatemoney/manage.py
@@ -5,8 +5,8 @@ import os
import random
import sys
-from flask_migrate import Migrate, MigrateCommand
-from flask_script import Command, Manager, Option
+import click
+from flask.cli import FlaskGroup
from werkzeug.security import generate_password_hash
from ihatemoney.models import Project, db
@@ -14,31 +14,48 @@ from ihatemoney.run import create_app
from ihatemoney.utils import create_jinja_env
-class GeneratePasswordHash(Command):
+@click.group(cls=FlaskGroup, create_app=create_app)
+def cli():
+ """IHateMoney Management script"""
- """Get password from user and hash it without printing it in clear text."""
- def run(self):
- password = getpass.getpass(prompt="Password: ")
- print(generate_password_hash(password))
-
-
-class GenerateConfig(Command):
- def get_options(self):
- return [
- Option(
- "config_file",
- choices=[
- "ihatemoney.cfg",
- "apache-vhost.conf",
- "gunicorn.conf.py",
- "supervisord.conf",
- "nginx.conf",
- ],
- )
+@cli.command(
+ context_settings={"ignore_unknown_options": True, "allow_extra_args": True}
+)
+@click.pass_context
+def runserver(ctx):
+ """Deprecated, use the "run" command instead"""
+ click.secho(
+ '"runserver" is deprecated, please use the standard "run" flask command',
+ fg="red",
+ )
+ run = cli.get_command(ctx, "run")
+ ctx.forward(run)
+
+
+@click.command(name="generate_password_hash")
+def password_hash():
+ """Get password from user and hash it without printing it in clear text."""
+ password = getpass.getpass(prompt="Password: ")
+ print(generate_password_hash(password))
+
+
+@click.command()
+@click.argument(
+ "config_file",
+ type=click.Choice(
+ [
+ "ihatemoney.cfg",
+ "apache-vhost.conf",
+ "gunicorn.conf.py",
+ "supervisord.conf",
+ "nginx.conf",
]
+ ),
+)
+def generate_config(config_file):
+ """Generate front-end server configuration"""
- @staticmethod
def gen_secret_key():
return "".join(
[
@@ -49,59 +66,33 @@ class GenerateConfig(Command):
]
)
- def run(self, config_file):
- env = create_jinja_env("conf-templates", strict_rendering=True)
- template = env.get_template("%s.j2" % config_file)
+ env = create_jinja_env("conf-templates", strict_rendering=True)
+ template = env.get_template(f"{config_file}.j2")
- bin_path = os.path.dirname(sys.executable)
- pkg_path = os.path.abspath(os.path.dirname(__file__))
+ bin_path = os.path.dirname(sys.executable)
+ pkg_path = os.path.abspath(os.path.dirname(__file__))
- print(
- template.render(
- pkg_path=pkg_path,
- bin_path=bin_path,
- sys_prefix=sys.prefix,
- secret_key=self.gen_secret_key(),
- )
+ print(
+ template.render(
+ pkg_path=pkg_path,
+ bin_path=bin_path,
+ sys_prefix=sys.prefix,
+ secret_key=gen_secret_key(),
)
-
-
-class DeleteProject(Command):
- def run(self, project_name):
- demo_project = Project.query.get(project_name)
- db.session.delete(demo_project)
+ )
+
+
+@cli.command()
+@click.argument("project_name")
+def delete_project(project_name):
+ """Delete a project"""
+ project = Project.query.get(project_name)
+ if project is None:
+ click.secho(f'Project "{project_name}" not found', fg="red")
+ else:
+ db.session.delete(project)
db.session.commit()
-def main():
- QUIET_COMMANDS = ("generate_password_hash", "generate-config")
-
- exception = None
- backup_stderr = sys.stderr
- # Hack to divert stderr for commands generating content to stdout
- # to avoid confusing the user
- if len(sys.argv) > 1 and sys.argv[1] in QUIET_COMMANDS:
- sys.stderr = open(os.devnull, "w")
-
- try:
- app = create_app()
- Migrate(app, db)
- except Exception as e:
- exception = e
-
- # Restore stderr
- sys.stderr = backup_stderr
-
- if exception:
- raise exception
-
- manager = Manager(app)
- manager.add_command("db", MigrateCommand)
- manager.add_command("generate_password_hash", GeneratePasswordHash)
- manager.add_command("generate-config", GenerateConfig)
- manager.add_command("delete-project", DeleteProject)
- manager.run()
-
-
if __name__ == "__main__":
- main()
+ cli()
diff --git a/ihatemoney/tests/tests.py b/ihatemoney/tests/tests.py
index b27fafc..23f19a6 100644
--- a/ihatemoney/tests/tests.py
+++ b/ihatemoney/tests/tests.py
@@ -15,7 +15,7 @@ from sqlalchemy import orm
from werkzeug.security import check_password_hash, generate_password_hash
from ihatemoney import history, models, utils
-from ihatemoney.manage import DeleteProject, GenerateConfig, GeneratePasswordHash
+from ihatemoney.manage import delete_project, generate_config, password_hash
from ihatemoney.run import create_app, db, load_configuration
from ihatemoney.versioning import LoggingMode
@@ -2157,28 +2157,24 @@ class CommandTestCase(BaseTestCase):
- raise no exception
- produce something non-empty
"""
- cmd = GenerateConfig()
- for config_file in cmd.get_options()[0].kwargs["choices"]:
- with patch("sys.stdout", new=io.StringIO()) as stdout:
- cmd.run(config_file)
- print(stdout.getvalue())
- self.assertNotEqual(len(stdout.getvalue().strip()), 0)
+ runner = self.app.test_cli_runner()
+ for config_file in generate_config.params[0].type.choices:
+ result = runner.invoke(generate_config, config_file)
+ self.assertNotEqual(len(result.output.strip()), 0)
def test_generate_password_hash(self):
- cmd = GeneratePasswordHash()
- with patch("sys.stdout", new=io.StringIO()) as stdout, patch(
- "getpass.getpass", new=lambda prompt: "secret"
- ): # NOQA
- cmd.run()
- print(stdout.getvalue())
- self.assertEqual(len(stdout.getvalue().strip()), 189)
+ runner = self.app.test_cli_runner()
+ with patch("getpass.getpass", new=lambda prompt: "secret"):
+ result = runner.invoke(password_hash)
+ print(result.output.strip())
+ self.assertEqual(len(result.output.strip()), 102)
def test_demo_project_deletion(self):
self.create_project("demo")
self.assertEquals(models.Project.query.get("demo").name, "demo")
- cmd = DeleteProject()
- cmd.run("demo")
+ runner = self.app.test_cli_runner()
+ runner.invoke(delete_project, "demo")
self.assertEqual(len(models.Project.query.all()), 0)
diff --git a/setup.cfg b/setup.cfg
index d493717..48e447c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -31,7 +31,6 @@ install_requires =
Flask-Mail==0.9.1
Flask-Migrate==2.5.3
Flask-RESTful==0.3.8
- Flask-Script==2.0.6
Flask-SQLAlchemy==2.4.1
Flask-WTF==0.14.3
WTForms==2.2.1
@@ -51,8 +50,12 @@ dev =
zest.releaser==6.20.1
[options.entry_points]
+flask.commands =
+ generate_password_hash = ihatemoney.manage:password_hash
+ generate-config = ihatemoney.manage:generate_config
+
console_scripts =
- ihatemoney = ihatemoney.manage:main
+ ihatemoney = ihatemoney.manage:cli
paste.app_factory =
main = ihatemoney.run:main

View file

@ -2791,6 +2791,8 @@ in {
flask-swagger-ui = callPackage ../development/python-modules/flask-swagger-ui { };
flask-talisman = callPackage ../development/python-modules/flask-talisman { };
flask_testing = callPackage ../development/python-modules/flask-testing { };
flask-versioned = callPackage ../development/python-modules/flask-versioned { };