diff --git a/.gitignore b/.gitignore index 9cf57a4..4ff3d94 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,8 @@ doc/latex /rndssucli/ssuproxy.h /.nodocs ssucli/ssuproxy.h +*.o +RPMS/ +installroot/ +moc_*.cpp +qrc_*.cpp diff --git a/libssu/ssu.cpp b/libssu/ssu.cpp index 93c7491..cb1ece5 100644 --- a/libssu/ssu.cpp +++ b/libssu/ssu.cpp @@ -98,6 +98,7 @@ QString Ssu::credentialsScope(QString repoName, bool rndRepo){ SsuVariables::variable(&repoSettings, domain() + "-domain", storeAuthReposKey).toStringList(); + if (storeAuthRepos.empty()) storeAuthRepos = SsuVariables::variable(&repoSettings, @@ -107,6 +108,18 @@ QString Ssu::credentialsScope(QString repoName, bool rndRepo){ if (storeAuthRepos.contains(repoName)) return "store"; + // If we defined explicitly what credentials to use with which secure domain + // use those. + QHash secureDomainAuth; + SsuVariables::variableSection(&repoSettings, "secure-domain-auth", &secureDomainAuth); + QHashIterator i(secureDomainAuth); + while (i.hasNext()) { + i.next(); + if (repoUrl(repoName, rndRepo).contains(i.key()) && !i.value().isEmpty()) { + return i.value(); + } + } + return settings->credentialsScope(repoName, rndRepo); } diff --git a/tests/tests.pro b/tests/tests.pro index 7fe0a0a..5f27299 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -7,6 +7,7 @@ SUBDIRS = \ ut_coreconfig \ ut_deviceinfo \ ut_repomanager \ + ut_ssu \ ut_ssucli \ ut_sandbox \ ut_settings \ diff --git a/tests/tests.xml b/tests/tests.xml index 247ceb0..ea0402b 100644 --- a/tests/tests.xml +++ b/tests/tests.xml @@ -18,6 +18,11 @@ /opt/tests/ssu/runtest.sh ut_repomanager + + + /opt/tests/ssu/runtest.sh ut_ssu + + /opt/tests/ssu/runtest.sh ut_ssucli diff --git a/tests/ut_ssu/main.cpp b/tests/ut_ssu/main.cpp new file mode 100644 index 0000000..6ffd4a5 --- /dev/null +++ b/tests/ut_ssu/main.cpp @@ -0,0 +1,26 @@ +/** + * @file main.cpp + * @copyright 2012 Jolla Ltd. + * @author Martin Kampas + * @date 2012 + */ + +#include + +#include "libssu/sandbox_p.h" +#include "ssutest.h" + +int main(int argc, char **argv){ + Sandbox sandbox(QString("%1/configroot").arg(LOCATE_DATA_PATH), + Sandbox::UseAsSkeleton, Sandbox::ThisProcess); + if (!sandbox.activate()){ + qFatal("Failed to activate sandbox"); + } + + SsuTest ssuTest; + + if (QTest::qExec(&ssuTest, argc, argv)) + return 1; + + return 0; +} diff --git a/tests/ut_ssu/ssutest.cpp b/tests/ut_ssu/ssutest.cpp new file mode 100644 index 0000000..965122e --- /dev/null +++ b/tests/ut_ssu/ssutest.cpp @@ -0,0 +1,67 @@ +/** + * @file repomanagertest.cpp + * @copyright 2015 Jolla Ltd. + * @author Marko Saukko + * @date 2015 + * @todo Add unit tests for other ssu lib functions. + */ + +#include "ssutest.h" + +#include + +#include "libssu/ssucoreconfig_p.h" +#include "libssu/ssurepomanager.h" +#include "libssu/ssu.h" + +void SsuTest::initTestCase(){ +} + +void SsuTest::testCredentialsScope(){ + // For store repo store is returned always no matter what + QCOMPARE(ssu.credentialsScope(QString("store")),QString("store")); + QCOMPARE(ssu.credentialsScope(QString("store-c-example")),QString("store")); + + ssu.setDomain(QString("default")); + QCOMPARE(ssu.domain(),QString("default")); + + QCOMPARE(ssu.credentialsScope(QString("store")),QString("store")); + QCOMPARE(ssu.credentialsScope(QString("apps")),QString("vendor")); + QCOMPARE(ssu.credentialsScope(QString("vendor")),QString("vendor")); + + QCOMPARE(ssu.credentialsScope(QString("store"),true),QString("store")); + QCOMPARE(ssu.credentialsScope(QString("adaptation"),true),QString("vendor")); + QCOMPARE(ssu.credentialsScope(QString("oss"),true),QString("vendor")); +} + +void SsuTest::testCredentialsScopeStoreAuthRepos() { + ssu.setDomain(QString("example")); + QCOMPARE(ssu.domain(),QString("example")); + + QCOMPARE(ssu.credentialsScope(QString("store")),QString("store")); + // store-auth-repos=apps in example domain + QCOMPARE(ssu.credentialsScope(QString("apps")),QString("store")); + QCOMPARE(ssu.credentialsScope(QString("vendor")),QString("vendor")); + + QCOMPARE(ssu.credentialsScope(QString("store"),true),QString("store")); + QCOMPARE(ssu.credentialsScope(QString("adaptation"),true),QString("vendor")); + QCOMPARE(ssu.credentialsScope(QString("oss"),true),QString("vendor")); +} + +void SsuTest::testCredentialsScopeSecureDomainAuth(){ + // [secure-domain-auth] + // packages.example2.com=example2 + + ssu.setDomain("example2"); + QCOMPARE(ssu.domain(),QString("example2")); + + QCOMPARE(ssu.credentialsScope(QString("store"),false),QString("store")); + QCOMPARE(ssu.credentialsScope(QString("apps"),false),QString("example2")); + QCOMPARE(ssu.credentialsScope(QString("vendor"),false),QString("example2")); + + // adaptation uses packages.example2.com + QCOMPARE(ssu.credentialsScope(QString("adaptation"),true),QString("example2")); + // oss uses dump.example2.com, thus vendor + QCOMPARE(ssu.credentialsScope(QString("oss"),true),QString("vendor")); +} + diff --git a/tests/ut_ssu/ssutest.h b/tests/ut_ssu/ssutest.h new file mode 100644 index 0000000..6ed0ff5 --- /dev/null +++ b/tests/ut_ssu/ssutest.h @@ -0,0 +1,28 @@ +/** + * @file repomanagertest.h + * @copyright 2015 Jolla Ltd. + * @author Marko Saukko + * @date 2015 + */ + +#ifndef _SSUTEST_H +#define _SSUTEST_H + +#include +#include + +#include "libssu/ssu.h" + +class SsuTest: public QObject { + Q_OBJECT + + private slots: + void initTestCase(); + void testCredentialsScope(); + void testCredentialsScopeStoreAuthRepos(); + void testCredentialsScopeSecureDomainAuth(); + private: + Ssu ssu; +}; + +#endif diff --git a/tests/ut_ssu/testdata/repos.ini b/tests/ut_ssu/testdata/repos.ini new file mode 100644 index 0000000..2d94dd8 --- /dev/null +++ b/tests/ut_ssu/testdata/repos.ini @@ -0,0 +1,45 @@ +[all] +credentials=vendor +store=https://%(packagesDomain)/store/ + +[release] +vendor=https://%(packagesDomain)/releases/%(release)/vendor/%(arch)/ +apps=https://%(packagesDomain)/releases/%(release)/vendor-apps/%(arch)/ + +[rnd] +mer-core=https://%(packagesDomain)/mer/%(release)/builds/%(arch)/%(debugSplit)/ +adaptation=https://%(packagesDomain)/nemo/%(release)/adaptation-%(deviceFamily)/%(arch)/ +nemo=https://%(packagesDomain)/nemo/%(release)/platform/%(arch)/ +non-oss=https://%(dumpDomain)/pj:/non-oss%(flavour)/%(release)_%(arch)/ +oss=https://%(dumpDomain)/pj:/oss%(flavour)/%(release)_%(arch)/ + +[devel-flavour] +flavour-pattern= + +[release-flavour] +flavour-pattern=:/release + +[testing-flavour] +flavour-pattern=:/testing + +[example-domain] +dumpDomain=dump.example.com +packagesDomain=packages.example.com +store-auth-repos=apps + +[example2-domain] +dumpDomain=dump.example2.com +packagesDomain=packages.example2.com + +# fallback if domain is not matched or not set +[default-domain] +dumpDomain=dump.testing.com +packagesDomain=packages.testing.com + +[default-repos] +release=vendor,apps +rnd=mer-core,adaptation,nemo,non-oss,oss + +[secure-domain-auth] +packages.example2.com=example2 + diff --git a/tests/ut_ssu/testdata/ssu.ini b/tests/ut_ssu/testdata/ssu.ini new file mode 100644 index 0000000..1fb51a4 --- /dev/null +++ b/tests/ut_ssu/testdata/ssu.ini @@ -0,0 +1,3 @@ +[General] +credentials-scope=vendor + diff --git a/tests/ut_ssu/ut_ssu.pro b/tests/ut_ssu/ut_ssu.pro new file mode 100644 index 0000000..53b69ad --- /dev/null +++ b/tests/ut_ssu/ut_ssu.pro @@ -0,0 +1,17 @@ +TARGET = ut_ssu +include(../testapplication.pri) +include(ut_ssu_dependencies.pri) + +HEADERS = \ + ssutest.h \ + +SOURCES = \ + main.cpp \ + ssutest.cpp \ + +test_data_etc.files = \ + testdata/ssu.ini \ + +test_data_usr_share.files = \ + testdata/repos.ini \ + diff --git a/tests/ut_ssu/ut_ssu_dependencies.pri b/tests/ut_ssu/ut_ssu_dependencies.pri new file mode 100644 index 0000000..37c741f --- /dev/null +++ b/tests/ut_ssu/ut_ssu_dependencies.pri @@ -0,0 +1 @@ +include(../../libssu/libssu.pri)