示例#1
0
    def setup(self):
        self.dynalite_port = str(random.randint(32000, 34000))
        os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis.ini"
        os.environ["AWS_XRAY_SDK_ENABLED"] = "false"
        os.environ["CIS_ENVIRONMENT"] = "local"
        os.environ["CIS_DYNALITE_PORT"] = self.dynalite_port
        os.environ["CIS_REGION_NAME"] = "us-west-2"
        os.environ["AWS_ACCESS_KEY_ID"] = "foo"
        os.environ["AWS_SECRET_ACCESS_KEY"] = "bar"
        from cis_identity_vault import vault
        from cis_change_service.common import get_config

        self.patcher_salt = mock.patch(
            "cis_crypto.secret.AWSParameterstoreProvider.uuid_salt")
        self.mock_salt = self.patcher_salt.start()

        config = get_config()
        os.environ["CIS_DYNALITE_PORT"] = str(random.randint(32000, 34000))
        self.dynalite_port = config("dynalite_port", namespace="cis")
        self.dynaliteprocess = subprocess.Popen(
            [
                "/usr/sbin/java",
                "-Djava.library.path=/opt/dynamodb_local/DynamoDBLocal_lib",
                "-jar",
                "/opt/dynamodb_local/DynamoDBLocal.jar",
                "-inMemory",
                "-port",
                self.dynalite_port,
            ],
            preexec_fn=os.setsid,
        )
        v = vault.IdentityVault()
        v.connect()
        v.create()

        user_profile = FakeUser(config=FakeProfileConfig().minimal())
        self.user_profile = user_profile.as_json()
        from cis_change_service import api

        api.app.testing = True
        self.app = api.app.test_client()
        self.publisher_rules = common.WellKnown().get_publisher_rules()
        self.complex_structures = get_complex_structures()
示例#2
0
    def setup_class(self):
        os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis.ini"
        self.dynalite_port = str(random.randint(32000, 34000))
        self.kinesalite_port = str(random.randint(32000, 34000))
        os.environ["CIS_DYNALITE_PORT"] = self.dynalite_port
        os.environ["CIS_KINESALITE_PORT"] = self.kinesalite_port
        os.environ["AWS_XRAY_SDK_ENABLED"] = "false"
        self.dynalite_host = "localhost"
        self.kinesalite_host = "localhost"
        self.dynaliteprocess = subprocess.Popen(["dynalite", "--port", self.dynalite_port], preexec_fn=os.setsid)
        self.kinesaliteprocess = subprocess.Popen(["kinesalite", "--port", self.kinesalite_port], preexec_fn=os.setsid)

        from cis_profile_retrieval_service.common import seed

        vault_client = vault.IdentityVault()
        vault_client.boto_session = boto3.session.Session(region_name="us-west-2")
        vault_client.connect()
        vault_client.create()
        vault_client.find_or_create()

        self.dynamodb_client = boto3.client(
            "dynamodb",
            region_name="us-west-2",
            aws_access_key_id="ak",
            aws_secret_access_key="sk",
            endpoint_url="http://{}:{}".format(self.dynalite_host, self.dynalite_port),
        )

        self.dynamodb_resource = boto3.resource(
            "dynamodb",
            region_name="us-west-2",
            aws_access_key_id="ak",
            aws_secret_access_key="sk",
            endpoint_url="http://{}:{}".format(self.dynalite_host, self.dynalite_port),
        )
        seed(number_of_fake_users=100)
        self.table = self.dynamodb_resource.Table("local-identity-vault")
        from cis_profile_retrieval_service import v2_api as api

        api.app.testing = True
        self.app = api.app.test_client()
示例#3
0
    def setup(self):
        os.environ["CIS_ENVIRONMENT"] = "purple"
        os.environ["CIS_REGION_NAME"] = "us-east-1"
        self.vault_client = vault.IdentityVault()
        self.vault_client.connect()
        self.vault_client.find_or_create()

        self.user_profile = FakeUser().as_dict()
        self.uuid = self.user_profile["uuid"]["value"]
        self.vault_json_datastructure = {
            "id": self.user_profile.get("user_id").get("value"),
            "user_uuid": self.uuid,
            "primary_email": self.user_profile.get("primary_email").get("value"),
            "primary_username": self.user_profile.get("primary_username").get("value"),
            "sequence_number": "12345678",
            "profile": json.dumps(self.user_profile),
        }
        self.boto_session = boto3.session.Session(region_name="us-east-1")
        self.dynamodb_resource = self.boto_session.resource("dynamodb")
        self.dynamodb_client = self.boto_session.client("dynamodb")
        self.table = self.dynamodb_resource.Table("purple-identity-vault")
示例#4
0
    def test_dynamo_stream(self):
        os.environ["CIS_ENVIRONMENT"] = "testing"
        os.environ["CIS_REGION_NAME"] = "us-east-1"
        os.environ["DEFAULT_AWS_REGION"] = "us-east-1"
        os.environ["CIS_DYNAMODB_ARN"] = boto3.client(
            "dynamodb", region_name="us-east-1").describe_table(
                TableName="testing-identity-vault")["Table"]["TableArn"]
        from cis_identity_vault import vault

        self.v = vault.IdentityVault()
        os.environ["CIS_ENVIRONMENT"] = "testing"
        os.environ["CIS_REGION_NAME"] = "us-east-1"
        os.environ["DEFAULT_AWS_REGION"] = "us-east-1"
        self.v.connect()
        result = self.v.find_or_create()
        assert result is not None
        self.v.tag_vault()
        self.seed_fake_users()
        exch = exchange.DynamoStream()
        user_ids = exch.user_ids_from_stream(self.events_and_users["event"])
        assert user_ids is not None
        profiles = exch.profiles(user_ids)
        assert profiles is not None
