Example #1
0
 def test_create_snf_user(self, client, create_user):
     snf_admin = identity.IdentityClient(None, None)
     vo = 'EXAMPLE'
     email = '*****@*****.**'
     server.create_snf_user(snf_admin, dn, vo, email)
     create_user.assert_called_once_with(
         username=email,
         first_name='Tyler',
         last_name='Durden.12345678',
         affiliation=vo)
Example #2
0
    def test_enroll_to_project(self, client):
        method = 'astavoms.identity.IdentityClient.enroll_to_project'
        snf_admin = identity.IdentityClient(None, None)
        email = '*****@*****.**'
        project = 's0me-proj3ct-1d'

        with mock.patch(method) as enroll:
            server.enroll_to_project(snf_admin, email, project)
            enroll.assert_called_once_with(email, project)

        with mock.patch(method, side_effect=ClientError('err', 409)) as enroll:
            server.enroll_to_project(snf_admin, email, project)
            #  User already enrolled, fail but supress the error
            enroll.assert_called_once_with(email, project)

        with mock.patch(method, side_effect=ClientError('err', 404)):
            with self.assertRaises(ClientError):
                server.enroll_to_project(snf_admin, email, project)
Example #3
0
def run(settings):
    """Run the service"""
    ldap_args = dict(ldap_url=settings.get('ldap_url'),
                     admin=settings.get('ldap_admin'),
                     password=settings.get('ldap_password'),
                     base_dn=settings.get('ldap_base_dn'))
    pool_args = dict(
        dbname=settings.get('pool_name'),
        host=settings.get('pool_host'),
        user=settings.get('pool_user'),
        password=settings.get('pool_password'),
    )
    voms_args = dict([(k, v) for k, v in settings.items()
                      if k in ('voms_policy', 'voms_dir', 'ca_path',
                               'voms_api_lib')])

    snf_certs = settings.get('snf_ca_certs', None)
    vo_projects = settings.get('vo_projects', None)
    if snf_certs:
        https.patch_with_certs(snf_certs)
    elif settings.get('snf_ignore_ssl', None):
        https.patch_ignore_ssl()
    snf_admin = identity.IdentityClient(settings['snf_auth_url'],
                                        settings['snf_admin_token'])
    snf_admin.authenticate()

    server.ASTAVOMS_SERVER_SETTINGS.update(
        dict(
            ldap_args=ldap_args,
            pool_args=pool_args,
            vomsauth=authvoms.VomsAuth(**voms_args),
            snf_admin=snf_admin,
            vo_projects=vo_projects,
            disable_voms_verification=settings.get(
                'disable_voms_verification'),
        ))
    server.app.config.from_object(server)
    utils.setup_logger(server.logger,
                       debug=settings['debug'],
                       logfile=settings['logfile'])
    server.app.run(host=settings.get('host'), port=settings.get('port'))
Example #4
0
    def setUp(self, client):
        self.vo_projects_file = tempfile.NamedTemporaryFile()
        json.dump(vo_projects, self.vo_projects_file)
        self.vo_projects_file.flush()

        server.app.config['TESTING'] = True
        server.app.config['ASTAVOMS_SERVER_SETTINGS'] = dict(
            vomsauth=authvoms.VomsAuth(),
            snf_admin=identity.IdentityClient('http://example.org', 'token'),
            vo_projects=self.vo_projects_file.name,
            ldap_args=dict(
                ldap_url='ldap://ldap.example.org',
                admin='cn=admin,dc=example,dc=org',
                password='******',
                base_dn='ou=users,dc=example,dc=org',),
            pool_args=dict(
                pool_name='astavoms',
                pool_host='localhost',
                pool_user='******',
                pool_password='******',
            ),
        )
        self.app = server.app.test_client()
Example #5
0
    dbname=settings.get('pool_name'),
    host=settings.get('pool_host'),
    user=settings.get('pool_user'),
    password=settings.get('pool_password'),
)
voms_args = dict([(k, v) for k, v in settings.items()
                  if k in ('voms_policy', 'voms_dir', 'ca_path',
                           'voms_api_lib')])

snf_certs = settings.get('snf_ca_certs', None)
if snf_certs:
    https.patch_with_certs(snf_certs)
elif settings.get('snf_ignore_ssl', None):
    https.patch_ignore_ssl()

snf_admin = identity.IdentityClient(settings['snf_auth_url'],
                                    settings['snf_admin_token'])
snf_admin.authenticate()
vo_projects = settings.get('vo_projects', '/etc/astavoms/vo_projects.json')

server.ASTAVOMS_SERVER_SETTINGS.update(
    dict(
        ldap_args=ldap_args,
        pool_args=pool_args,
        vomsauth=authvoms.VomsAuth(**voms_args),
        snf_admin=snf_admin,
        vo_projects=vo_projects,
        disable_voms_verification=settings.get('disable_voms_verification'),
        self_url=settings.get('self_url', 'https://127.0.0.1:443'),
    ))
application.config.from_object(server)
debug = settings.get('debug')