def test_fetch_groups(app, example_cern): """Test group extraction.""" example_response, example_token, _ = example_cern res = get_dict_from_response(example_response) # Override hidden group configuration import re cern.CFG_EXTERNAL_AUTH_HIDDEN_GROUPS = ('hidden_group',) cern.CFG_EXTERNAL_AUTH_HIDDEN_GROUPS_RE = (re.compile(r'Group[1-3]'),) # Check that groups were hidden as required groups = fetch_groups(res['Group']) assert all(group in groups for group in ('Group{}'.format(i) for i in range(4, 6)))
def test_fetch_extra_data(app, example_cern): """Test extra data extraction.""" example_response, example_token, _ = example_cern res = get_dict_from_response(example_response) # Check that groups were hidden as required extra_data = fetch_extra_data(res) assert 'person_id' in extra_data assert extra_data['person_id'] == "234567" assert 'identity_class' in extra_data assert extra_data['identity_class'] == "CERN Registered" assert 'department' in extra_data assert extra_data['department'] == "IT/CDA"
def test_fetch_groups(app, example_cern): """Test group extraction.""" example_response, example_token, _ = example_cern res = get_dict_from_response(example_response) # Override hidden group configuration import re app.config['OAUTHCLIENT_CERN_HIDDEN_GROUPS'] = ('hidden_group', ) app.config['OAUTHCLIENT_CERN_HIDDEN_GROUPS_RE'] = ( re.compile(r'Group[1-3]'), ) # Check that groups were hidden as required groups = fetch_groups(res['Group']) assert all(group in groups for group in ('Group{}'.format(i) for i in range(4, 6)))
def test_fetch_extra_data_fields_missing(app, example_cern): """Test extra data extraction when fields are missing.""" example_response, example_token, _ = example_cern res = get_dict_from_response(example_response) del res['PersonID'] del res['IdentityClass'] del res['Department'] # Check that groups were hidden as required extra_data = fetch_extra_data(res) assert 'person_id' in extra_data assert extra_data['person_id'] is None assert 'identity_class' in extra_data assert extra_data['identity_class'] is None assert 'department' in extra_data assert extra_data['department'] is None
def test_account_setup(app, example_cern, models_fixture): """Test account setup after login.""" client = app.test_client() ioc = app.extensions['oauthlib.client'] # Ensure remote apps have been loaded (due to before first request) client.get(url_for("invenio_oauthclient.login", remote_app='cern')) example_response, example_token, example_account_info = example_cern res = get_dict_from_response(example_response) mock_remote_get(ioc, 'cern', example_response) app = models_fixture datastore = app.extensions['invenio-accounts'].datastore user = datastore.find_user(email="*****@*****.**") token = RemoteToken.create( user.id, 'client_id', example_token['access_token'], 'secret', token_type=example_token['token_type'] ) account_setup(ioc.remote_apps['cern'], token, None)