Exemple #1
0
def test_change_user_password(connection_with_temporary_testuser):

    connection, users, user, user_id = connection_with_temporary_testuser

    with user as m:
        m.password = "******"

    # Retrieve updated object from server
    verification = users[user_id]
    assert 'password' not in verification

    # Backup
    original_auth = connection._authprovider

    # Try to login with the old password, should fail
    with pytest.raises(Unauthorized):
        connection._authprovider = Credentials(username=user.username,
                                               password="******",
                                               provider=verification.type)
        current_session = connection.server.current_session

    # Try to login
    connection._authprovider = Credentials(username=user.username,
                                           password="******",
                                           provider=verification.type)
    current_session = connection.server.current_session
    print("current_session", current_session)

    # Restore
    connection._authprovider = original_auth

    # Verify that we were logged in as the temporary user
    assert user_id == current_session['userId']
Exemple #2
0
def pytest_generate_tests(metafunc):

    # Creates a "servers" fixture on the fly when another fixture uses it.
    if 'servers' in metafunc.fixturenames:

        configs = []

        s = metafunc.config.getoption('server')
        print("Running tests against server {}".format(s))

        hostname, port = s.split(":")

        # magic hostname
        if hostname == "mockserverlocal":
            clazz = MockedConnection
        else:
            clazz = Connection

        configs.append(
            ConnectionContainer(
                clazz, hostname, int(port),
                Credentials(
                    metafunc.config.getoption("username"),
                    metafunc.config.getoption("password"),
                    metafunc.config.getoption("provider"),
                ), False))

        metafunc.parametrize("servers",
                             argvalues=configs,
                             ids=identifiers_for_server_list)
Exemple #3
0
def mock_server_with_authenticated_connection_and_bad_credentials():
    raise DeprecationWarning()
    connection = Connection("mockserverlocal",
                            auth=Credentials("fakeuserthatdoesntexist", "",
                                             "mock"))
    adapter = LogInsightMockAdapter()
    adapter.prep()
    connection._requestsession.mount('https://', adapter)
    return connection
Exemple #4
0
def mock_server_with_authenticated_connection():
    """Instantiate a LogInsightMockAdapter with a """
    raise DeprecationWarning()
    connection = Connection("mockserverlocal",
                            auth=Credentials("admin", "password", "mock"))
    adapter = LogInsightMockAdapter()
    adapter.prep()
    connection._requestsession.mount('https://', adapter)
    return connection
Exemple #5
0
#!/usr/bin/env python

from pyloginsight.connection import Connection, Credentials
import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser('Gets the shared content from a server.')
    parser.add_argument('--username', required=True)
    parser.add_argument('--password', required=True)
    parser.add_argument('--provider', default='Local')
    parser.add_argument('--hostname', required=True)
    args = parser.parse_args()

    creds = Credentials(username=args.username,
                        password=args.password,
                        provider=args.provider)
    conn = Connection(hostname=args.hostname, auth=creds, verify=False)

    response = conn.get(url='/users')
    for user in response['users']:
        print('{} {}'.format(user.get('id', 'unknown'),
                             user.get('username', 'unknown')))
Exemple #6
0
                                  auth=c.auth,
                                  port=c.port,
                                  verify=c.verify)

    # Lie about port number
    if c.clazz is Connection:
        adapter = SetHostHeaderAdapter("%s:9543" % c.hostname)
        connection_instance._requestsession.mount(connection_instance._apiroot,
                                                  adapter)

    ensure_server_bootstrapped_and_licensed(connection_instance, licensekey)
    return connection_instance


# Matrix of bad credentials multipled by server list
@pytest.fixture(params=[Credentials("fake", "fake", "fake"), None])
def wrong_credential_connection(servers, request, licensekey):
    """A pyloginsight.connection to a remote server, with non-functional credentials."""
    c = servers._replace(auth=request.param)
    connection_instance = c.clazz(c.hostname,
                                  auth=c.auth,
                                  port=c.port,
                                  verify=c.verify)
    # Lie about port number
    if c.clazz is Connection:
        adapter = SetHostHeaderAdapter("%s:9543" % c.hostname)
        connection_instance._requestsession.mount(connection_instance._apiroot,
                                                  adapter)
    ensure_server_bootstrapped_and_licensed(connection_instance, licensekey)
    return connection_instance
Exemple #7
0
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

# Logging
import logging
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=logging.INFO)

if __name__ == "__main__":

    parser = argparse.ArgumentParser(
        description='Check AD configuration values across multiple hosts with the same credentials.')
    parser.add_argument('-u', '--username', required=True)
    parser.add_argument('-p', '--provider', required=True)
    parser.add_argument('-s', '--servers', nargs='+', required=True)
    args = parser.parse_args()

    creds = Credentials(username=args.username, password=getpass.getpass('Password: '******'Skipping {server} since provided credentials do not work.'.format(server=server))
            continue
        except requests.ConnectionError:
            logging.error('Skipping {server} due to connection error.  Check IP or FQDN.'.format(server=server))
            continue

        try:
            ad_domain_servers = root.find('./authentication/auth-method/ad-domain-servers').get('value')
        except AttributeError: