コード例 #1
0
def setup_sqlite3_auth_tables(username, password):
    """Setup the SQLite3 auth database."""
    auth_driver = SQLAlchemyAuthDriver('sqlite:///auth.sq3')
    try:
        auth_driver.add(username, password)
    except Exception as error:
        print('Unable to create auth tables')
        print(error)
コード例 #2
0
def test_driver_auth_accepts_good_creds():
    '''
    Tests driver accepts good creds.
    '''
    driver = SQLAlchemyAuthDriver('sqlite:///auth.sq3')

    with sqlite3.connect('auth.sq3') as conn:

        conn.execute(
            '''
            INSERT INTO auth_record VALUES (?,?)
        ''', (USERNAME, DIGESTED))

    driver.auth(USERNAME, PASSWORD)
コード例 #3
0
def test_driver_auth_accepts_good_creds():
    """
    Tests driver accepts good creds.
    """
    driver = SQLAlchemyAuthDriver("sqlite:///auth.sq3")

    with sqlite3.connect("auth.sq3") as conn:

        conn.execute(
            """
            INSERT INTO auth_record VALUES (?,?)
        """,
            (USERNAME, DIGESTED),
        )

    driver.auth(USERNAME, PASSWORD)
コード例 #4
0
def test_driver_auth_returns_user_context():
    '''
    Tests driver accepts good creds.
    '''
    driver = SQLAlchemyAuthDriver('sqlite:///auth.sq3')

    with sqlite3.connect('auth.sq3') as conn:

        conn.execute(
            '''
            INSERT INTO auth_record VALUES (?,?)
        ''', (USERNAME, DIGESTED))

    user = driver.auth(USERNAME, PASSWORD)

    assert user is not None, 'user context was None'
コード例 #5
0
def test_driver_auth_returns_user_context():
    """
    Tests driver accepts good creds.
    """
    driver = SQLAlchemyAuthDriver("sqlite:///auth.sq3")

    with sqlite3.connect("auth.sq3") as conn:

        conn.execute(
            """
            INSERT INTO auth_record VALUES (?,?)
        """,
            (USERNAME, DIGESTED),
        )

    user = driver.auth(USERNAME, PASSWORD)

    assert user is not None, "user context was None"
コード例 #6
0
def test_driver_init_does_not_create_records():
    """
    Tests for creation of records after driver init.
    Tests driver init does not have unexpected side-effects.
    """
    driver = SQLAlchemyAuthDriver("sqlite:///auth.sq3")  # pylint: disable=unused-variable

    with sqlite3.connect("auth.sq3") as conn:

        count = conn.execute("""
            SELECT COUNT(*) FROM auth_record
        """).fetchone()[0]

        assert count == 0, "driver created records upon initilization"
コード例 #7
0
def test_driver_init_does_not_create_records():
    '''
    Tests for creation of records after driver init.
    Tests driver init does not have unexpected side-effects.
    '''
    driver = SQLAlchemyAuthDriver('sqlite:///auth.sq3')

    with sqlite3.connect('auth.sq3') as conn:

        count = conn.execute('''
            SELECT COUNT(*) FROM auth_record
        ''').fetchone()[0]

        assert count == 0, 'driver created records upon initilization'
コード例 #8
0
def test_driver_auth_rejects_bad_creds():
    '''
    Test driver rejects bad creds.
    '''
    driver = SQLAlchemyAuthDriver('sqlite:///auth.sq3')

    with sqlite3.connect('auth.sq3') as conn:

        conn.execute(
            '''
            INSERT INTO auth_record VALUES (?, ?)
        ''', (USERNAME, DIGESTED))

    with pytest.raises(AuthError):
        driver.auth(USERNAME, 'invalid_' + PASSWORD)

    with pytest.raises(AuthError):
        driver.auth('invalid_' + USERNAME, PASSWORD)
