diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..62b63ea --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,35 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + + runs-on: ubuntu-latest + + steps: + - name: Install ldap dependencies + run: sudo apt-get install libldap2-dev libsasl2-dev + - uses: actions/checkout@v2 + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: 3.6 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with black + run: | + # stop the build if there are Python syntax errors or undefined names + black --check selfservice + - name: Lint with pylint + run: | + pylint selfservice diff --git a/.pylintrc b/.pylintrc index 3f24ebd..e8fdc7e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -67,6 +67,7 @@ disable= inconsistent-return-statements, no-name-in-module, cyclic-import, + unnecessary-pass, [REPORTS] diff --git a/selfservice/__init__.py b/selfservice/__init__.py index c79dfb1..a6517d2 100644 --- a/selfservice/__init__.py +++ b/selfservice/__init__.py @@ -101,7 +101,10 @@ @app.errorhandler(500) def app_error(e): - return render_template("error.html"), 500 + """ + Renders an error page. + """ + return render_template("error.html", e=e), 500 @app.route("/") diff --git a/selfservice/blueprints/otp.py b/selfservice/blueprints/otp.py index 9d51ec3..d17ce04 100644 --- a/selfservice/blueprints/otp.py +++ b/selfservice/blueprints/otp.py @@ -2,11 +2,13 @@ Flask blueprint for handling creating and removing OTP secrets from accounts. """ +import logging +import pyotp + from flask import Blueprint, render_template, request, redirect, flash from flask import session as flask_session import dill as pickle -import pyotp -import logging + from selfservice.utilities.keycloak import ( OTPConfigError, @@ -63,7 +65,7 @@ def enable(): if not secret or not otp_session: flash("Invalid secret provided. Please try again.") return redirect("/otp") - elif not otp_code: + if not otp_code: flash("No one time password provided. Please scan the code and try again.") return redirect("/otp".format(secret)) diff --git a/selfservice/blueprints/recovery.py b/selfservice/blueprints/recovery.py index d3b326e..903f334 100644 --- a/selfservice/blueprints/recovery.py +++ b/selfservice/blueprints/recovery.py @@ -75,9 +75,8 @@ def create_session(): # Redirect the user to thier session. return redirect("/recovery/" + session_id) - else: - flash("Please complete the reCaptcha.") - return redirect("/recovery") + flash("Please complete the reCaptcha.") + return redirect("/recovery") @recovery_bp.route("/recovery/") @@ -197,9 +196,8 @@ def verify_phone(recovery_id): if not token: token = generate_token(session) return redirect("/reset?token=" + token) - else: - flash("Your verification code did not match, sorry!") - return redirect("/recovery") + flash("Your verification code did not match, sorry!") + return redirect("/recovery") @recovery_bp.route("/reset", methods=["GET", "POST"]) diff --git a/selfservice/utilities/app_passwd.py b/selfservice/utilities/app_passwd.py index a31d86c..d5c865f 100644 --- a/selfservice/utilities/app_passwd.py +++ b/selfservice/utilities/app_passwd.py @@ -56,5 +56,11 @@ def set_app_passwd(username): def delete_app_passwd(username): + """ + Deletes an existing App Specific Password + + Keyword arguments: + username -- User who's app password will be deleted + """ AppSpecificPassword.query.filter_by(user=username).delete() db.session.commit() diff --git a/selfservice/utilities/reset.py b/selfservice/utilities/reset.py index 789008c..e9f8657 100644 --- a/selfservice/utilities/reset.py +++ b/selfservice/utilities/reset.py @@ -93,8 +93,7 @@ def valid_token(token_id): if is_expired(token_data.created, 30): return False return True - else: - return False + return False def passwd_reset(username, password):