Esempio n. 1
0
def setup_module():

    global settings
    global session
    global base_url
    global inst
    global aggregator_ssh

    with open('test_config.json', 'r') as infile:
        settings = json.load(infile)

    with open('../aws_instance_info.json', 'r') as infile:
        tmp = json.load(infile)
        settings['subnet'] = tmp['subnet_id']
        settings['sec_group'] = tmp['sec_group']

    ip = EXCALIBUR_HOSTNAME + ':' + settings['port']

    aggregator_ip = AGGREGATOR_HOSTNAME

    inst = LDAP('', '')
    dn = 'cn=admin,dc=canvas,dc=virtue,dc=com'
    inst.get_ldap_connection()
    inst.conn.simple_bind_s(dn, 'Test123!')

    redirect = settings['redirect'].format(ip)

    sso = sso_tool(ip)
    assert sso.login(settings['user'], settings['password'])

    client_id = sso.get_app_client_id(settings['app_name'])
    if (client_id == None):
        client_id = sso.create_app(settings['app_name'], redirect)
        assert client_id

    code = sso.get_oauth_code(client_id, redirect)
    assert code

    token = sso.get_oauth_token(client_id, code, redirect)
    assert 'access_token' in token

    session = requests.Session()
    session.headers = {
        'Authorization': 'Bearer {0}'.format(token['access_token'])
    }
    session.verify = settings['verify']

    base_url = 'https://{0}/virtue/admin'.format(ip)

    subprocess.call(['sudo', 'mkdir', '-p', '/mnt/efs/images/tests'])
    subprocess.check_call([
        'sudo', 'rsync', '/mnt/efs/images/unities/8GB.img',
        '/mnt/efs/images/tests/8GB.img'
    ])

    aggregator_ssh = ssh_tool('ubuntu',
                              aggregator_ip,
                              sshkey='~/user-keys/default-virtue-key.pem')
Esempio n. 2
0
def test_create_app():

    sso = sso_tool(ip)
    assert sso.login(settings['user'], settings['password'])

    assert sso.get_app_client_id('DoesNotExist') == None
    client_id = sso.get_app_client_id(settings['app_name'])

    if (client_id == None):
        client_id = sso.create_app(settings['app_name'],
                                   settings['redirect'].format(ip))
        assert client_id
Esempio n. 3
0
def test_get_code():

    sso = sso_tool(ip)
    assert sso.login(settings['user'], settings['password'])

    client_id = sso.get_app_client_id(settings['app_name'])

    if (client_id == None):
        client_id = sso.create_app(settings['app_name'],
                                   settings['redirect'].format(ip))
        assert client_id

    print('client_id: ' + client_id)

    assert sso.get_oauth_code('NotTheClientId',
                              settings['redirect'].format(ip)) == None
    assert sso.get_oauth_code(client_id, 'NotARedirect') == None
    code = sso.get_oauth_code(client_id, settings['redirect'].format(ip))
    assert code
Esempio n. 4
0
def create_session():
    with open('test_config.json', 'r') as infile:
        settings = json.load(infile)

    excalibur_url = EXCALIBUR_HOSTNAME + ':' + settings['port']

    redirect = settings['redirect'].format(excalibur_url)

    sso = sso_tool(excalibur_url)
    res = sso.login(settings['user'], settings['password'])
    if not res:
        raise Exception('Failed to login [{}]'.format(res))

    client_id = sso.get_app_client_id(settings['app_name'])
    if (client_id == None):
        client_id = sso.create_app(settings['app_name'], redirect)
        if not client_id:
            raise Exception(
                'Failed to create oauth app [{}]'.format(client_id))

    code = sso.get_oauth_code(client_id, redirect)
    if not code:
        raise Exception('Failed to get oauth code [{}]'.format(code))

    token = sso.get_oauth_token(client_id, code, redirect)
    if not 'access_token' in token:
        raise Exception(
            'Failed to get access token from oauth token [{}]'.format(token))

    session = requests.Session()
    session.headers = {
        'Authorization': 'Bearer {0}'.format(token['access_token'])
    }
    session.verify = settings['verify']

    admin_url = 'https://{0}/virtue/admin'.format(excalibur_url)

    security_url = 'https://{0}/virtue/security'.format(excalibur_url)

    user_url = 'https://{0}/virtue/user'.format(excalibur_url)

    return session, admin_url, security_url, user_url
