def test_post_profiles_and_update_it_and_retrieving_status_it_should_succeed( self, fake_jwks): os.environ["CIS_ENVIRONMENT"] = "local" os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis.ini" os.environ["AWS_XRAY_SDK_ENABLED"] = "false" os.environ["CIS_DYNALITE_PORT"] = self.dynalite_port from cis_change_service import api # Post a new user f = FakeBearer() fake_jwks.return_value = json_form_of_pk token = f.generate_bearer_without_scope() api.app.testing = True self.app = api.app.test_client() my_fake_user = User(user_id="userA") my_fake_user.active.value = True my_fake_user.primary_email.value = "*****@*****.**" my_fake_user.uuid.value = None my_fake_user.primary_username.value = None result = self.app.post( "/v2/user?user_id={}".format(my_fake_user.user_id.value), headers={"Authorization": "Bearer " + token}, json=my_fake_user.as_dict(), content_type="application/json", follow_redirects=True, ) results = json.loads(result.get_data()) # Post it again result = self.app.post( "/v2/user?user_id={}".format(my_fake_user.user_id.value), headers={"Authorization": "Bearer " + token}, json=my_fake_user.as_dict(), content_type="application/json", follow_redirects=True, ) results = json.loads(result.get_data()) assert results is not None assert results.get("status_code") == 202 or results.get( "status_code") == 200
def filter_full_profiles(scopes, filter_display, vault_profiles): v2_profiles = [] for profile in vault_profiles: if isinstance(profile.get("profile"), str): vault_profile = json.loads(profile.get("profile")) else: vault_profile = profile.get("profile") v2_profile = User(user_structure_json=vault_profile) if "read:fullprofile" in scopes: # Assume someone has asked for all the data. logger.debug("The provided token has access to all of the data.", extra={"scopes": scopes}) pass else: # Assume the we are filtering falls back to public with no scopes logger.debug("This is a limited scoped query.", extra={"scopes": scopes}) v2_profile.filter_scopes( scope_to_mozilla_data_classification(scopes)) if "display:all" in scopes: logger.debug("display:all in token not filtering profile.", extra={"scopes": scopes}) else: logger.debug("display filtering engaged for query.", extra={"scopes": scopes}) v2_profile.filter_display(scope_to_display_level(scopes)) if filter_display is not None: v2_profile.filter_display(DisplayLevelParms.map(filter_display)) v2_profiles.append( dict(id=v2_profile.user_id, profile=v2_profile.as_dict())) return v2_profiles