Beispiel #1
0
void KDEPrintd::processRequest()
{
    if(m_requestsPending.count() == 0)
        return;

    Request *req = m_requestsPending.first();
    KIO::AuthInfo info;
    QByteArray params, reply;
    QCString replyType;
    QString authString("::");

    info.username = req->user;
    info.keepPassword = true;
    info.url = req->uri;
    info.comment = i18n("Printing system");

    QDataStream input(params, IO_WriteOnly);
    input << info << i18n("Authentication failed (user name=%1)").arg(info.username) << 0L << (long int)req->seqNbr;
    if(callingDcopClient()->call("kded", "kpasswdserver", "queryAuthInfo(KIO::AuthInfo,QString,long int,long int)", params, replyType, reply))
    {
        if(replyType == "KIO::AuthInfo")
        {
            QDataStream output(reply, IO_ReadOnly);
            KIO::AuthInfo result;
            int seqNbr;
            output >> result >> seqNbr;

            if(result.isModified())
                authString = result.username + ":" + result.password + ":" + QString::number(seqNbr);
        }
        else
Beispiel #2
0
    void simpleTest()
    {
        KPasswdServer server(this);
        server.setWalletDisabled(true);

        // Check that processRequest doesn't crash when it has nothing to do
        server.processRequest();

        KIO::AuthInfo info;
        info.url = QUrl(QStringLiteral("http://www.example.com"));

        // Make a check for that host, should say "not found"
        QVERIFY(noCheckAuth(server, info));

        // Now add auth to the cache
        const qlonglong windowId = 42;
        KIO::AuthInfo realInfo = info;
        realInfo.username = QStringLiteral("toto"); // you can see I'm french
        realInfo.password = QStringLiteral("foobar");
        server.addAuthInfo(realInfo, windowId); // seqnr=2

        // queryAuth without the ability to prompt, will just return info unmodified
        KIO::AuthInfo resultInfo;
        queryAuth(server, info, resultInfo);
        QCOMPARE(resultInfo.url, info.url);
        QCOMPARE(resultInfo.username, QString());
        QCOMPARE(resultInfo.password, QString());
        QCOMPARE(resultInfo.isModified(), false);

        // Check that checkAuth finds it
        QVERIFY(successCheckAuth(server, info, realInfo));

        // Now remove auth
        server.removeAuthInfo(info.url.host(), info.url.scheme(), info.username);
        // Check we can't find that auth anymore
        QVERIFY(noCheckAuth(server, info));
    }