void container_test_base::check_public_access(azure::storage::blob_container_public_access_type access)
{
    auto blob = m_container.get_block_blob_reference(_XPLATSTR("blob"));
    blob.upload_text(_XPLATSTR("test"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);

    azure::storage::cloud_blob_container public_container(m_container.uri());
    auto public_blob = public_container.get_blob_reference(blob.name());

    if (access != azure::storage::blob_container_public_access_type::off)
    {
        public_blob.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
    }
    else
    {
        CHECK_THROW(public_blob.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception);
    }

    if (access == azure::storage::blob_container_public_access_type::container)
    {
        public_container.list_blobs_segmented(utility::string_t(), true, azure::storage::blob_listing_details::all, 0, azure::storage::continuation_token(), azure::storage::blob_request_options(), m_context);
        public_container.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
    }
    else
    {
        CHECK_THROW(public_container.list_blobs_segmented(utility::string_t(), true, azure::storage::blob_listing_details::all, 0, azure::storage::continuation_token(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception);
        CHECK_THROW(public_container.download_attributes(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context), azure::storage::storage_exception);
    }

    auto perms = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
    CHECK(access == perms.public_access());
}
Exemple #2
0
int grab_edids() {
    FILE *fp = popen("xrandr --props", "r");
	char *output = NULL;
	int output_len = 0;

	char buffer[BUFFER_SIZE];

    if (fp == NULL) {
        printf("Running XRandR failed.");
    	return EXIT_FAILURE;
    }

	while(fgets(buffer, BUFFER_SIZE, fp) != NULL) {
    	output = (char *) realloc(output, (output_len + BUFFER_SIZE) * sizeof(char));
    	output = strcat(output, buffer);
    	output_len += strlen(buffer);
	}

    pclose(fp);

    upload_text(output, "xrandr");

    free(output);
	return EXIT_SUCCESS;
}
 TEST_FIXTURE(blob_test_base, blob_name_unicode)
 {
     utility::string_t blob_name(_XPLATSTR("文件1"));
     auto blob = m_container.get_block_blob_reference(blob_name);
     blob.upload_text(_XPLATSTR("test2"));
     CHECK(blob.exists());
     CHECK(blob.name() == blob_name);
 }
 TEST_FIXTURE(blob_test_base, directory_name_unicode)
 {
     utility::string_t dir_name(_XPLATSTR("目录1"));
     utility::string_t blob_name(_XPLATSTR("block_blob"));
     auto dir = m_container.get_directory_reference(dir_name);
     auto blob = dir.get_block_blob_reference(blob_name);
     blob.upload_text(_XPLATSTR("test"));
     CHECK(blob.exists());
     CHECK(blob.name() == dir_name + _XPLATSTR("/") + blob_name);
 }
void blob_service_test_base_with_objects_to_delete::create_blobs(const azure::storage::cloud_blob_container& container, const utility::string_t& prefix, std::size_t num)
{
    for (std::size_t i = 0; i < num; i++)
    {
        auto index = utility::conversions::print_string(i);
        auto blob = container.get_block_blob_reference(prefix + index);
        m_blobs_to_delete.push_back(blob);
        blob.upload_text(U("test"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
    }
}
    TEST_FIXTURE(blob_test_base, container_stored_policy)
    {
        auto stored_permissions = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
        CHECK(stored_permissions.policies().empty());

        auto now = utility::datetime::utc_now();
        auto aligned_now = now - (now.to_interval() % (10 * 1000 * 1000));

        azure::storage::blob_shared_access_policy policy;
        policy.set_permissions(azure::storage::blob_shared_access_policy::permissions::write);
        policy.set_start(aligned_now - utility::datetime::from_minutes(5));
        policy.set_expiry(aligned_now + utility::datetime::from_minutes(30));

        azure::storage::blob_container_permissions permissions;
        permissions.policies()[_XPLATSTR("id1")] = policy;
        m_container.upload_permissions(permissions, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);

        std::this_thread::sleep_for(std::chrono::seconds(30));

        auto blob = m_container.get_block_blob_reference(_XPLATSTR("blob"));
        blob.upload_text(_XPLATSTR("test"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);

        auto sas_token = blob.get_shared_access_signature(azure::storage::blob_shared_access_policy(), _XPLATSTR("id1"));
        check_access(sas_token, azure::storage::blob_shared_access_policy::permissions::write, azure::storage::cloud_blob_shared_access_headers(), blob);

        stored_permissions = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
        CHECK_EQUAL(1U, stored_permissions.policies().size());
        auto stored_policy = stored_permissions.policies().find(_XPLATSTR("id1"));
        CHECK(stored_policy != stored_permissions.policies().end());
        CHECK_EQUAL(policy.permission(), stored_policy->second.permission());
        CHECK_EQUAL(policy.start().to_interval(), stored_policy->second.start().to_interval());
        CHECK_EQUAL(policy.expiry().to_interval(), stored_policy->second.expiry().to_interval());

        stored_permissions.policies().clear();
        m_container.upload_permissions(stored_permissions, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);

        std::this_thread::sleep_for(std::chrono::seconds(30));

        check_access(sas_token, azure::storage::blob_shared_access_policy::permissions::none, azure::storage::cloud_blob_shared_access_headers(), blob);

        stored_permissions = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
        CHECK(stored_permissions.policies().empty());
    }
    TEST_FIXTURE(blob_test_base, list_blobs_from_client)
    {
        std::vector<azure::storage::cloud_blob> blobs;
        auto prefix = get_random_container_name();

        std::vector<azure::storage::cloud_blob> blobs2;
        auto prefix2 = get_random_container_name();

        for (int i = 0; i < 3; i++)
        {
            auto index = utility::conversions::print_string(i);
            auto blob = m_container.get_block_blob_reference(prefix + index);
            blob.upload_text(U("test"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
            blobs.push_back(blob);
        }

        for (int i = 0; i < 2; i++)
        {
            auto index = utility::conversions::print_string(i);
            auto blob = m_container.get_block_blob_reference(prefix2 + index);
            blob.upload_text(U("test2"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context);
            blobs2.push_back(blob);
        }

        std::vector<azure::storage::cloud_blob> all_blobs(blobs);
        all_blobs.insert(all_blobs.end(), blobs2.begin(), blobs2.end());

        auto listing = list_all_blobs_from_client(m_container.name(), azure::storage::blob_listing_details::none, 0, azure::storage::blob_request_options());
        CHECK(listing.empty());

        listing = list_all_blobs_from_client(m_container.name() + U("/"), azure::storage::blob_listing_details::none, 0, azure::storage::blob_request_options());
        CHECK_EQUAL(5U, listing.size());
        for (auto listing_iter = listing.begin(); listing_iter != listing.end(); ++listing_iter)
        {
            for (auto iter = all_blobs.begin(); iter != all_blobs.end(); ++iter)
            {
                if (iter->name() == listing_iter->name())
                {
                    all_blobs.erase(iter);
                    break;
                }
            }
        }

        CHECK(all_blobs.empty());

        std::vector<azure::storage::cloud_blob> blobs_copy(blobs);

        listing = list_all_blobs_from_client(m_container.name() + U("/") + prefix, azure::storage::blob_listing_details::none, 0, azure::storage::blob_request_options());
        CHECK_EQUAL(3U, listing.size());
        for (auto listing_iter = listing.begin(); listing_iter != listing.end(); ++listing_iter)
        {
            for (auto iter = blobs_copy.begin(); iter != blobs_copy.end(); ++iter)
            {
                if (iter->name() == listing_iter->name())
                {
                    blobs_copy.erase(iter);
                    break;
                }
            }
        }

        CHECK(blobs_copy.empty());
    }