コード例 #9
0
def test_driver_auth_rejects_bad_creds():
    """
    Test driver rejects bad creds.
    """
    driver = SQLAlchemyAuthDriver("sqlite:///auth.sq3")

    with sqlite3.connect("auth.sq3") as conn:

        conn.execute(
            """
            INSERT INTO auth_record VALUES (?, ?)
        """,
            (USERNAME, DIGESTED),
        )

    with pytest.raises(AuthError):
        driver.auth(USERNAME, "invalid_" + PASSWORD)

    with pytest.raises(AuthError):
        driver.auth("invalid_" + USERNAME, PASSWORD)
コード例 #10
0
            db=db,
        ),
        index_config=index_config,
    ),
}

CONFIG["ALIAS"] = {
    "driver":
    SQLAlchemyAliasDriver(
        "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
            usr=usr,
            psw=psw,
            pghost=pghost,
            pgport=pgport,
            db=db,
        )),
}

AUTH = SQLAlchemyAuthDriver(
    "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
        usr=usr,
        psw=psw,
        pghost=pghost,
        pgport=pgport,
        db=db,
    ),
    arborist="http://localhost/",
)

settings = {"config": CONFIG, "auth": AUTH}
コード例 #11
0
CONFIG["INDEX"] = {
    "driver":
    SQLAlchemyIndexDriver(
        "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
            usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db),
        index_config=index_config,
    )
}

CONFIG["ALIAS"] = {
    "driver":
    SQLAlchemyAliasDriver(
        "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
            usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db))
}

if arborist:
    AUTH = SQLAlchemyAuthDriver(
        "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
            usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db),
        arborist=
        "http://arborist-service/",  # uncomment if you're using arborist
    )
else:
    AUTH = SQLAlchemyAuthDriver(
        "postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}".format(
            usr=usr, psw=psw, pghost=pghost, pgport=pgport, db=db))

settings = {"config": CONFIG, "auth": AUTH}
コード例 #12
0
            pgport=pgport,
            db=db,
        ),
        index_config=index_config),
}

CONFIG['ALIAS'] = {
    'driver':
    SQLAlchemyAliasDriver(
        'postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}'.format(
            usr=usr,
            psw=psw,
            pghost=pghost,
            pgport=pgport,
            db=db,
        )),
}

AUTH = SQLAlchemyAuthDriver(
    'postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}'.format(
        usr=usr,
        psw=psw,
        pghost=pghost,
        pgport=pgport,
        db=db,
    ),
    arborist="http://arborist-service/",
)

settings = {'config': CONFIG, 'auth': AUTH}
コード例 #13
0
            psw=psw,
            pghost=pghost,
            pgport=pgport,
            db=db,
        ),
        index_config=index_config),
}

CONFIG['ALIAS'] = {
    'driver':
    SQLAlchemyAliasDriver(
        'postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}'.format(
            usr=usr,
            psw=psw,
            pghost=pghost,
            pgport=pgport,
            db=db,
        )),
}

AUTH = SQLAlchemyAuthDriver(
    'postgresql+psycopg2://{usr}:{psw}@{pghost}:{pgport}/{db}'.format(
        usr=usr,
        psw=psw,
        pghost=pghost,
        pgport=pgport,
        db=db,
    ))

settings = {'config': CONFIG, 'auth': AUTH}
コード例 #14
0
import sqlite3
import hashlib

import pytest

import tests.util as util

from indexd.errors import AuthError

from indexd.auth.drivers.alchemy import SQLAlchemyAuthDriver

USERNAME = "******"
PASSWORD = "******"
DIGESTED = SQLAlchemyAuthDriver.digest(PASSWORD)

# TODO check if pytest has utilities for meta-programming of tests


@util.removes("auth.sq3")
def test_driver_init_does_not_create_records():
    """
    Tests for creation of records after driver init.
    Tests driver init does not have unexpected side-effects.
    """
    driver = SQLAlchemyAuthDriver("sqlite:///auth.sq3")  # pylint: disable=unused-variable

    with sqlite3.connect("auth.sq3") as conn:

        count = conn.execute("""
            SELECT COUNT(*) FROM auth_record
        """).fetchone()[0]