Merge lp:~mardy/online-accounts-api/apparmor-1489489 into lp:online-accounts-api

Proposed by Alberto Mardegan
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 27
Merged at revision: 34
Proposed branch: lp:~mardy/online-accounts-api/apparmor-1489489
Merge into: lp:online-accounts-api
Diff against target: 157 lines (+51/-24)
4 files modified
src/lib/OnlineAccountsDaemon/client_registry.cpp (+16/-6)
tests/daemon/functional_tests/dbus_apparmor.py (+28/-14)
tests/daemon/functional_tests/fake_dbus_apparmor.h (+3/-3)
tests/daemon/functional_tests/functional_tests.cpp (+4/-1)
To merge this branch: bzr merge lp:~mardy/online-accounts-api/apparmor-1489489
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
Review via email: mp+307560@code.launchpad.net

Commit message

Use GetConnectionCredentials() method instead of the deprecated apparmor-specific method.

Description of the change

Use GetConnectionCredentials() method instead of the deprecated apparmor-specific method.

To post a comment you must log in.
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

LGTM

review: Approve
28. By Alberto Mardegan

Merge from trunk
* Fix reply of password-based authentication (LP: #1628473)
* debian/control:
  - Depend on qttools5-dev-tools for qdoc (LP: #1608814)
* debian/rules:
  - No need to invoke dh_python

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lib/OnlineAccountsDaemon/client_registry.cpp'
2--- src/lib/OnlineAccountsDaemon/client_registry.cpp 2015-09-03 10:41:07 +0000
3+++ src/lib/OnlineAccountsDaemon/client_registry.cpp 2016-10-13 13:42:31 +0000
4@@ -20,12 +20,15 @@
5
6 #include "client_registry.h"
7
8+#include <QByteArray>
9 #include <QDBusConnection>
10 #include <QDBusConnectionInterface>
11 #include <QDBusMessage>
12+#include <QDBusReply>
13 #include <QDBusServiceWatcher>
14 #include <QDebug>
15 #include <QHash>
16+#include <QVariantMap>
17 #include <sys/apparmor.h>
18
19 using namespace OnlineAccountsDaemon;
20@@ -91,18 +94,25 @@
21 QDBusMessage::createMethodCall(dbusService,
22 "/org/freedesktop/DBus",
23 "org.freedesktop.DBus",
24- "GetConnectionAppArmorSecurityContext");
25+ "GetConnectionCredentials");
26 msg << client;
27- QDBusMessage reply = m_connection.call(msg, QDBus::Block);
28+ QDBusReply<QVariantMap> reply = m_connection.call(msg, QDBus::Block);
29
30 QString context;
31- if (reply.type() == QDBusMessage::ReplyMessage) {
32- context = reply.arguments().value(0).value<QString>();
33+ if (reply.isValid()) {
34+ QVariantMap map = reply.value();
35+ QByteArray label = map.value("LinuxSecurityLabel").toByteArray();
36+ if (!label.isEmpty()) {
37+ aa_splitcon(label.data(), NULL);
38+ context = QString::fromUtf8(label);
39+ }
40 } else {
41- qWarning() << "Could not determine AppArmor context: " <<
42- reply.errorName() << ": " << reply.errorMessage();
43+ QDBusError error = reply.error();
44+ qWarning() << "Error getting app ID:" << error.name() <<
45+ error.message();
46 context = QStringLiteral("unconfined");
47 }
48+ qDebug() << "Client security context:" << context;
49
50 return context;
51 }
52
53=== modified file 'tests/daemon/functional_tests/dbus_apparmor.py'
54--- tests/daemon/functional_tests/dbus_apparmor.py 2015-07-23 13:57:48 +0000
55+++ tests/daemon/functional_tests/dbus_apparmor.py 2016-10-13 13:42:31 +0000
56@@ -1,4 +1,7 @@
57-'''D-Bus mock template for GetConnectionAppArmorSecurityContext
58+'''dbus mock template
59+
60+This creates the expected methods and properties of the
61+org.freedesktop.DBus service.
62 '''
63
64 # This program is free software; you can redistribute it and/or modify it under
65@@ -9,28 +12,39 @@
66
67 __author__ = 'Alberto Mardegan'
68 __email__ = 'alberto.mardegan@canonical.com'
69-__copyright__ = '(c) 2015 Canonical Ltd.'
70+__copyright__ = '(c) 2016 Canonical Ltd.'
71 __license__ = 'LGPL 3+'
72
73 import dbus
74+import time
75
76 from dbusmock import MOCK_IFACE
77+import dbusmock
78
79 BUS_NAME = 'mocked.org.freedesktop.dbus'
80 MAIN_OBJ = '/org/freedesktop/DBus'
81 MAIN_IFACE = 'org.freedesktop.DBus'
82 SYSTEM_BUS = False
83
84+ERROR_PREFIX = 'org.freedesktop.DBus.Error.'
85+ERROR_NAME_HAS_NO_OWNER = ERROR_PREFIX + 'NameHasNoOwner'
86+
87+def get_credentials(self, service):
88+ if service not in self.credentials:
89+ raise dbus.exceptions.DBusException('Service not found',
90+ name=ERROR_NAME_HAS_NO_OWNER)
91+ return self.credentials[service]
92+
93+
94 def load(mock, parameters):
95- mock.AddMethod(MAIN_IFACE,
96- 'GetConnectionAppArmorSecurityContext',
97- 's', 's',
98- 'ret = self.contexts.get(args[0], "unconfined")')
99-
100- mock.contexts = {}
101-
102-@dbus.service.method(MOCK_IFACE, in_signature='ss', out_signature='')
103-def AddClient(self, client, context):
104- '''Adds a client with its security context'''
105- self.contexts[client] = context
106-
107+ mock.get_credentials = get_credentials
108+ mock.AddMethods(MAIN_IFACE, [
109+ ('GetConnectionCredentials', 's', 'a{sv}', 'ret = self.get_credentials(self, args[0])'),
110+ ])
111+
112+ mock.credentials = {}
113+
114+
115+@dbus.service.method(MOCK_IFACE, in_signature='sa{sv}', out_signature='')
116+def SetCredentials(self, service, credentials):
117+ self.credentials[service] = credentials
118
119=== modified file 'tests/daemon/functional_tests/fake_dbus_apparmor.h'
120--- tests/daemon/functional_tests/fake_dbus_apparmor.h 2015-07-23 13:57:48 +0000
121+++ tests/daemon/functional_tests/fake_dbus_apparmor.h 2016-10-13 13:42:31 +0000
122@@ -21,7 +21,7 @@
123 #ifndef OAD_FAKE_DBUS_APPARMOR_H
124 #define OAD_FAKE_DBUS_APPARMOR_H
125
126-#include <QString>
127+#include <QVariantMap>
128 #include <libqtdbusmock/DBusMock.h>
129
130 class FakeDBusApparmor
131@@ -33,8 +33,8 @@
132 QDBusConnection::SessionBus);
133 }
134
135- void addClient(const QString &client, const QString context) {
136- mocked().call("AddClient", client, context);
137+ void setCredentials(const QString &service, const QVariantMap &credentials) {
138+ mocked().call("SetCredentials", service, credentials);
139 }
140
141 private:
142
143=== modified file 'tests/daemon/functional_tests/functional_tests.cpp'
144--- tests/daemon/functional_tests/functional_tests.cpp 2016-09-28 13:09:06 +0000
145+++ tests/daemon/functional_tests/functional_tests.cpp 2016-10-13 13:42:31 +0000
146@@ -308,7 +308,10 @@
147 DaemonInterface *daemon = new DaemonInterface(m_dbus->sessionConnection());
148
149 TestProcess testProcess;
150- m_dbus->dbusApparmor().addClient(testProcess.uniqueName(), securityContext);
151+ QVariantMap credentials {
152+ { "LinuxSecurityLabel", securityContext.toUtf8() },
153+ };
154+ m_dbus->dbusApparmor().setCredentials(testProcess.uniqueName(), credentials);
155
156 QList<AccountInfo> accountInfos = testProcess.getAccounts(filters);
157 QList<int> accountIds;

Subscribers

People subscribed via source and target branches