示例#5
0
 def setup(self):
     self.patcher_salt = mock.patch(
         "cis_crypto.secret.AWSParameterstoreProvider.uuid_salt")
     self.patcher_salt = self.patcher_salt.start()
     os.environ["AWS_XRAY_SDK_ENABLED"] = "false"
     os.environ["CIS_ENVIRONMENT"] = "local"
     os.environ["CIS_CONFIG_INI"] = "tests/mozilla-cis.ini"
     self.dynalite_port = str(random.randint(32000, 34000))
     os.environ["CIS_DYNALITE_PORT"] = self.dynalite_port
     self.dynaliteprocess = subprocess.Popen([
         "/usr/sbin/java",
         "-Djava.library.path=/opt/dynamodb_local/DynamoDBLocal_lib",
         "-jar", "/opt/dynamodb_local/DynamoDBLocal.jar", "-inMemory",
         "-port", self.dynalite_port
     ],
                                             preexec_fn=os.setsid)
     from cis_identity_vault import vault
     v = vault.IdentityVault()
     v.connect()
     v.create()
     user_profile = FakeUser(config=FakeProfileConfig().minimal())
     self.user_profile = user_profile.as_json()
     self.user_profile_dict = user_profile.as_dict()
示例#6
0
    def setup(self):
        os.environ["CIS_CONFIG_INI"] = "tests/fixture/mozilla-cis.ini"
        self.dynamodb_client = boto3.client("dynamodb",
                                            region_name="us-west-2",
                                            aws_access_key_id="ak",
                                            aws_secret_access_key="sk")

        self.dynamodb_resource = boto3.resource("dynamodb",
                                                region_name="us-west-2",
                                                aws_access_key_id="ak",
                                                aws_secret_access_key="sk")

        from cis_identity_vault import vault

        self.vault_client = vault.IdentityVault()
        self.vault_client.boto_session = Stubber(
            boto3.session.Session(region_name="us-west-2")).client
        self.vault_client.dynamodb_client = self.dynamodb_client
        self.vault_client.find_or_create()
        self.table = self.dynamodb_resource.Table("testing-identity-vault")
        self.mr_mozilla_profile = fake_profile.FakeUser(seed=1337).as_dict()

        self.mr_nozilla_tainted_profile = fake_profile.FakeUser(
            seed=1337).as_dict()

        from cis_identity_vault.models import user

        vault_interface = user.Profile(self.table, self.dynamodb_client, False)
        vault_interface.create(
            profile_to_vault_structure(user_profile=self.mr_mozilla_profile))
        vault_interface.create(
            profile_to_vault_structure(
                user_profile=self.mr_nozilla_tainted_profile))

        self.mr_mozilla_change_event = kinesis_event_generate(
            self.mr_mozilla_profile)
示例#7
0
    def setup(self):
        os.environ["CIS_ENVIRONMENT"] = "purple"
        os.environ["CIS_REGION_NAME"] = "us-east-1"
        os.environ["DEFAULT_AWS_REGION"] = "us-east-1"
        self.vault_client = vault.IdentityVault()
        self.vault_client.connect()
        self.vault_client.find_or_create()
        self.boto_session = boto3.session.Session(region_name="us-east-1")
        self.dynamodb_resource = self.boto_session.resource("dynamodb")
        self.dynamodb_client = self.boto_session.client("dynamodb")
        self.table = self.dynamodb_resource.Table("purple-identity-vault")

        for x in range(0, 50):  # Must generate 50 users to test paginator
            user_profile = FakeUser().as_dict()
            user_profile["active"]["value"] = True
            uuid = user_profile["uuid"]["value"]
            vault_json_datastructure = {
                "id":
                user_profile.get("user_id").get("value"),
                "user_uuid":
                uuid,
                "primary_email":
                user_profile.get("primary_email").get("value"),
                "primary_username":
                user_profile.get("primary_username").get("value"),
                "sequence_number":
                "12345678",
                "profile":
                json.dumps(user_profile),
                "active":
                True,
            }
            from cis_identity_vault.models import user

            profile = user.Profile(self.table,
                                   self.dynamodb_client,
                                   transactions=False)
            profile.create(vault_json_datastructure)

        self.user_profile = FakeUser().as_dict()
        self.user_profile["active"]["value"] = True
        self.uuid = self.user_profile["uuid"]["value"]
        self.user_profile["staff_information"]["director"] = True
        self.vault_json_datastructure = {
            "id":
            self.user_profile.get("user_id").get("value"),
            "user_uuid":
            self.uuid,
            "primary_email":
            self.user_profile.get("primary_email").get("value"),
            "primary_username":
            self.user_profile.get("primary_username").get("value"),
            "sequence_number":
            "12345678",
            "profile":
            json.dumps(self.user_profile),
            "active":
            True,
        }

        profile.create(self.vault_json_datastructure)