Esempio n. 1
0
TEST_FIXTURE(oauth1_server_setup, oauth1_build_authorization_uri)
{
    m_server.server()->next_request().then([](test_request *request)
    {
        const utility::string_t header_authorization(request->m_headers[header_names::authorization]);

        // Verify prefix, and without 'oauth_token'.
        const utility::string_t prefix(U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
        VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));

        // Verify suffix with proper 'oauth_callback'.
        const utility::string_t suffix(U(", oauth_callback=\"http%3A%2F%2Flocalhost%3A17778%2F\""));
        VERIFY_IS_TRUE(std::equal(suffix.rbegin(), suffix.rend(), header_authorization.rbegin()));

        // Reply with temporary token and secret.
        std::map<utility::string_t, utility::string_t> headers;
        headers[header_names::content_type] = mime_types::application_x_www_form_urlencoded;
        request->reply(status_codes::OK, U(""), headers, "oauth_token=testbar&oauth_token_secret=xyzzy&oauth_callback_confirmed=true");
    });

    VERIFY_IS_FALSE(m_oauth1_config.token().is_valid_access_token());
    utility::string_t auth_uri = m_oauth1_config.build_authorization_uri().get();
    VERIFY_ARE_EQUAL(auth_uri, U("http://localhost:17778/?oauth_token=testbar"));
    VERIFY_IS_FALSE(m_oauth1_config.token().is_valid_access_token());
}
Esempio n. 2
0
// NOTE: This test also covers token_from_verifier().
TEST_FIXTURE(oauth1_server_setup, oauth1_token_from_redirected_uri)
{
    m_server.server()->next_request().then([](test_request *request)
    {
        const utility::string_t header_authorization(request->m_headers[header_names::authorization]);

        // Verify temporary token prefix.
        const utility::string_t prefix(U("OAuth oauth_version=\"1.0\", oauth_consumer_key=\"test_key\", oauth_token=\"xyzzy\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\""));
        VERIFY_ARE_EQUAL(0, header_authorization.find(prefix));

        // Verify suffix with 'oauth_verifier'.
        const utility::string_t suffix(U(", oauth_verifier=\"simsalabim\""));
        VERIFY_IS_TRUE(std::equal(suffix.rbegin(), suffix.rend(), header_authorization.rbegin()));

        // Verify we have 'oauth_nonce' and 'oauth_signature'.
        VERIFY_ARE_NOT_EQUAL(utility::string_t::npos, header_authorization.find(U("oauth_nonce")));
        VERIFY_ARE_NOT_EQUAL(utility::string_t::npos, header_authorization.find(U("oauth_signature")));

        // Reply with access token and secret.
        std::map<utility::string_t, utility::string_t> headers;
        headers[header_names::content_type] = mime_types::application_x_www_form_urlencoded;
        request->reply(status_codes::OK, U(""), headers, "oauth_token=test&oauth_token_secret=bar");
    });

    m_oauth1_config.set_token(oauth1_token(U("xyzzy"), U(""))); // Simulate temporary token.

    const web::http::uri redirected_uri(U("http://localhost:17778/?oauth_token=xyzzy&oauth_verifier=simsalabim"));
    m_oauth1_config.token_from_redirected_uri(redirected_uri).wait();

    VERIFY_IS_TRUE(m_oauth1_config.token().is_valid_access_token());
    VERIFY_ARE_EQUAL(m_oauth1_config.token().access_token(), U("test"));
    VERIFY_ARE_EQUAL(m_oauth1_config.token().secret(), U("bar"));
}
Esempio n. 3
0
void extract_fractional_second(const utility::string_t& dateString, utility::string_t& resultString, uint64_t& ufrac_second)
{
    resultString = dateString;
    // First, the string must be strictly longer than 2 characters, and the trailing character must be 'Z'
    if (resultString.size() > 2 && resultString[resultString.size() - 1] == U('Z'))
    {
        // Second, find the last non-digit by scanning the string backwards
        auto last_non_digit = std::find_if_not(resultString.rbegin() + 1, resultString.rend(), is_digit);
        if (last_non_digit < resultString.rend() - 1)
        {
            // Finally, make sure the last non-digit is a dot:
            auto last_dot = last_non_digit.base() - 1;
            if (*last_dot == U('.'))
            {
                // Got it! Now extract the fractional second
                auto last_before_Z = std::end(resultString) - 1;
                ufrac_second = timeticks_from_second(last_dot, last_before_Z);
                // And erase it from the string
                resultString.erase(last_dot, last_before_Z);
            }
        }
    }
}
Esempio n. 4
0
	///Right trim
	///@details Trim right part of the string
	///@param s - string to be trimmed
	void rtrim(utility::string_t& s)
	{
		s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int,int>(std::isspace))).base(),s.end());
	}