Ejemplo n.º 1
0
def test_payload_refresh_kano_kit():
    token = cf.get_token()
    if token:
        import mercury
        m = mercury.KanoWorld(cf.API_URL)
        p = m.get_refresh_header(token)
        assert p == 'Authorization: Bearer {}'.format(token)
def test_refresh_token_kano_kit():
    token = cf.get_token()
    if token:
        import mercury
        m = mercury.KanoWorld(cf.API_URL)
        s = m.refresh_token(token, cf.HTTP_VERBOSE)
        assert s is True
Ejemplo n.º 3
0
def test_timestamp_corrupted():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)

    # Token should be valid by about 1 day
    fake_duration_file(m.data_filename, 'corrupted number')
    s = m.is_logged_in(cf.HTTP_VERBOSE)
    assert s is False
Ejemplo n.º 4
0
def test_timestamp_future():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)

    # Token should be valid by 1 day
    fake_duration_file(m.data_filename, time.time() + 86400)
    s = m.is_logged_in(cf.HTTP_VERBOSE)
    assert s is True
Ejemplo n.º 5
0
def get_mixed_username():
    if is_registered():
        import mercury  # Lazy import to avoid dynamically linking with global import
        kw = mercury.KanoWorld(kw_url)
        username = kw.get_username()
    else:
        username = get_user_unsudoed()
    return username
Ejemplo n.º 6
0
def test_login_success():
    username = '******'
    password = '******'

    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    s = m.login(username, password, cf.HTTP_VERBOSE)
    assert s is True
Ejemplo n.º 7
0
def test_timestamp_now():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)

    # Token should be valid, just by 15 seconds
    fake_duration_file(m.data_filename, time.time() + 15)
    s = m.is_logged_in(cf.HTTP_VERBOSE)
    assert s is True
def test_refresh_token_test_user():
    token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.' \
            'eyJleHAiOjE2MTk5MjMxNjIuMDE2LCJ1c2VyIjp7' \
            'ImlkIjoiMDE3MTA3Njg0NzQ4MTg5OTE0NzciLCJyb2xlcyI6W119fQ.' \
            'Dhm3_2wDUyA5Tf3IANGfB8Y6DH2Nxzgl84fPSiURdJ8'

    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    s = m.refresh_token(token, cf.HTTP_VERBOSE)
    assert s is True
Ejemplo n.º 9
0
def test_is_logged_in_fail():
    username = '******'
    password = '******'

    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    s = m.login(username, password, cf.HTTP_VERBOSE)
    assert s is False

    s = m.is_logged_in(cf.HTTP_VERBOSE)
    assert s is False
Ejemplo n.º 10
0
def test_login_failed():
    username = '******'
    password = '******'

    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    s = m.login(username, password, cf.HTTP_VERBOSE)
    assert s is False

    assert len(m.get_token()) == 0
    assert len(m.get_expiration_date()) == 0
Ejemplo n.º 11
0
def login(login_name, password, verbose=http_verbose):
    import mercury  # Lazy import to avoid dynamically linking with global import

    login_name = login_name.strip()
    password = password.strip()

    kw = mercury.KanoWorld(kw_url)
    success = kw.login(login_name, password, verbose)
    if success:
        # TODO: refactor function login_register_data
        return True, None
    else:
        return False, _("Could not login to Kano World Services")
Ejemplo n.º 12
0
def test_timestamp_behind():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    username = '******'
    password = '******'

    s = m.login(username, password, cf.HTTP_VERBOSE)
    assert s is True

    # Token expired sometime around January 1, 1970
    fake_duration_file(m.data_filename, '100')
    s = m.is_logged_in(cf.HTTP_VERBOSE)
    assert s is False
def test_persistence_login():
    username = '******'
    password = '******'

    import mercury
    m = mercury.KanoWorld(cf.API_URL)

    if os.path.isfile(m.data_filename):
        os.unlink(m.data_filename)

    assert os.path.isfile(m.data_filename) is False
    s = m.login(username, password, cf.HTTP_VERBOSE)
    assert s is True
    assert os.path.isfile(m.data_filename) is True
def test_persistence_filename():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    assert len(m.data_filename) > 0
Ejemplo n.º 15
0
def test_kano_world_class():
    import mercury
    dummy = mercury.KanoWorld(cf.API_URL)
Ejemplo n.º 16
0
def test_refresh_failed():
    import mercury
    kw = mercury.KanoWorld(API_URL)
    s = kw.refresh_token('1234567890', False)
    assert s is False
Ejemplo n.º 17
0
def get_token():
    import mercury  # Lazy import to avoid dynamically linking with global import
    kw = mercury.KanoWorld(kw_url)
    return kw.get_token()
Ejemplo n.º 18
0
def remove_registration(verbose=http_verbose):
    import mercury  # Lazy import to avoid dynamically linking with global import
    kw = mercury.KanoWorld(kw_url)
    return kw.logout()
Ejemplo n.º 19
0
def is_registered():
    import mercury  # Lazy import to avoid dynamically linking with global import
    kw = mercury.KanoWorld(kw_url)
    return kw.is_logged_in()
def test_refresh_token_malformed():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    s = m.refresh_token('x', cf.HTTP_VERBOSE)
    assert s is False
Ejemplo n.º 21
0
def test_login_failed():
    import mercury
    kw = mercury.KanoWorld(API_URL)
    s = kw.login('abcde', '12345', False)
    assert s is False
Ejemplo n.º 22
0
def test_kw_whoami():
    import mercury
    kw = mercury.KanoWorld(cf.API_URL)
    assert kw.whoami() is not None
Ejemplo n.º 23
0
def test_logged_in():
    import mercury
    kw = mercury.KanoWorld(API_URL)
    assert kw.is_logged_in() is False
def test_refresh_token_nonexisting():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    s = m.refresh_token('1234567890', cf.HTTP_VERBOSE)
    assert s is False
Ejemplo n.º 25
0
def test_payload_refresh_nonempty():
    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    assert m.get_refresh_header("1234567890") is not None
Ejemplo n.º 26
0
def test_payload_refresh_bearer():
    token = '1234567890'
    import mercury
    m = mercury.KanoWorld(cf.API_URL)
    p = m.get_refresh_header("1234567890")
    assert p == 'Authorization: Bearer {}'.format(token)
Ejemplo n.º 27
0
def test_load_mercury_kw():
    import mercury
    kw = mercury.KanoWorld(API_URL)
    assert kw is not None