Skip to content

Commit

Permalink
ut_urlresolver: add checkSetCredentials()
Browse files Browse the repository at this point in the history
  • Loading branch information
martyone committed Apr 9, 2013
1 parent a4fb6d3 commit 1a26540
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libssu/ssu.h
Expand Up @@ -23,6 +23,8 @@ class QNetworkReply;
class Ssu: public QObject {
Q_OBJECT

friend class UrlResolverTest;

public:
Ssu();
/**
Expand Down
66 changes: 66 additions & 0 deletions tests/ut_urlresolver/urlresolvertest.cpp
Expand Up @@ -124,4 +124,70 @@ void UrlResolverTest::checkReleaseRepoUrls(){
}
}

void UrlResolverTest::checkSetCredentials(){
QDomDocument doc("foo");

QDomElement root = doc.createElement("foo");
doc.appendChild(root);

QDomElement credentials1 = doc.createElement("credentials");
root.appendChild(credentials1);

QVERIFY2(!ssu.setCredentials(&doc),
"Ssu::setCredentials() should fail when 'scope' is not defined");

credentials1.setAttribute("scope", "utscope1");

QVERIFY2(!ssu.setCredentials(&doc),
"Ssu::setCredentials() should fail when username/password is missing");

QDomElement username1 = doc.createElement("username");
credentials1.appendChild(username1);
username1.appendChild(doc.createTextNode("john.doe1"));

QVERIFY2(!ssu.setCredentials(&doc),
"Ssu::setCredentials() should fail when password is missing");

QDomElement password1 = doc.createElement("password");
credentials1.appendChild(password1);
password1.appendChild(doc.createTextNode("SeCrEt1"));

QVERIFY2(ssu.setCredentials(&doc),
qPrintable(QString("setCredentials() failed: %1").arg(ssu.lastError())));

QVERIFY2(ssu.lastCredentialsUpdate() > QDateTime::currentDateTime().addSecs(-5) &&
ssu.lastCredentialsUpdate() <= QDateTime::currentDateTime(),
"Ssu::lastCredentialsUpdate was not updated");

//QVERIFY(ssu.credentialScopes().contains("utscope1"));
QCOMPARE(ssu.credentials("utscope1").first, QString("john.doe1"));
QCOMPARE(ssu.credentials("utscope1").second, QString("SeCrEt1"));


QDomElement credentials2 = doc.createElement("credentials");
root.appendChild(credentials2);
credentials2.setAttribute("scope", "utscope2");

QDomElement username2 = doc.createElement("username");
credentials2.appendChild(username2);
username2.appendChild(doc.createTextNode("john.doe2"));

QDomElement password2 = doc.createElement("password");
credentials2.appendChild(password2);
password2.appendChild(doc.createTextNode("SeCrEt2"));

QVERIFY2(ssu.setCredentials(&doc),
qPrintable(QString("setCredentials() failed: %1").arg(ssu.lastError())));

QVERIFY2(ssu.lastCredentialsUpdate() > QDateTime::currentDateTime().addSecs(-5) &&
ssu.lastCredentialsUpdate() <= QDateTime::currentDateTime(),
"Ssu::lastCredentialsUpdate was not updated");

//QVERIFY(ssu.credentialScopes().contains("utscope1"));
QCOMPARE(ssu.credentials("utscope1").first, QString("john.doe1"));
QCOMPARE(ssu.credentials("utscope1").second, QString("SeCrEt1"));

//QVERIFY(ssu.credentialScopes().contains("utscope2"));
QCOMPARE(ssu.credentials("utscope2").first, QString("john.doe2"));
QCOMPARE(ssu.credentials("utscope2").second, QString("SeCrEt2"));
}
1 change: 1 addition & 0 deletions tests/ut_urlresolver/urlresolvertest.h
Expand Up @@ -26,6 +26,7 @@ class UrlResolverTest: public QObject {
void checkCleanUrl();
void simpleRepoUrlLookup();
void checkReleaseRepoUrls();
void checkSetCredentials();

private:
Ssu ssu;
Expand Down
2 changes: 2 additions & 0 deletions tests/ut_urlresolver/ut_urlresolver.pro
Expand Up @@ -2,6 +2,8 @@ TARGET = ut_urlresolver
include(../testapplication.pri)
include(ut_urlresolver_dependencies.pri)

QT += xml

HEADERS = urlresolvertest.h
SOURCES = main.cpp \
urlresolvertest.cpp
Expand Down

0 comments on commit 1a26540

Please sign in to comment.