Esempio n. 1
0
def test_oauth_conversion_setup(auth_fc, monkeypatch):
    """Prepares data for auth conversion

    You need to run this as a test (no other cases), and then:
        rm -rf email_data
        mv email_work email_data

    Also grab the cookie output, and add it to test_oauth_conversion
    """
    fc = auth_fc

    from pykern import pkcollections
    from pykern.pkdebug import pkdlog
    from pykern.pkunit import pkok, pkre, pkeq
    from sirepo.auth import github
    from sirepo import github_srunit

    oc = github_srunit.MockOAuthClient(monkeypatch, 'emailer')
    fc.sr_get('authGithubLogin', {'simulation_type': fc.sr_sim_type}, redirect=False)
    t = fc.sr_auth_state(userName=None, isLoggedIn=False, method=None)
    state = oc.values.state
    r = fc.sr_get('authGithubAuthorized', query={'state': state})
    uid = fc.sr_auth_state(
        displayName=None,
        method='github',
        needCompleteRegistration=True,
        userName='******',
    ).uid
    fc.sr_get('authLogout', {'simulation_type': fc.sr_sim_type})
Esempio n. 2
0
def _fc(monkeypatch, user_name):
    from sirepo import srunit
    sim_type = 'myapp'
    fc = srunit.flask_client({
        'SIREPO_AUTH_METHODS': 'guest:github',
        'SIREPO_FEATURE_CONFIG_SIM_TYPES': sim_type,
        'SIREPO_AUTH_GITHUB_CALLBACK_URI': '/uri',
        'SIREPO_AUTH_GITHUB_KEY': 'key',
        'SIREPO_AUTH_GITHUB_SECRET': 'secret',
    })
    from sirepo import github_srunit
    from sirepo.auth import github

    fc.cookie_jar.clear()
    oc = github_srunit.MockOAuthClient(monkeypatch, user_name=user_name)
    return fc, sim_type, oc
Esempio n. 3
0
def test_oauth_conversion(monkeypatch):
    """See `x_test_oauth_conversion_setup`"""
    fc, sim_type = _fc()

    from pykern import pkcollections
    from pykern.pkdebug import pkdp
    from pykern.pkunit import pkok, pkre, pkeq
    from pykern import pkunit
    from pykern import pkio
    from sirepo.auth import github
    from sirepo import github_srunit
    from sirepo import server
    import re
    import shutil

    pkio.unchecked_remove(server._app.sirepo_db_dir)
    pkunit.data_dir().join('db').copy(server._app.sirepo_db_dir)
    fc.cookie_jar.clear()
    fc.set_cookie(
        'localhost', 'sirepo_dev',
        'Z0FBQUFBQmN2bGQzaGc1MmpCRkxIOWNpWi1yd1JReXUxZG5FV2VqMjFwU2w2cmdOSXhlaWVkOC1VUzVkLVR5NzdiS080R3p1aGUwUEFfdmpmdDcxTmJlOUR2eXpJY2l1YUVWaUVVa3dCYXpnZGIwTV9fei1iTWNCdkp0eXJVY0Ffenc2SVoxSUlLYVM='
    )
    oc = github_srunit.MockOAuthClient(monkeypatch, 'emailer')
    uid = fc.sr_auth_state(isLoggedIn=False, method='github').uid
    r = fc.sr_post('listSimulations', {'simulationType': sim_type})
    pkeq('loginWith', r.srException.routeName)
    pkeq('github', r.srException.params.method)
    r = fc.sr_get('authGithubLogin', {'simulation_type': sim_type})
    state = oc.values.state
    pkeq(302, r.status_code)
    pkre(state, r.headers['location'])
    fc.sr_get('authGithubAuthorized', query={'state': state})
    r = fc.sr_post(
        'authEmailLogin',
        {
            'email': '*****@*****.**',
            'simulationType': sim_type
        },
    )
    fc.sr_auth_state(isLoggedIn=True, method='github', uid=uid)
    fc.get(r.url)
    fc.sr_auth_state(
        isLoggedIn=True,
        method='email',
        uid=uid,
        userName='******',
    )
Esempio n. 4
0
def x_test_oauth_conversion_setup(monkeypatch):
    """Prepares data for auth conversion

    You need to run this as a test (no other cases), and then:
        rm -rf email_data
        mv email_work email_data

    Also grab the cookie output, and add it to test_oauth_conversion
    """
    fc, sim_type = _fc(github_deprecated=False)

    from pykern import pkcollections
    from pykern.pkdebug import pkdlog
    from pykern.pkunit import pkok, pkre, pkeq
    from sirepo.auth import github
    from sirepo import github_srunit
    import re

    oc = github_srunit.MockOAuthClient(monkeypatch, 'emailer')
    fc.sr_get(
        'oauthLogin',
        {
            'simulation_type': sim_type,
            'oauth_type': github.DEFAULT_OAUTH_TYPE,
        },
    )
    t = fc.sr_auth_state(userName=None, isLoggedIn=False, method=None)
    state = oc.values.state
    r = fc.sr_get(
        'oauthAuthorized',
        {
            'oauth_type': github.DEFAULT_OAUTH_TYPE,
        },
        query={'state': state},
    )
    uid = fc.sr_auth_state(
        displayName=None,
        method='github',
        needCompleteRegistration=True,
        userName='******',
    ).uid
    fc.sr_get('authLogout', {'simulation_type': sim_type})
    pkdlog(fc.cookie_jar)
    return
Esempio n. 5
0
def test_oauth_conversion(auth_fc, monkeypatch):
    """See `x_test_oauth_conversion_setup`"""
    fc = auth_fc

    from pykern import pkcollections
    from pykern.pkdebug import pkdp
    from pykern.pkunit import pkok, pkre, pkeq, pkexcept, pkfail
    from pykern import pkunit
    from pykern import pkio
    from sirepo.auth import github
    from sirepo import github_srunit
    from sirepo import server
    import sirepo.srdb
    import sirepo.util
    import shutil

    pkio.unchecked_remove(sirepo.srdb.root())
    pkunit.data_dir().join('db').copy(sirepo.srdb.root())
    fc.cookie_jar.clear()
    fc.set_cookie('localhost', 'sirepo_dev', 'Z0FBQUFBQmN2bGQzaGc1MmpCRkxIOWNpWi1yd1JReXUxZG5FV2VqMjFwU2w2cmdOSXhlaWVkOC1VUzVkLVR5NzdiS080R3p1aGUwUEFfdmpmdDcxTmJlOUR2eXpJY2l1YUVWaUVVa3dCYXpnZGIwTV9fei1iTWNCdkp0eXJVY0Ffenc2SVoxSUlLYVM=')
    oc = github_srunit.MockOAuthClient(monkeypatch, 'emailer')
    uid = fc.sr_auth_state(isLoggedIn=False, method='github').uid
    with pkexcept('SRException.*method.*github.*routeName=loginWith'):
        fc.sr_post('listSimulations', {'simulationType': fc.sr_sim_type})
    r = fc.sr_get('authGithubLogin', {'simulation_type': fc.sr_sim_type}, redirect=False)
    pkre(oc.values.state, r.headers['Location'])
    state = oc.values.state
    fc.sr_get('authGithubAuthorized', query={'state': state})
    r = fc.sr_post(
        'authEmailLogin',
        {'email': '*****@*****.**', 'simulationType': fc.sr_sim_type},
    )
    fc.sr_auth_state(isLoggedIn=True, method='github', uid=uid)
    fc.sr_email_confirm(fc, r)
    fc.sr_auth_state(
        isLoggedIn=True,
        method='email',
        uid=uid,
        userName='******',
    )