From b8b008b1b3916878e4fe36db1532c33d527717c4 Mon Sep 17 00:00:00 2001 From: Jonathan Griffin Date: Thu, 21 Jan 2010 14:35:03 -0500 Subject: [PATCH] Test for bug 539755, NPN_GetAuthenticationInfo --HG-- extra : transplant_source : %1E%F7%C1%BF0%14Ul%0Ex%ABJ%0A%B9Z%0CX4%02%98 --- modules/plugin/test/mochitest/Makefile.in | 1 + .../mochitest/test_getauthenticationinfo.html | 75 +++++++++++++++++++ modules/plugin/test/testplugin/README | 5 ++ modules/plugin/test/testplugin/nptest.cpp | 69 +++++++++++++++++ .../passwordmgr/test/authenticate.sjs | 12 ++- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 modules/plugin/test/mochitest/test_getauthenticationinfo.html diff --git a/modules/plugin/test/mochitest/Makefile.in b/modules/plugin/test/mochitest/Makefile.in index 94b7549d3136..344110652c92 100644 --- a/modules/plugin/test/mochitest/Makefile.in +++ b/modules/plugin/test/mochitest/Makefile.in @@ -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 \ diff --git a/modules/plugin/test/mochitest/test_getauthenticationinfo.html b/modules/plugin/test/mochitest/test_getauthenticationinfo.html new file mode 100644 index 000000000000..8cf711c5e4eb --- /dev/null +++ b/modules/plugin/test/mochitest/test_getauthenticationinfo.html @@ -0,0 +1,75 @@ + + + + Test for Login Manager + + + + + +Test for NPN_GetAuthenticationInfo +

+ +
+ +
+ + + + diff --git a/modules/plugin/test/testplugin/README b/modules/plugin/test/testplugin/README index 7ed9e797b28c..f679bcb8002e 100644 --- a/modules/plugin/test/testplugin/README +++ b/modules/plugin/test/testplugin/README @@ -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 == diff --git a/modules/plugin/test/testplugin/nptest.cpp b/modules/plugin/test/testplugin/nptest.cpp index a48d57760091..10688ac07ca7 100644 --- a/modules/plugin/test/testplugin/nptest.cpp +++ b/modules/plugin/test/testplugin/nptest.cpp @@ -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(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; +} diff --git a/toolkit/components/passwordmgr/test/authenticate.sjs b/toolkit/components/passwordmgr/test/authenticate.sjs index 284aebda3fba..7c2102fd0dbb 100644 --- a/toolkit/components/passwordmgr/test/authenticate.sjs +++ b/toolkit/components/passwordmgr/test/authenticate.sjs @@ -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("This is a footnote after the huge content fill"); } + if (plugin) { + response.write("\n"); + } + response.write(""); }