Ejemplo n.º 1
0
void HTTPCredentialsTest::testAuthenticationParams()
{
	const std::string authInfo("nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"40e4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
	HTTPAuthenticationParams params(authInfo);
	
	assert (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
	assert (params["realm"] == "TestDigest");
	assert (params["response"] == "40e4889cfbd0e561f71e3107a2863bc4");
	assert (params["uri"] == "/digest/");
	assert (params["username"] == "user");
	assert (params.size() == 5);
	assert (params.toString() == authInfo);
	
	params.clear();
	HTTPRequest request;
	request.set("Authorization", "Digest " + authInfo);
	params.fromRequest(request);

	assert (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
	assert (params["realm"] == "TestDigest");
	assert (params["response"] == "40e4889cfbd0e561f71e3107a2863bc4");
	assert (params["uri"] == "/digest/");
	assert (params["username"] == "user");
	assert (params.size() == 5);

	params.clear();
	HTTPResponse response;
	response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");	
	params.fromResponse(response);
	
	assert (params["realm"] == "TestDigest");
	assert (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
	assert (params.size() == 2);
}
Ejemplo n.º 2
0
void HTTPCredentialsTest::testProxyCredentialsDigest()
{
	HTTPCredentials creds("user", "s3cr3t");
	HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
	HTTPResponse response;
	response.set("Proxy-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");	
	creds.proxyAuthenticate(request, response);	
	assert (request.get("Proxy-Authorization") == "Digest username=\"user\", nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", uri=\"/digest/\", response=\"40e4889cfbd0e561f71e3107a2863bc4\"");
}
Ejemplo n.º 3
0
void HTTPCredentialsTest::testProxyCredentialsBasic()
{
	HTTPCredentials creds("user", "s3cr3t");
	HTTPRequest request(HTTPRequest::HTTP_GET, "/basic/");
	HTTPResponse response;
	response.set("Proxy-Authenticate", "Basic realm=\"TestBasic\"");	
	creds.proxyAuthenticate(request, response);	
	assert (request.get("Proxy-Authorization") == "Basic dXNlcjpzM2NyM3Q=");
}
Ejemplo n.º 4
0
void HTTPCredentialsTest::testVerifyAuthInfoQoP()
{
	HTTPDigestCredentials creds("user", "s3cr3t");
	HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
	HTTPResponse response;
	response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\", opaque=\"opaque\", qop=\"auth,auth-int\"");	
	creds.authenticate(request, response);
	assert (creds.verifyAuthInfo(request));
	
	request.set("Authorization", "Digest cnonce=\"f9c80ffd1c3bc4ee47ed92b704ba75a4\", nc=00000001, nonce=\"212573bb90170538efad012978ab811f%lu\", opaque=\"opaque\", qop=\"auth\", realm=\"TestDigest\", response=\"ff0e90b9aa019120ea0ed6e23ce95d9a\", uri=\"/digest/\", username=\"user\"");
	assert (!creds.verifyAuthInfo(request));
}
Ejemplo n.º 5
0
void HTTPCredentialsTest::testVerifyAuthInfo()
{
	HTTPDigestCredentials creds("user", "s3cr3t");
	HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
	HTTPResponse response;
	response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\"");	
	creds.authenticate(request, response);
	assert (creds.verifyAuthInfo(request));
	
	request.set("Authorization", "Digest nonce=\"212573bb90170538efad012978ab811f%lu\", realm=\"TestDigest\", response=\"xxe4889cfbd0e561f71e3107a2863bc4\", uri=\"/digest/\", username=\"user\"");
	assert (!creds.verifyAuthInfo(request));
}
Ejemplo n.º 6
0
void HTTPCredentialsTest::testDigestCredentialsQoP()
{
	HTTPDigestCredentials creds("user", "s3cr3t");
	HTTPRequest request(HTTPRequest::HTTP_GET, "/digest/");
	HTTPResponse response;
	response.set("WWW-Authenticate", "Digest realm=\"TestDigest\", nonce=\"212573bb90170538efad012978ab811f%lu\", opaque=\"opaque\", qop=\"auth,auth-int\"");	
	creds.authenticate(request, response);
	
	HTTPAuthenticationParams params(request);
	assert (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
	assert (params["realm"] == "TestDigest");
	assert (params["response"] != "40e4889cfbd0e561f71e3107a2863bc4");
	assert (params["uri"] == "/digest/");
	assert (params["username"] == "user");
	assert (params["opaque"] == "opaque");
	assert (params["cnonce"] != "");
	assert (params["nc"] == "00000001");
	assert (params["qop"] == "auth");
	assert (params.size() == 9);
	
	std::string cnonce = params["cnonce"];
	std::string aresp = params["response"];
	
	params.clear();
	
	creds.updateAuthInfo(request);
	params.fromRequest(request);
	assert (params["nonce"] == "212573bb90170538efad012978ab811f%lu");
	assert (params["realm"] == "TestDigest");
	assert (params["response"] != aresp);
	assert (params["uri"] == "/digest/");
	assert (params["username"] == "user");
	assert (params["opaque"] == "opaque");
	assert (params["cnonce"] == cnonce);
	assert (params["nc"] == "00000002");
	assert (params["qop"] == "auth");
	assert (params.size() == 9);
}