def verify_object_id_and_tagging():
            from boto3 import client

            tenant = auth.get_tenant_id()
            conn = client('s3')

            artifacts = deploy.get_artifacts()
            assert len(artifacts) == 1

            artifact_id = artifacts[0]["id"]

            # verify object ID of proper MT format
            for key in conn.list_objects(Bucket='mender-artifacts-int-testing-us')['Contents']:
                if key['Key'].startswith(tenant):
                    expectedObject = "%s/%s" % (tenant, artifact_id)
                    assert key['Key'] == expectedObject

            # verify tagging is working
            tags = conn.get_object_tagging(Bucket='mender-artifacts-int-testing-us', Key=expectedObject)["TagSet"][0]
            assert tags["Value"] == tenant
            assert tags["Key"] == "tenant_id"

            # Delete artifact and make sure it's really gone
            conn.delete_object(Bucket="mender-artifacts-int-testing-us",
                               Key=expectedObject)

            deploy.delete_artifact(artifact_id)

            conn.list_objects(Bucket='mender-artifacts-int-testing-us')

            for key in conn.list_objects(Bucket='mender-artifacts-int-testing-us').get('Contents', []):
                if key['Key'].startswith(tenant):
                    pytest.fail("failed to delete artifact from s3")
예제 #2
0
    def test_artifacts_exclusive_to_user(self):
        users = [
            {
                "email": "*****@*****.**",
                "password": "******",
                "username": "******"
            },
            {
                "email": "*****@*****.**",
                "password": "******",
                "username": "******"
            },
        ]

        for user in users:
            auth.set_tenant(user["username"], user["email"], user["password"])
            with artifact_lock:
                with tempfile.NamedTemporaryFile() as artifact_file:
                    artifact = image.make_artifact(conftest.get_valid_image(),
                                                   conftest.machine_name,
                                                   user["email"],
                                                   artifact_file)

                    deploy.upload_image(artifact)

        for user in users:
            auth.set_tenant(user["username"], user["email"], user["password"])
            artifacts_for_user = deploy.get_artifacts()

            # make sure that one a single artifact exist for a given tenant
            assert len(artifacts_for_user)
            assert artifacts_for_user[0]["name"] == user["email"]