# Path: oslo_middleware/basic_auth.py
# LOG = logging.getLogger(__name__)
# OPTS = [
#     cfg.StrOpt('http_basic_auth_user_file',
#                default='/etc/htpasswd',
#                help="HTTP basic auth password file.")
# ]
# class ConfigInvalid(Exception):
# class BasicAuthMiddleware(base.ConfigurableMiddleware):
#     def __init__(self, error_msg):
#     def __init__(self, application, conf=None):
#     def format_exception(self, e):
#     def __call__(self, req):
# def authenticate(auth_file, username, password):
# def auth_entry(entry, password):
# def validate_auth_file(auth_file):
# def parse_entry(entry):
# def parse_token(token):
# def parse_header(env):


import base64
import os
import tempfile
import webob
from oslo_config import cfg
from oslo_middleware import basic_auth as auth
from oslotest import base as test_base
        entry_fail = 'foo:bar'
        # success
        self.assertEqual(
            {'HTTP_X_USER': 'myName', 'HTTP_X_USER_NAME': 'myName'},
            auth.auth_entry(entry_pass, b'myPassword')
        )
        # failed, unknown digest format
        ex = self.assertRaises(webob.exc.HTTPBadRequest,
                               auth.auth_entry, entry_fail, b'bar')
        self.assertEqual('Only bcrypt digested '
                         'passwords are supported for foo', str(ex))
        # failed, incorrect password
        self.assertRaises(webob.exc.HTTPUnauthorized,
                          auth.auth_entry, entry_pass, b'bar')

    def test_validate_auth_file(self):
        auth_file = self.write_auth_file(
            'myName:$2y$05$lE3eGtyj41jZwrzS87KTqe6.'
            'JETVCWBkc32C63UP2aYrGoYOEpbJm\n\n\n')
        # success, valid config
        auth.validate_auth_file(auth_file)
        # failed, missing auth file
        auth_file = auth_file + '.missing'
        self.assertRaises(auth.ConfigInvalid,
                          auth.validate_auth_file, auth_file)
        # failed, invalid entry
        auth_file = self.write_auth_file(
            'foo:bar\nmyName:$2y$05$lE3eGtyj41jZwrzS87KTqe6.'
            'JETVCWBkc32C63UP2aYrGoYOEpbJm\n\n\n')
        self.assertRaises(webob.exc.HTTPBadRequest,

# Path: oslo_middleware/basic_auth.py
# LOG = logging.getLogger(__name__)
# OPTS = [
#     cfg.StrOpt('http_basic_auth_user_file',
#                default='/etc/htpasswd',
#                help="HTTP basic auth password file.")
# ]
# class ConfigInvalid(Exception):
# class BasicAuthMiddleware(base.ConfigurableMiddleware):
#     def __init__(self, error_msg):
#     def __init__(self, application, conf=None):
#     def format_exception(self, e):
#     def __call__(self, req):
# def authenticate(auth_file, username, password):
# def auth_entry(entry, password):
# def validate_auth_file(auth_file):
# def parse_entry(entry):
# def parse_token(token):
# def parse_header(env):


# Path: oslo_middleware/tests/test_auth_basic.py
import base64
import os
import tempfile
import webob
from oslo_config import cfg
from oslo_middleware import basic_auth as auth
from oslotest import base as test_base

        entry_fail = 'foo:bar'
        # success
        self.assertEqual(
            {'HTTP_X_USER': 'myName', 'HTTP_X_USER_NAME': 'myName'},
            auth.auth_entry(entry_pass, b'myPassword')
        )
        # failed, unknown digest format
        ex = self.assertRaises(webob.exc.HTTPBadRequest,
                               auth.auth_entry, entry_fail, b'bar')
        self.assertEqual('Only bcrypt digested '
                         'passwords are supported for foo', str(ex))
        # failed, incorrect password
        self.assertRaises(webob.exc.HTTPUnauthorized,
                          auth.auth_entry, entry_pass, b'bar')

    def test_validate_auth_file(self):
        auth_file = self.write_auth_file(
            'myName:$2y$05$lE3eGtyj41jZwrzS87KTqe6.'
            'JETVCWBkc32C63UP2aYrGoYOEpbJm\n\n\n')
        # success, valid config
        auth.validate_auth_file(auth_file)
        # failed, missing auth file
        auth_file = auth_file + '.missing'
        self.assertRaises(auth.ConfigInvalid,
                          auth.validate_auth_file, auth_file)
        # failed, invalid entry
        auth_file = self.write_auth_file(
            'foo:bar\nmyName:$2y$05$lE3eGtyj41jZwrzS87KTqe6.'
            'JETVCWBkc32C63UP2aYrGoYOEpbJm\n\n\n')
        self.assertRaises(webob.exc.HTTPBadRequest,

                          auth.validate_auth_file, auth_file)