def setUp(self): app = Flask(__name__) app.config['SECRET_KEY'] = 'my secret' basic_auth = HTTPBasicAuth() basic_auth_my_realm = HTTPBasicAuth() basic_auth_my_realm.realm = "My Realm" basic_custom_auth = HTTPBasicAuth() digest_auth = HTTPDigestAuth() digest_auth_my_realm = HTTPDigestAuth() digest_auth_my_realm.realm = "My Realm" @basic_auth.get_password def get_basic_password(username): if username == "john": return "hello" elif username == "susan": return "bye" else: return "other" @basic_auth_my_realm.get_password def get_basic_password(username): if username == "john": return "hello" elif username == "susan": return "bye" else: return "other" @basic_auth_my_realm.error_handler def basic_auth_my_realm_error(): return "custom error" @basic_custom_auth.get_password def get_basic_custom_auth_get_password(username): if username == "john": return md5("hello").hexdigest() elif username == "susan": return md5("bye").hexdigest() else: return "other" @basic_custom_auth.hash_password def custom_authenticate(password): return md5(password).hexdigest() @digest_auth.get_password def get_digest_password(username): if username == "susan": return "hello" elif username == "john": return "bye" else: return "other" @digest_auth_my_realm.get_password def get_digest_password(username): if username == "susan": return "hello" elif username == "john": return "bye" else: return "other" @app.route('/') def index(): return "index" @app.route('/basic') @basic_auth.login_required def basic_auth_route(): return "basic_auth" @app.route('/basic-with-realm') @basic_auth_my_realm.login_required def basic_auth_my_realm_route(): return "basic_auth_my_realm" @app.route('/basic-custom') @basic_custom_auth.login_required def basic_custom_auth_route(): return "basic_custom_auth" @app.route('/digest') @digest_auth.login_required def digest_auth_route(): return "digest_auth" @app.route('/digest-with-realm') @digest_auth_my_realm.login_required def digest_auth_my_realm_route(): return "digest_auth_my_realm" self.app = app self.basic_auth = basic_auth self.basic_auth_my_realm = basic_auth_my_realm self.basic_custom_auth = basic_custom_auth self.digest_auth = digest_auth self.client = app.test_client()
def setUp(self): app = Flask(__name__) app.config['SECRET_KEY'] = 'my secret' basic_auth = HTTPBasicAuth() basic_auth_my_realm = HTTPBasicAuth() basic_auth_my_realm.realm = 'My Realm' basic_custom_auth = HTTPBasicAuth() basic_verify_auth = HTTPBasicAuth() digest_auth = HTTPDigestAuth() digest_auth_my_realm = HTTPDigestAuth() digest_auth_my_realm.realm = 'My Realm' @basic_auth.get_password def get_basic_password(username): if username == 'john': return 'hello' elif username == 'susan': return 'bye' else: return None @basic_auth_my_realm.get_password def get_basic_password_2(username): if username == 'john': return 'johnhello' elif username == 'susan': return 'susanbye' else: return None @basic_auth_my_realm.hash_password def basic_auth_my_realm_hash_password(username, password): return username + password @basic_auth_my_realm.error_handler def basic_auth_my_realm_error(): return 'custom error' @basic_custom_auth.get_password def get_basic_custom_auth_get_password(username): if username == 'john': return md5('hello').hexdigest() elif username == 'susan': return md5('bye').hexdigest() else: return None @basic_custom_auth.hash_password def basic_custom_auth_hash_password(password): return md5(password).hexdigest() @basic_verify_auth.verify_password def basic_verify_auth_verify_password(username, password): if username == 'john': return password == 'hello' elif username == 'susan': return password == 'bye' return False @digest_auth.get_password def get_digest_password(username): if username == 'susan': return 'hello' elif username == 'john': return 'bye' else: return None @digest_auth_my_realm.get_password def get_digest_password_2(username): if username == 'susan': return 'hello' elif username == 'john': return 'bye' else: return None @app.route('/') def index(): return 'index' @app.route('/basic') @basic_auth.login_required def basic_auth_route(): return 'basic_auth:' + basic_auth.username() @app.route('/basic-with-realm') @basic_auth_my_realm.login_required def basic_auth_my_realm_route(): return 'basic_auth_my_realm:' + basic_auth_my_realm.username() @app.route('/basic-custom') @basic_custom_auth.login_required def basic_custom_auth_route(): return 'basic_custom_auth:' + basic_custom_auth.username() @app.route('/basic-verify') @basic_verify_auth.login_required def basic_verify_auth_route(): return 'basic_verify_auth:' + basic_verify_auth.username() @app.route('/digest') @digest_auth.login_required def digest_auth_route(): return 'digest_auth:' + digest_auth.username() @app.route('/digest-with-realm') @digest_auth_my_realm.login_required def digest_auth_my_realm_route(): return 'digest_auth_my_realm:' + digest_auth_my_realm.username() self.app = app self.basic_auth = basic_auth self.basic_auth_my_realm = basic_auth_my_realm self.basic_custom_auth = basic_custom_auth self.basic_verify_auth = basic_verify_auth self.digest_auth = digest_auth self.client = app.test_client()
def setUp(self): app = Flask(__name__) app.config["SECRET_KEY"] = "my secret" basic_auth = HTTPBasicAuth() basic_auth_my_realm = HTTPBasicAuth() basic_auth_my_realm.realm = "My Realm" basic_custom_auth = HTTPBasicAuth() basic_verify_auth = HTTPBasicAuth() digest_auth = HTTPDigestAuth() digest_auth_my_realm = HTTPDigestAuth() digest_auth_my_realm.realm = "My Realm" @basic_auth.get_password def get_basic_password(username): if username == "john": return "hello" elif username == "susan": return "bye" else: return "other" @basic_auth_my_realm.get_password def get_basic_password(username): if username == "john": return "johnhello" elif username == "susan": return "susanbye" else: return "other" @basic_auth_my_realm.hash_password def basic_auth_my_realm_hash_password(username, password): return username + password @basic_auth_my_realm.error_handler def basic_auth_my_realm_error(): return "custom error" @basic_custom_auth.get_password def get_basic_custom_auth_get_password(username): if username == "john": return md5("hello").hexdigest() elif username == "susan": return md5("bye").hexdigest() else: return "other" @basic_custom_auth.hash_password def basic_custom_auth_hash_password(password): return md5(password).hexdigest() @basic_verify_auth.verify_password def basic_verify_auth_verify_password(username, password): if username == "john": return password == "hello" elif username == "susan": return password == "bye" return False @digest_auth.get_password def get_digest_password(username): if username == "susan": return "hello" elif username == "john": return "bye" else: return "other" @digest_auth_my_realm.get_password def get_digest_password(username): if username == "susan": return "hello" elif username == "john": return "bye" else: return "other" @app.route("/") def index(): return "index" @app.route("/basic") @basic_auth.login_required def basic_auth_route(): return "basic_auth:" + basic_auth.username() @app.route("/basic-with-realm") @basic_auth_my_realm.login_required def basic_auth_my_realm_route(): return "basic_auth_my_realm:" + basic_auth_my_realm.username() @app.route("/basic-custom") @basic_custom_auth.login_required def basic_custom_auth_route(): return "basic_custom_auth:" + basic_custom_auth.username() @app.route("/basic-verify") @basic_verify_auth.login_required def basic_verify_auth_route(): return "basic_verify_auth:" + basic_verify_auth.username() @app.route("/digest") @digest_auth.login_required def digest_auth_route(): return "digest_auth:" + digest_auth.username() @app.route("/digest-with-realm") @digest_auth_my_realm.login_required def digest_auth_my_realm_route(): return "digest_auth_my_realm:" + digest_auth_my_realm.username() self.app = app self.basic_auth = basic_auth self.basic_auth_my_realm = basic_auth_my_realm self.basic_custom_auth = basic_custom_auth self.basic_verify_auth = basic_verify_auth self.digest_auth = digest_auth self.client = app.test_client()