Esempio n. 5
0
def login():

    global session

    sso = sso_tool(ip)
    assert sso.login('*****@*****.**', 'Test123!')

    client_id = sso.get_app_client_id(app_name)
    if (client_id is None):
        client_id = sso.create_app(app_name, redirect)
        assert client_id

    code = sso.get_oauth_code(client_id, redirect)
    assert code

    token = sso.get_oauth_token(client_id, code, redirect)
    assert 'access_token' in token

    session = requests.Session()
    session.headers = {
        'Authorization': 'Bearer {0}'.format(token['access_token'])
    }
    session.verify = verify_https
Esempio n. 6
0
def test_get_token():

    sso = sso_tool(ip)
    assert sso.login(settings['user'], settings['password'])

    client_id = sso.get_app_client_id(settings['app_name'])

    if (client_id == None):
        client_id = sso.create_app(settings['app_name'],
                                   settings['redirect'].format(ip))
        assert client_id

    print('client_id: ' + client_id)

    code = sso.get_oauth_code(client_id, settings['redirect'].format(ip))
    assert code
    print('code: ' + code)

    assert sso.get_oauth_token('NotTheClientId', code,
                               settings['redirect'].format(ip)) == None
    assert sso.get_oauth_token(client_id, 'NotTheCode',
                               settings['redirect'].format(ip)) == None
    assert sso.get_oauth_token(client_id, code, 'NotTheRedirect') == None
    token_data = sso.get_oauth_token(client_id, code,
                                     settings['redirect'].format(ip))
    assert token_data
    assert 'access_token' in token_data
    print('access_token: ' + token_data['access_token'])

    token = token_data['access_token']
    res = requests.request(
        'GET', ('https://{0}/virtue/user' + '/application/get').format(ip),
        headers={'Authorization': 'Bearer {0}'.format(token)},
        params={'appId': 'DoesNotExist'},
        verify=settings['verify'])

    assert json.loads(res.text) == [10, 'The given ID is invalid.']
Esempio n. 7
0
 def __init__(self, ip):
     self.ip = ip
     self.sso = sso_tool(ip + ':5002')
     self.session = None
     self.commands = {'help': {"help": "Get help"},
                      'exit': {"help": "Return to BASE mode or exit"}}
Esempio n. 8
0
    if (args.interrogate):
        Packager.interrogate_package(args.interrogate)

    if (not args.export and not args.import_):
        exit(0)

    if (args.excalibur_ip == None):
        print('Need -e/--excalibur_ip argument to import/export')
        exit(1)

    ip = args.excalibur_ip + ':' + str(args.excalibur_port)

    redirect = OAUTH_REDIRECT.format(ip)

    sso = sso_tool(ip)

    username = args.user
    if (username == None):
        username = input('Username: '******'Password: ')
    assert sso.login(username, password)

    del args.password
    del password

    oauth_app = args.oauth_app
    if (oauth_app == DEFAULT_APP_NAME):
Esempio n. 9
0
def test_login():

    sso = sso_tool(ip)
    assert not sso.login(settings['user'], 'NotThePassword')
    assert sso.login(settings['user'], settings['password'])
Esempio n. 10
0
    parser.add_argument('-p', '--password',
                        help='Password to use. If not specified, will prompt.')
    parser.add_argument('-A', '--appid', default='APP_1', help='Application ID to use ('
                                                               'default is APP_1)')
    parser.add_argument('-s', '--server', default='excalibur.galahad.com:5002',
                        help='Server address')

    args = parser.parse_args()

    if args.password is None:
        import getpass

        password = getpass.getpass('User password: '******'ERROR: Could not log in')
        sys.exit(1)

    redirect = 'https://{}/virtue/test'.format(args.server)
    redirect_canvas = 'https://{}/virtue/test\n' \
                      'http://canvas.com:3000/connect/excalibur/callback'.format(args.server)

    client_id = sso.get_app_client_id(args.appid)
    if (client_id is None):
        client_id = sso.create_app(args.appid, redirect_canvas)
        assert client_id

    print('The Client ID is {}'.format(client_id))