Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #48 from nemomobile/jb32346
Allow defining url domains to be used with specific credentials
  • Loading branch information
saukko committed Sep 21, 2015
2 parents 53a40e2 + fff0d58 commit 8a44464
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,8 @@ doc/latex
/rndssucli/ssuproxy.h
/.nodocs
ssucli/ssuproxy.h
*.o
RPMS/
installroot/
moc_*.cpp
qrc_*.cpp
13 changes: 13 additions & 0 deletions libssu/ssu.cpp
Expand Up @@ -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,
Expand All @@ -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<QString, QString> secureDomainAuth;
SsuVariables::variableSection(&repoSettings, "secure-domain-auth", &secureDomainAuth);
QHashIterator<QString, QString> 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);
}

Expand Down
1 change: 1 addition & 0 deletions tests/tests.pro
Expand Up @@ -7,6 +7,7 @@ SUBDIRS = \
ut_coreconfig \
ut_deviceinfo \
ut_repomanager \
ut_ssu \
ut_ssucli \
ut_sandbox \
ut_settings \
Expand Down
5 changes: 5 additions & 0 deletions tests/tests.xml
Expand Up @@ -18,6 +18,11 @@
<step expected_result="0">/opt/tests/ssu/runtest.sh ut_repomanager</step>
</case>
</set>
<set name="ssu" description="Test to determine if ssu library works properly" feature="ssu">
<case name="ut_ssu" type="Functional" description="ssu library" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/runtest.sh ut_ssu</step>
</case>
</set>
<set name="ssucli" description="Test to determine if ssu command line tool works properly" feature="ssucli">
<case name="ut_ssucli" type="Functional" description="ssu command line utility test" timeout="1000" subfeature="">
<step expected_result="0">/opt/tests/ssu/runtest.sh ut_ssucli</step>
Expand Down
26 changes: 26 additions & 0 deletions tests/ut_ssu/main.cpp
@@ -0,0 +1,26 @@
/**
* @file main.cpp
* @copyright 2012 Jolla Ltd.
* @author Martin Kampas <martin.kampas@tieto.com>
* @date 2012
*/

#include <QtTest/QtTest>

#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;
}
67 changes: 67 additions & 0 deletions tests/ut_ssu/ssutest.cpp
@@ -0,0 +1,67 @@
/**
* @file repomanagertest.cpp
* @copyright 2015 Jolla Ltd.
* @author Marko Saukko <marko.saukko@jolla.com>
* @date 2015
* @todo Add unit tests for other ssu lib functions.
*/

#include "ssutest.h"

#include <QtTest/QtTest>

#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"));
}

28 changes: 28 additions & 0 deletions tests/ut_ssu/ssutest.h
@@ -0,0 +1,28 @@
/**
* @file repomanagertest.h
* @copyright 2015 Jolla Ltd.
* @author Marko Saukko <marko.saukko@jolla.com>
* @date 2015
*/

#ifndef _SSUTEST_H
#define _SSUTEST_H

#include <QObject>
#include <QStringList>

#include "libssu/ssu.h"

class SsuTest: public QObject {
Q_OBJECT

private slots:
void initTestCase();
void testCredentialsScope();
void testCredentialsScopeStoreAuthRepos();
void testCredentialsScopeSecureDomainAuth();
private:
Ssu ssu;
};

#endif
45 changes: 45 additions & 0 deletions 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

3 changes: 3 additions & 0 deletions tests/ut_ssu/testdata/ssu.ini
@@ -0,0 +1,3 @@
[General]
credentials-scope=vendor

17 changes: 17 additions & 0 deletions 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 \

1 change: 1 addition & 0 deletions tests/ut_ssu/ut_ssu_dependencies.pri
@@ -0,0 +1 @@
include(../../libssu/libssu.pri)

0 comments on commit 8a44464

Please sign in to comment.