Test for bug 539755, NPN_GetAuthenticationInfo
--HG-- extra : transplant_source : %1E%F7%C1%BF0%14Ul%0Ex%ABJ%0A%B9Z%0CX4%02%98
This commit is contained in:
Родитель
e2a663d5d0
Коммит
d49b0c3dee
|
@ -45,6 +45,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_MOCHITEST_FILES = \
|
||||
test_getauthenticationinfo.html \
|
||||
test_npobject_getters.html \
|
||||
test_npruntime_npnevaluate.html \
|
||||
test_npruntime_npninvoke.html \
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for Login Manager</title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
Test for NPN_GetAuthenticationInfo
|
||||
<p id="display"></p>
|
||||
|
||||
<div id="content">
|
||||
<iframe id="iframe"></iframe>
|
||||
</div>
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
|
||||
function iframeLoad() {
|
||||
var plugin = iframe.contentDocument.getElementById("embedtest");
|
||||
// valid request
|
||||
is(plugin.getAuthInfo("http", "localhost", 8888, "http", "testrealm"),
|
||||
"user1|password1",
|
||||
"correct user/pass retrieved");
|
||||
try {
|
||||
// invalid request -- wrong host
|
||||
is(plugin.getAuthInfo("http", "example.com", 8888, "http", "testrealm"),
|
||||
"user1|password1",
|
||||
"correct user/pass retrieved");
|
||||
ok(false, "no exception was thrown");
|
||||
}
|
||||
catch (err) {
|
||||
ok(true, "expected exception caught");
|
||||
}
|
||||
try {
|
||||
// invalid request -- wrong port
|
||||
is(plugin.getAuthInfo("http", "localhost", 90, "http", "testrealm"),
|
||||
"user1|password1",
|
||||
"correct user/pass retrieved");
|
||||
ok(false, "no exception was thrown");
|
||||
}
|
||||
catch (err) {
|
||||
ok(true, "expected exception caught");
|
||||
}
|
||||
try {
|
||||
// invalid request -- wrong realm
|
||||
is(plugin.getAuthInfo("http", "localhost", 8888, "http", "wrongrealm"),
|
||||
"user1|password1",
|
||||
"correct user/pass retrieved");
|
||||
ok(false, "no exception was thrown");
|
||||
}
|
||||
catch (err) {
|
||||
ok(true, "expected exception caught");
|
||||
}
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
var iframe = document.getElementById("iframe");
|
||||
var am = Cc["@mozilla.org/network/http-auth-manager;1"].
|
||||
getService(Ci.nsIHttpAuthManager);
|
||||
am.setAuthIdentity("http", "localhost", 8888, "basic", "testrealm", "",
|
||||
"localhost", "user1", "password1");
|
||||
iframe.onload = iframeLoad;
|
||||
iframe.src = "http://localhost:8888/tests/toolkit/components/passwordmgr/" +
|
||||
"test/authenticate.sjs?user=user1&pass=password1&realm=testrealm&plugin=1";
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -80,6 +80,11 @@ arguments passed to the method.
|
|||
the object is passed to the same plugin instance, and false when passed
|
||||
to other plugin instances, see bug 532246 and
|
||||
test_multipleinstanceobjects.html.
|
||||
|
||||
* getAuthInfo(protocol, host, port, scheme, realm) - a wrapper for
|
||||
NPN_GetAuthenticationInfo(). Returns a string "username|password" for
|
||||
the specified auth criteria, or throws an exception if no data is
|
||||
available.
|
||||
|
||||
== Private browsing ==
|
||||
|
||||
|
|
|
@ -137,6 +137,7 @@ static bool checkObjectValue(NPObject* npobj, const NPVariant* args, uint32_t ar
|
|||
static bool enableFPExceptions(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool setCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool getCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
static bool getAuthInfo(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result);
|
||||
|
||||
static const NPUTF8* sPluginMethodIdentifierNames[] = {
|
||||
"npnEvaluateTest",
|
||||
|
@ -173,6 +174,7 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = {
|
|||
"enableFPExceptions",
|
||||
"setCookie",
|
||||
"getCookie",
|
||||
"getAuthInfo",
|
||||
};
|
||||
static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)];
|
||||
static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMethodIdentifierNames)] = {
|
||||
|
@ -210,6 +212,7 @@ static const ScriptableFunction sPluginMethodFunctions[ARRAY_LENGTH(sPluginMetho
|
|||
enableFPExceptions,
|
||||
setCookie,
|
||||
getCookie,
|
||||
getAuthInfo,
|
||||
};
|
||||
|
||||
struct URLNotifyData
|
||||
|
@ -1331,6 +1334,20 @@ NPN_GetValueForURL(NPP instance, NPNURLVariable variable, const char *url, char
|
|||
return sBrowserFuncs->getvalueforurl(instance, variable, url, value, len);
|
||||
}
|
||||
|
||||
NPError
|
||||
NPN_GetAuthenticationInfo(NPP instance,
|
||||
const char *protocol,
|
||||
const char *host, int32_t port,
|
||||
const char *scheme,
|
||||
const char *realm,
|
||||
char **username, uint32_t *ulen,
|
||||
char **password,
|
||||
uint32_t *plen)
|
||||
{
|
||||
return sBrowserFuncs->getauthenticationinfo(instance, protocol, host, port, scheme, realm,
|
||||
username, ulen, password, plen);
|
||||
}
|
||||
|
||||
//
|
||||
// npruntime object functions
|
||||
//
|
||||
|
@ -2279,3 +2296,55 @@ getCookie(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant*
|
|||
STRINGZ_TO_NPVARIANT(cookie, *result);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
getAuthInfo(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result)
|
||||
{
|
||||
if (argCount != 5)
|
||||
return false;
|
||||
|
||||
NPP npp = static_cast<TestNPObject*>(npobj)->npp;
|
||||
|
||||
if (!NPVARIANT_IS_STRING(args[0]) || !NPVARIANT_IS_STRING(args[1]) ||
|
||||
!NPVARIANT_IS_INT32(args[2]) || !NPVARIANT_IS_STRING(args[3]) ||
|
||||
!NPVARIANT_IS_STRING(args[4]))
|
||||
return false;
|
||||
|
||||
const NPString* protocol = &NPVARIANT_TO_STRING(args[0]);
|
||||
const NPString* host = &NPVARIANT_TO_STRING(args[1]);
|
||||
uint32_t port = NPVARIANT_TO_INT32(args[2]);
|
||||
const NPString* scheme = &NPVARIANT_TO_STRING(args[3]);
|
||||
const NPString* realm = &NPVARIANT_TO_STRING(args[4]);
|
||||
|
||||
char* username = NULL;
|
||||
char* password = NULL;
|
||||
uint32_t ulen = 0, plen = 0;
|
||||
|
||||
NPError err = NPN_GetAuthenticationInfo(npp,
|
||||
protocol->UTF8Characters,
|
||||
host->UTF8Characters,
|
||||
port,
|
||||
scheme->UTF8Characters,
|
||||
realm->UTF8Characters,
|
||||
&username,
|
||||
&ulen,
|
||||
&password,
|
||||
&plen);
|
||||
|
||||
if (err != NPERR_NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* outstring = (char*)NPN_MemAlloc(ulen + plen + 2);
|
||||
memset(outstring, 0, ulen + plen + 2);
|
||||
strncpy(outstring, username, ulen);
|
||||
strcat(outstring, "|");
|
||||
strncat(outstring, password, plen);
|
||||
|
||||
STRINGZ_TO_NPVARIANT(outstring, *result);
|
||||
|
||||
NPN_MemFree(username);
|
||||
NPN_MemFree(password);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ function reallyHandleRequest(request, response) {
|
|||
|
||||
var expected_user = "", expected_pass = "", realm = "mochitest";
|
||||
var proxy_expected_user = "", proxy_expected_pass = "", proxy_realm = "mochi-proxy";
|
||||
var huge = false;
|
||||
var huge = false, plugin = false;
|
||||
var authHeaderCount = 1;
|
||||
// user=xxx
|
||||
match = /user=([^&]*)/.exec(query);
|
||||
|
@ -56,6 +56,11 @@ function reallyHandleRequest(request, response) {
|
|||
if (match)
|
||||
huge = true;
|
||||
|
||||
// plugin=1
|
||||
match = /plugin=1/.exec(query);
|
||||
if (match)
|
||||
plugin = true;
|
||||
|
||||
// multiple=1
|
||||
match = /multiple=([^&]*)/.exec(query);
|
||||
if (match)
|
||||
|
@ -139,6 +144,11 @@ function reallyHandleRequest(request, response) {
|
|||
response.write("<span id='footnote'>This is a footnote after the huge content fill</span>");
|
||||
}
|
||||
|
||||
if (plugin) {
|
||||
response.write("<embed id='embedtest' style='width: 400px; height: 100px;' " +
|
||||
"type='application/x-test'></embed>\n");
|
||||
}
|
||||
|
||||
response.write("</html>");
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче