Adding pytest config / env and basic auth
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
def is_authenticated(username, password):
|
||||
logging.debug(f"Authentication attempt for {username}, {password}")
|
||||
return (username == os.environ.get('USERNAME') and password == os.environ.get('PASSWORD'))
|
||||
@@ -0,0 +1,6 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def valid_credentials():
|
||||
return (os.environ.get('USERNAME'), os.environ.get('PASSWORD'))
|
||||
+8
-1
@@ -1,4 +1,5 @@
|
||||
from bottle import Bottle
|
||||
from bottle import Bottle, auth_basic
|
||||
from groove.auth import is_authenticated
|
||||
|
||||
server = Bottle()
|
||||
|
||||
@@ -6,3 +7,9 @@ server = Bottle()
|
||||
@server.route('/')
|
||||
def index():
|
||||
return "Groovy."
|
||||
|
||||
|
||||
@server.route('/admin')
|
||||
@auth_basic(is_authenticated)
|
||||
def admin():
|
||||
return "Authenticated. Groovy."
|
||||
|
||||
Reference in New Issue
Block a user