Merge lp:~indicator-applet-developers/indicator-network/secret-agent into lp:indicator-network/13.10

Proposed by Pete Woods
Status: Merged
Approved by: Charles Kerr
Approved revision: no longer in the source branch.
Merged at revision: 276
Proposed branch: lp:~indicator-applet-developers/indicator-network/secret-agent
Merge into: lp:indicator-network/13.10
Diff against target: 1669 lines (+1333/-127)
25 files modified
CMakeLists.txt (+35/-6)
cmake/FindGMock.cmake (+10/-0)
cmake/FindValgrind.cmake (+34/-0)
config.h.in (+2/-1)
data/CMakeLists.txt (+17/-2)
data/indicator-secret-agent.conf.in (+8/-0)
data/nm-agent-manager.xml (+38/-0)
data/nm-secret-agent.xml (+190/-0)
debian/control (+16/-12)
network/CMakeLists.txt (+0/-1)
secret-agent/CMakeLists.txt (+59/-0)
secret-agent/DBusTypes.h (+37/-0)
secret-agent/Localisation.h (+28/-0)
secret-agent/SecretAgent.cpp (+136/-0)
secret-agent/SecretAgent.h (+81/-0)
secret-agent/SecretAgentInclude.h (+25/-0)
secret-agent/SecretRequest.cpp (+65/-0)
secret-agent/SecretRequest.h (+71/-0)
secret-agent/main.cpp (+54/-0)
test/network.py (+0/-105)
tests/CMakeLists.txt (+61/-0)
tests/TestIndicatorNetworkService.cpp (+60/-0)
tests/TestSecretAgent.cpp (+167/-0)
tests/data/valgrind.suppression (+95/-0)
tests/main.cpp (+44/-0)
To merge this branch: bzr merge lp:~indicator-applet-developers/indicator-network/secret-agent
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+182421@code.launchpad.net

Commit message

Move the secret agent code over into this package

Description of the change

Move the secret agent code over into this package

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
275. By PS Jenkins bot

Releasing 0.5.0+13.10.20130827.3-0ubuntu1 (revision 273 from lp:indicator-network).

Approved by PS Jenkins bot.

Revision history for this message
Charles Kerr (charlesk) wrote :

> W: Failed to fetch bzip2:/var/lib/apt/lists/partial/ppa.launchpad.net_ubuntu-unity_daily-build_ubuntu_dists_saucy_main_binary-armhf_Packages Hash Sum mismatch

That's not right. Kicking off a rebuild.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) :
review: Approve
276. By Pete Woods

Move the secret agent code over into this package.

Approved by Charles Kerr, PS Jenkins bot.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-08-27 13:48:41 +0000
3+++ CMakeLists.txt 2013-08-27 16:07:33 +0000
4@@ -5,7 +5,7 @@
5
6 set(PACKAGE ${CMAKE_PROJECT_NAME})
7 set(GETTEXT_PACKAGE ${CMAKE_PROJECT_NAME})
8-set(GNOMELOCALEDIR "${CMAKE_INSTALL_FULL_DATADIR}/locale")
9+set(LOCALE_DIR "${CMAKE_INSTALL_FULL_DATADIR}/locale")
10
11 add_definitions( -DGETTEXT_PACKAGE="${GETTEXT_PACKAGE}" )
12
13@@ -20,8 +20,7 @@
14 set(CMAKE_INSTALL_FULL_LIBEXECDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}")
15 endif()
16
17-set(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")
18-set(SOURCE_BINARY_DIR "${CMAKE_BINARY_DIR}/src")
19+set(DATA_DIR "${CMAKE_SOURCE_DIR}/data")
20
21 set(GLIB_REQUIRED_VERSION 2.26)
22
23@@ -41,12 +40,36 @@
24 )
25 include_directories(${NM_INCLUDE_DIRS})
26
27+
28+find_package(Qt5Core REQUIRED)
29+include_directories(${Qt5Core_INCLUDE_DIRS})
30+
31+find_package(Qt5DBus COMPONENTS Qt5DBusMacros REQUIRED)
32+include_directories(${Qt5DBus_INCLUDE_DIRS})
33+
34+find_package(Qt5Test REQUIRED)
35+include_directories(${Qt5Test_INCLUDE_DIRS})
36+
37+pkg_check_modules(NM REQUIRED NetworkManager REQUIRED)
38+include_directories(${NM_INCLUDE_DIRS})
39+
40+pkg_check_modules(QTDBUSTEST REQUIRED libqtdbustest-1 REQUIRED)
41+include_directories(${QTDBUSTEST_INCLUDE_DIRS})
42+
43+pkg_check_modules(QTDBUSMOCK REQUIRED libqtdbusmock-1 REQUIRED)
44+include_directories(${QTDBUSMOCK_INCLUDE_DIRS})
45+
46+pkg_check_modules(QMENUMODEL REQUIRED qmenumodel REQUIRED)
47+include_directories(${QMENUMODEL_INCLUDE_DIRS})
48+
49+set(CMAKE_AUTOMOC ON)
50+set(CMAKE_INCLUDE_CURRENT_DIR ON)
51+
52 find_package(Vala 0.18)
53
54 find_package(GObjectIntrospection 0.9.12)
55
56-include_directories(${SOURCE_DIR})
57-include_directories(${SOURCE_BINARY_DIR})
58+include_directories(${CMAKE_BINARY_DIR})
59
60 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
61 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
62@@ -57,12 +80,18 @@
63
64 configure_file(
65 "config.h.in"
66- "${CMAKE_CURRENT_BINARY_DIR}/config.h"
67+ "config.h"
68 )
69
70 add_subdirectory(data)
71 add_subdirectory(network)
72+add_subdirectory(secret-agent)
73
74 enable_testing()
75 add_subdirectory(tests)
76
77+ADD_CUSTOM_TARGET(
78+ check
79+ ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure
80+)
81+
82
83=== added file 'cmake/FindGMock.cmake'
84--- cmake/FindGMock.cmake 1970-01-01 00:00:00 +0000
85+++ cmake/FindGMock.cmake 2013-08-27 16:07:33 +0000
86@@ -0,0 +1,10 @@
87+# Build with system gmock and embedded gtest
88+set (GMOCK_INCLUDE_DIRS "/usr/include/gmock/include" CACHE PATH "gmock source include directory")
89+set (GMOCK_SOURCE_DIR "/usr/src/gmock" CACHE PATH "gmock source directory")
90+set (GTEST_INCLUDE_DIRS "${GMOCK_SOURCE_DIR}/gtest/include" CACHE PATH "gtest source include directory")
91+
92+add_subdirectory(${GMOCK_SOURCE_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock")
93+
94+set(GTEST_LIBRARIES gtest)
95+set(GTEST_MAIN_LIBRARIES gtest_main)
96+set(GMOCK_LIBRARIES gmock gmock_main)
97
98=== added file 'cmake/FindValgrind.cmake'
99--- cmake/FindValgrind.cmake 1970-01-01 00:00:00 +0000
100+++ cmake/FindValgrind.cmake 2013-08-27 16:07:33 +0000
101@@ -0,0 +1,34 @@
102+
103+option(
104+ ENABLE_MEMCHECK_OPTION
105+ "If set to ON, enables automatic creation of memcheck targets"
106+ OFF
107+)
108+
109+find_program(
110+ VALGRIND_PROGRAM
111+ NAMES valgrind
112+)
113+
114+if(VALGRIND_PROGRAM)
115+ set(VALGRIND_PROGRAM_OPTIONS
116+ "--suppressions=${CMAKE_SOURCE_DIR}/tests/data/valgrind.suppression"
117+ "--error-exitcode=1"
118+ "--leak-check=full"
119+ "--gen-suppressions=all"
120+ "--quiet"
121+ )
122+endif()
123+
124+find_package_handle_standard_args(
125+ VALGRIND DEFAULT_MSG
126+ VALGRIND_PROGRAM
127+)
128+
129+function(add_valgrind_test NAME EXECUTABLE)
130+ if(ENABLE_MEMCHECK_OPTION)
131+ add_test(${NAME} ${VALGRIND_PROGRAM} ${VALGRIND_PROGRAM_OPTIONS} "${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE}")
132+ else()
133+ add_test(${NAME} ${EXECUTABLE})
134+ endif()
135+endfunction()
136
137=== modified file 'config.h.in'
138--- config.h.in 2013-08-27 13:48:41 +0000
139+++ config.h.in 2013-08-27 16:07:33 +0000
140@@ -20,6 +20,7 @@
141 #define INDICATOR_NETWORK_CONFIG_H_
142
143 #define GETTEXT_PACKAGE "@GETTEXT_PACKAGE@"
144-#define GNOMELOCALEDIR "@GNOMELOCALEDIR@"
145+#define GNOMELOCALEDIR "@LOCALE_DIR@"
146+#define LOCALE_DIR "@LOCALE_DIR@"
147
148 #endif // INDICATOR_NETWORK_CONFIG_H_
149
150=== modified file 'data/CMakeLists.txt'
151--- data/CMakeLists.txt 2013-08-27 13:55:21 +0000
152+++ data/CMakeLists.txt 2013-08-27 16:07:33 +0000
153@@ -2,7 +2,7 @@
154 add_subdirectory(icons)
155
156 ###########################
157-# Indicator service
158+# Indicator-network service
159 ###########################
160
161 set(
162@@ -17,7 +17,7 @@
163 )
164
165 ###########################
166-# Upstart job
167+# Indicator-network upstart job
168 ###########################
169
170 set(
171@@ -36,3 +36,18 @@
172 DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/sessions/"
173 )
174
175+###########################
176+# Secret agent upstart job
177+###########################
178+
179+configure_file (
180+ indicator-secret-agent.conf.in
181+ indicator-secret-agent.conf
182+ @ONLY
183+)
184+
185+install (
186+ FILES ${CMAKE_CURRENT_BINARY_DIR}/indicator-secret-agent.conf
187+ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/upstart/sessions
188+)
189+
190
191=== added file 'data/indicator-secret-agent.conf.in'
192--- data/indicator-secret-agent.conf.in 1970-01-01 00:00:00 +0000
193+++ data/indicator-secret-agent.conf.in 2013-08-27 16:07:33 +0000
194@@ -0,0 +1,8 @@
195+description "Secret agent to repsond to Network Manager password requests"
196+
197+start on starting indicator-network
198+stop on stopping indicator-network
199+
200+respawn
201+
202+exec @CMAKE_INSTALL_FULL_LIBEXECDIR@/indicator-secret-agent
203
204=== added file 'data/nm-agent-manager.xml'
205--- data/nm-agent-manager.xml 1970-01-01 00:00:00 +0000
206+++ data/nm-agent-manager.xml 2013-08-27 16:07:33 +0000
207@@ -0,0 +1,38 @@
208+<?xml version="1.0" encoding="UTF-8" ?>
209+
210+<node name="/org/freedesktop/NetworkManager/AgentManager" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
211+ <interface name="org.freedesktop.NetworkManager.AgentManager">
212+
213+ <method name="Register">
214+ <tp:docstring>
215+ Called by secret Agents to register their ability to provide and save
216+ network secrets.
217+ </tp:docstring>
218+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_register"/>
219+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
220+ <arg name="identifier" type="s" direction="in">
221+ <tp:docstring>
222+ Identifies this agent; only one agent in each user session may use the
223+ same identifier. Identifier formatting follows the same rules as
224+ D-Bus bus names with the exception that the ':' character is not
225+ allowed. The valid set of characters is "[A-Z][a-z][0-9]_-." and the
226+ identifier is limited in length to 255 characters with a minimum
227+ of 3 characters. An example valid identifier is 'org.gnome.nm-applet'
228+ (without quotes).
229+ </tp:docstring>
230+ </arg>
231+ </method>
232+
233+ <method name="Unregister">
234+ <tp:docstring>
235+ Called by secret Agents to notify NetworkManager that they will no
236+ longer handle requests for network secrets. Agents are automatically
237+ unregistered when they disconnect from D-Bus.
238+ </tp:docstring>
239+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_agent_manager_unregister"/>
240+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
241+ </method>
242+
243+ </interface>
244+</node>
245+
246
247=== added file 'data/nm-secret-agent.xml'
248--- data/nm-secret-agent.xml 1970-01-01 00:00:00 +0000
249+++ data/nm-secret-agent.xml 2013-08-27 16:07:33 +0000
250@@ -0,0 +1,190 @@
251+<?xml version="1.0" encoding="UTF-8" ?>
252+
253+<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
254+
255+ <interface name="org.freedesktop.NetworkManager.SecretAgent">
256+ <tp:docstring>
257+ Private D-Bus interface used by secret agents that store and provide
258+ secrets to NetworkManager. If an agent provides secrets to
259+ NetworkManager as part of connection creation, and the some of those
260+ secrets are "agent owned" the agent should store those secrets
261+ itself and should not expect its SaveSecrets() method to be called.
262+ SaveSecrets() will be called eg if some program other than the
263+ agent itself (like a connection editor) changes the secrets out of
264+ band.
265+ </tp:docstring>
266+
267+ <method name="GetSecrets">
268+ <tp:docstring>
269+ Retrieve and return stored secrets, if any, or request new
270+ secrets from the agent's user. If user interaction is allowed
271+ and the user enters new secrets, the agent is expected to save
272+ the new secrets to persistent storage (if the secret's flags
273+ include AGENT_OWNED) as NetworkManager will not send these
274+ secrets back to the same agent via a SaveSecrets() call.
275+ </tp:docstring>
276+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_get_secrets"/>
277+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
278+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantDictMap"/>
279+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantDictMap"/>
280+ <arg name="connection" type="a{sa{sv}}" direction="in" tp:type="String_String_Variant_Map_Map">
281+ <tp:docstring>
282+ Nested settings maps containing the connection for which
283+ secrets are being requested. This may contain system-owned
284+ secrets if the agent has successfully authenticated to
285+ modify system network settings and the GetSecrets request
286+ flags allow user interaction.
287+ </tp:docstring>
288+ </arg>
289+ <arg name="connection_path" type="o" direction="in">
290+ <tp:docstring>
291+ Object path of the connection for which secrets are being
292+ requested.
293+ </tp:docstring>
294+ </arg>
295+ <arg name="setting_name" type="s" direction="in">
296+ <tp:docstring>
297+ Setting name for which secrets are being requested.
298+ </tp:docstring>
299+ </arg>
300+ <arg name="hints" type="as" direction="in">
301+ <tp:docstring>
302+ Array of strings of key names in the requested setting for
303+ which NetworkManager thinks a secrets may be required,
304+ and/or well-known identifiers and data that may be useful
305+ to the client in processing the secrets request. Note that
306+ it's not always possible to determine which secret is
307+ required, so in some cases no hints may be given. The Agent
308+ should return any secrets it has, or that it thinks are
309+ required, regardless of what hints NetworkManager sends
310+ in this request.
311+ </tp:docstring>
312+ </arg>
313+ <arg name="flags" type="u" direction="in" tp:type="NM_SECRET_AGENT_GET_SECRETS_FLAGS">
314+ <tp:docstring>
315+ Flags which modify the behavior of the secrets request.
316+ If true, new secrets are assumed to be invalid or incorrect,
317+ and the agent should ask the user for new secrets. If false,
318+ existing secrets should be retrieved from storage and
319+ returned without interrupting the user.
320+ </tp:docstring>
321+ </arg>
322+
323+ <arg name="secrets" type="a{sa{sv}}" direction="out" tp:type="String_String_Variant_Map_Map">
324+ <tp:docstring>
325+ Nested settings maps containing secrets. Each setting MUST
326+ contain at least the 'name' field, containing the name of
327+ the setting, and one or more secrets.
328+ </tp:docstring>
329+ </arg>
330+ </method>
331+
332+ <tp:flags name="NM_SECRET_AGENT_GET_SECRETS_FLAGS" value-prefix="NM_SECRET_AGENT_GET_SECRETS_FLAG" type="u">
333+ <tp:docstring>
334+ Flags modifying the behavior of GetSecrets request.
335+ </tp:docstring>
336+ <tp:flag suffix="NONE" value="0x0">
337+ <tp:docstring>
338+ No special behavior; by default no user interaction is allowed and
339+ requests for secrets are fulfilled from persistent storage, or
340+ if no secrets are available an error is returned.
341+ </tp:docstring>
342+ </tp:flag>
343+ <tp:flag suffix="ALLOW_INTERACTION" value="0x1">
344+ <tp:docstring>
345+ Allows the request to interact with the user, possibly prompting
346+ via UI for secrets if any are required, or if none are found in
347+ persistent storage.
348+ </tp:docstring>
349+ </tp:flag>
350+ <tp:flag suffix="REQUEST_NEW" value="0x2">
351+ <tp:docstring>
352+ Explicitly prompt for new secrets from the user. This flag
353+ signals that NetworkManager thinks any existing secrets are
354+ invalid or wrong. This flag implies that interaction is allowed.
355+ </tp:docstring>
356+ </tp:flag>
357+ <tp:flag suffix="USER_REQUESTED" value="0x4">
358+ <tp:docstring>
359+ Set if the request was initiated by user-requested action via the
360+ D-Bus interface, as opposed to automatically initiated by
361+ NetworkManager in response to (for example) scan results or
362+ carrier changes.
363+ </tp:docstring>
364+ </tp:flag>
365+ </tp:flags>
366+
367+ <method name="CancelGetSecrets">
368+ <tp:docstring>
369+ Cancel a pending GetSecrets request for secrets of the given
370+ connection. Any GetSecrets request with the same
371+ 'connection_path' and 'setting_name' that are given in a
372+ CancelGetSecrets request should be canceled.
373+ </tp:docstring>
374+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_cancel_get_secrets"/>
375+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
376+ <arg name="connection_path" type="o" direction="in">
377+ <tp:docstring>
378+ Object path of the connection for which, if secrets for
379+ the given 'setting_name' are being requested, the request
380+ should be canceled.
381+ </tp:docstring>
382+ </arg>
383+ <arg name="setting_name" type="s" direction="in">
384+ <tp:docstring>
385+ Setting name for which secrets for this connection were
386+ originally being requested.
387+ </tp:docstring>
388+ </arg>
389+ </method>
390+
391+ <method name="SaveSecrets">
392+ <tp:docstring>
393+ Save given secrets to backing storage.
394+ </tp:docstring>
395+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_save_secrets"/>
396+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
397+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantDictMap"/>
398+ <arg name="connection" type="a{sa{sv}}" direction="in" tp:type="String_String_Variant_Map_Map">
399+ <tp:docstring>
400+ Nested settings maps containing the entire connection
401+ (including secrets), for which the agent should save the
402+ secrets to backing storage. This method will not be called
403+ when the agent itself is the process creating or updating
404+ a connection; in that case the agent is assumed to have
405+ already saved those secrets since it had them already.
406+ </tp:docstring>
407+ </arg>
408+ <arg name="connection_path" type="o" direction="in">
409+ <tp:docstring>
410+ Object path of the connection for which the agent should
411+ save secrets to backing storage.
412+ </tp:docstring>
413+ </arg>
414+ </method>
415+
416+ <method name="DeleteSecrets">
417+ <tp:docstring>
418+ Delete secrets from backing storage.
419+ </tp:docstring>
420+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_secret_agent_delete_secrets"/>
421+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
422+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantDictMap"/>
423+ <arg name="connection" type="a{sa{sv}}" direction="in" tp:type="String_String_Variant_Map_Map">
424+ <tp:docstring>
425+ Nested settings maps containing the connection properties
426+ (sans secrets), for which the agent should delete the
427+ secrets from backing storage.
428+ </tp:docstring>
429+ </arg>
430+ <arg name="connection_path" type="o" direction="in">
431+ <tp:docstring>
432+ Object path of the connection for which the agent should
433+ delete secrets from backing storage.
434+ </tp:docstring>
435+ </arg>
436+ </method>
437+
438+ </interface>
439+
440+</node>
441
442=== modified file 'debian/control'
443--- debian/control 2013-08-27 13:48:41 +0000
444+++ debian/control 2013-08-27 16:07:33 +0000
445@@ -3,19 +3,23 @@
446 Priority: optional
447 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
448 XSBC-Original-Maintainer: Ken VanDine <ken.vandine@canonical.com>
449-Build-Depends: debhelper (>= 9.0.0),
450- cmake,
451- gnome-common,
452- pkg-config,
453+Build-Depends: cmake,
454 dbus,
455+ debhelper (>= 9.0.0),
456+ google-mock (>= 1.6.0+svn437),
457+ libglib2.0-dev,
458 libnm-glib-dev (>= 0.9),
459 libnm-util-dev (>= 0.9),
460- libglib2.0-dev,
461+ libqmenumodel-dev,
462+ libqtdbusmock1-dev,
463+ libqtdbustest1-dev,
464 liburl-dispatcher1-dev,
465+ network-manager-dev,
466+ pkg-config,
467+ python3-dbusmock,
468+ qtbase5-dev,
469 valac (>= 0.18),
470- python3,
471- python3-dbusmock,
472- dbus-test-runner,
473+ valgrind,
474 Standards-Version: 3.9.3
475 # If you aren't a member of ~indicator-applet-developers but need to upload
476 # packaging changes, just go ahead. ~indicator-applet-developers will notice
477@@ -26,10 +30,10 @@
478
479 Package: indicator-network
480 Architecture: any
481-Depends: ${shlibs:Depends},
482- ${misc:Depends},
483-Conflicts: indicators-client-plugin-network,
484- chewie,
485+Depends: ${misc:Depends},
486+ ${shlibs:Depends},
487+Conflicts: chewie,
488+ indicators-client-plugin-network,
489 Description: Systems settings menu service - Network indicator
490 The Indicator-network service is responsible for exporting the system settings
491 menu through dbus.
492
493=== modified file 'network/CMakeLists.txt'
494--- network/CMakeLists.txt 2013-08-27 13:55:21 +0000
495+++ network/CMakeLists.txt 2013-08-27 16:07:33 +0000
496@@ -5,7 +5,6 @@
497
498 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
499 include_directories(${CMAKE_CURRENT_BINARY_DIR})
500-include_directories(${CMAKE_SOURCE_DIR})
501
502 ###########################
503 # libnetwork
504
505=== added directory 'secret-agent'
506=== added file 'secret-agent/CMakeLists.txt'
507--- secret-agent/CMakeLists.txt 1970-01-01 00:00:00 +0000
508+++ secret-agent/CMakeLists.txt 2013-08-27 16:07:33 +0000
509@@ -0,0 +1,59 @@
510+
511+set(
512+ INDICATOR_SECRET_AGENT_SOURCES
513+ SecretAgent.cpp
514+ SecretAgentAdaptor.cpp
515+ SecretRequest.cpp
516+)
517+
518+qt5_add_dbus_adaptor(
519+ INDICATOR_SECRET_AGENT_SOURCES
520+ "${DATA_DIR}/nm-secret-agent.xml"
521+ SecretAgentInclude.h
522+ SecretAgent
523+ SecretAgentAdaptor
524+)
525+
526+qt5_add_dbus_interface(
527+ INDICATOR_SECRET_AGENT_SOURCES
528+ "${DATA_DIR}/nm-agent-manager.xml"
529+ AgentManagerInterface
530+)
531+
532+add_library(
533+ indicator-secret-agent
534+ STATIC
535+ ${INDICATOR_SECRET_AGENT_SOURCES}
536+)
537+
538+qt5_use_modules(
539+ indicator-secret-agent
540+ Core
541+ DBus
542+)
543+
544+add_executable(
545+ indicator-secret-agent-bin
546+ main.cpp
547+)
548+
549+set_target_properties(
550+ indicator-secret-agent-bin
551+ PROPERTIES
552+ OUTPUT_NAME indicator-secret-agent
553+)
554+
555+qt5_use_modules(
556+ indicator-secret-agent-bin
557+ Core
558+)
559+
560+target_link_libraries(
561+ indicator-secret-agent-bin
562+ indicator-secret-agent
563+)
564+
565+install(
566+ TARGETS indicator-secret-agent-bin
567+ RUNTIME DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}"
568+)
569
570=== added file 'secret-agent/DBusTypes.h'
571--- secret-agent/DBusTypes.h 1970-01-01 00:00:00 +0000
572+++ secret-agent/DBusTypes.h 2013-08-27 16:07:33 +0000
573@@ -0,0 +1,37 @@
574+/*
575+ * Copyright (C) 2013 Canonical, Ltd.
576+ *
577+ * This program is free software: you can redistribute it and/or modify it
578+ * under the terms of the GNU General Public License version 3, as published
579+ * by the Free Software Foundation.
580+ *
581+ * This program is distributed in the hope that it will be useful, but
582+ * WITHOUT ANY WARRANTY; without even the implied warranties of
583+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
584+ * PURPOSE. See the GNU General Public License for more details.
585+ *
586+ * You should have received a copy of the GNU General Public License along
587+ * with this program. If not, see <http://www.gnu.org/licenses/>.
588+ *
589+ * Author: Pete Woods <pete.woods@canonical.com>
590+ */
591+
592+#ifndef DBUSTYPES_H_
593+#define DBUSTYPES_H_
594+
595+#include <QtDBus>
596+#include <QMap>
597+
598+typedef QMap<QString, QVariantMap> QVariantDictMap;
599+Q_DECLARE_METATYPE(QVariantDictMap)
600+
601+class DBusTypes {
602+public:
603+ static void registerMetaTypes() {
604+ qRegisterMetaType<QVariantDictMap>("QVariantDictMap");
605+
606+ qDBusRegisterMetaType<QVariantDictMap>();
607+ }
608+};
609+
610+#endif /* DBUSTYPES_H_ */
611
612=== added file 'secret-agent/Localisation.h'
613--- secret-agent/Localisation.h 1970-01-01 00:00:00 +0000
614+++ secret-agent/Localisation.h 2013-08-27 16:07:33 +0000
615@@ -0,0 +1,28 @@
616+/*
617+ * Copyright (C) 2013 Canonical, Ltd.
618+ *
619+ * This program is free software: you can redistribute it and/or modify it
620+ * under the terms of the GNU General Public License version 3, as published
621+ * by the Free Software Foundation.
622+ *
623+ * This program is distributed in the hope that it will be useful, but
624+ * WITHOUT ANY WARRANTY; without even the implied warranties of
625+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
626+ * PURPOSE. See the GNU General Public License for more details.
627+ *
628+ * You should have received a copy of the GNU General Public License along
629+ * with this program. If not, see <http://www.gnu.org/licenses/>.
630+ *
631+ * Author: Pete Woods <pete.woods@canonical.com>
632+ */
633+
634+#ifndef DAEMON_LOCALISATION_H_
635+#define DAEMON_LOCALISATION_H_
636+
637+#include <libintl.h>
638+
639+inline char* _(const char *__msgid) {
640+ return gettext(__msgid);
641+}
642+
643+#endif // DAEMON_LOCALISATION_H_
644
645=== added file 'secret-agent/SecretAgent.cpp'
646--- secret-agent/SecretAgent.cpp 1970-01-01 00:00:00 +0000
647+++ secret-agent/SecretAgent.cpp 2013-08-27 16:07:33 +0000
648@@ -0,0 +1,136 @@
649+/*
650+ * Copyright (C) 2013 Canonical, Ltd.
651+ *
652+ * This program is free software: you can redistribute it and/or modify it
653+ * under the terms of the GNU General Public License version 3, as published
654+ * by the Free Software Foundation.
655+ *
656+ * This program is distributed in the hope that it will be useful, but
657+ * WITHOUT ANY WARRANTY; without even the implied warranties of
658+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
659+ * PURPOSE. See the GNU General Public License for more details.
660+ *
661+ * You should have received a copy of the GNU General Public License along
662+ * with this program. If not, see <http://www.gnu.org/licenses/>.
663+ *
664+ * Author: Pete Woods <pete.woods@canonical.com>
665+ */
666+
667+#include <Localisation.h>
668+#include <SecretAgent.h>
669+#include <SecretAgentAdaptor.h>
670+
671+#include <NetworkManager.h>
672+
673+#include <stdexcept>
674+
675+using namespace std;
676+using namespace org::freedesktop::NetworkManager;
677+
678+const QString SecretAgent::WIRELESS_SECURITY_SETTING_NAME(
679+ "802-11-wireless-security");
680+
681+const QString SecretAgent::WIRELESS_SECURITY_PSK("psk");
682+const QString SecretAgent::WIRELESS_SECURITY_WEP_KEY0("wep-key0");
683+
684+const QString SecretAgent::WIRELESS_SECURITY_KEY_MGMT("key-mgmt");
685+
686+const QString SecretAgent::KEY_MGMT_WPA_NONE("wpa-none");
687+const QString SecretAgent::KEY_MGMT_WPA_PSK("wpa-psk");
688+const QString SecretAgent::KEY_MGMT_NONE("none");
689+
690+SecretAgent::SecretAgent(const QDBusConnection &connection, QObject *parent) :
691+ QObject(parent), m_adaptor(new SecretAgentAdaptor(this)), m_connection(
692+ connection), m_agentManager(NM_DBUS_SERVICE,
693+ NM_DBUS_PATH_AGENT_MANAGER, m_connection), m_requestCounter(0) {
694+ if (!m_connection.registerObject(NM_DBUS_PATH_SECRET_AGENT, this)) {
695+ throw logic_error(
696+ _("Unable to register user secret agent object on DBus"));
697+ }
698+
699+ m_agentManager.Register("com.canonical.indicator.SecretAgent").waitForFinished();
700+}
701+
702+SecretAgent::~SecretAgent() {
703+ m_agentManager.Unregister().waitForFinished();
704+ m_connection.unregisterObject(NM_DBUS_PATH_SECRET_AGENT);
705+}
706+
707+/**
708+ * Example call:
709+ * [Argument: a{sa{sv}}
710+ * {
711+ * "802-11-wireless" = [Argument: a{sv} {
712+ * "security" = [Variant(QString): "802-11-wireless-security"],
713+ * "ssid" = [Variant(QByteArray): {83, 119, 97, 108, 108, 111, 119, 115, 32, 66, 97, 114, 110}],
714+ * "mode" = [Variant(QString): "infrastructure"],
715+ * "mac-address" = [Variant(QByteArray): {8, 212, 43, 19, 139, 130}]
716+ * }],
717+ * "connection" = [Argument: a{sv} {
718+ * "id" = [Variant(QString): "Swallows Barn"],
719+ * "uuid" = [Variant(QString): "40fdd8b6-e119-41ae-87a3-7bfc8044f753"],
720+ * "type" = [Variant(QString): "802-11-wireless"]
721+ * }],
722+ * "ipv4" = [Argument: a{sv} {
723+ * "addresses" = [Variant: [Argument: aau {}]],
724+ * "dns" = [Variant: [Argument: au {}]],
725+ * "method" = [Variant(QString): "auto"],
726+ * "routes" = [Variant: [Argument: aau {}]]
727+ * }],
728+ * "802-11-wireless-security" = [Argument: a{sv} {
729+ * "auth-alg" = [Variant(QString): "open"],
730+ * "key-mgmt" = [Variant(QString): "wpa-psk"]
731+ * }],
732+ * "ipv6" = [Argument: a{sv} {
733+ * "addresses" = [Variant: [Argument: a(ayuay) {}]],
734+ * "dns" = [Variant: [Argument: aay {}]],
735+ * "method" = [Variant(QString): "auto"],
736+ * "routes" = [Variant: [Argument: a(ayuayu) {}]]
737+ * }]
738+ * }
739+ * ],
740+ * [ObjectPath: /org/freedesktop/NetworkManager/Settings/0],
741+ * "802-11-wireless-security",
742+ * {},
743+ * 5
744+ */
745+QVariantDictMap SecretAgent::GetSecrets(const QVariantDictMap &connection,
746+ const QDBusObjectPath &connectionPath, const QString &settingName,
747+ const QStringList &hints, uint flags) {
748+
749+ setDelayedReply(true);
750+
751+ if (flags == 0) {
752+ m_connection.send(
753+ message().createErrorReply(QDBusError::InternalError,
754+ "No password found for this connection."));
755+ } else {
756+ SecretRequestPtr request(
757+ new SecretRequest(m_requestCounter, *this, connection,
758+ connectionPath, settingName, hints, flags, message()));
759+ m_requests.insert(m_requestCounter, request);
760+
761+ ++m_requestCounter;
762+ }
763+
764+ return QVariantDictMap();
765+}
766+
767+void SecretAgent::FinishGetSecrets(SecretRequest &request) {
768+ m_connection.send(
769+ request.message().createReply(
770+ QVariant::fromValue(request.connection())));
771+ m_requests.remove(request.requestId());
772+}
773+
774+void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connectionPath,
775+ const QString &settingName) {
776+}
777+
778+void SecretAgent::DeleteSecrets(const QVariantDictMap &connection,
779+ const QDBusObjectPath &connectionPath) {
780+}
781+
782+void SecretAgent::SaveSecrets(const QVariantDictMap &connection,
783+ const QDBusObjectPath &connectionPath) {
784+}
785
786=== added file 'secret-agent/SecretAgent.h'
787--- secret-agent/SecretAgent.h 1970-01-01 00:00:00 +0000
788+++ secret-agent/SecretAgent.h 2013-08-27 16:07:33 +0000
789@@ -0,0 +1,81 @@
790+/*
791+ * Copyright (C) 2013 Canonical, Ltd.
792+ *
793+ * This program is free software: you can redistribute it and/or modify it
794+ * under the terms of the GNU General Public License version 3, as published
795+ * by the Free Software Foundation.
796+ *
797+ * This program is distributed in the hope that it will be useful, but
798+ * WITHOUT ANY WARRANTY; without even the implied warranties of
799+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
800+ * PURPOSE. See the GNU General Public License for more details.
801+ *
802+ * You should have received a copy of the GNU General Public License along
803+ * with this program. If not, see <http://www.gnu.org/licenses/>.
804+ *
805+ * Author: Pete Woods <pete.woods@canonical.com>
806+ */
807+
808+#ifndef SECRETAGENT_H_
809+#define SECRETAGENT_H_
810+
811+#include <QScopedPointer>
812+#include <QDBusConnection>
813+#include <QtDBus>
814+#include <QMap>
815+
816+#include <DBusTypes.h>
817+#include <SecretRequest.h>
818+#include <AgentManagerInterface.h>
819+
820+class SecretAgentAdaptor;
821+
822+class SecretAgent: public QObject, protected QDBusContext {
823+Q_OBJECT
824+
825+public:
826+ static const QString WIRELESS_SECURITY_SETTING_NAME;
827+
828+ static const QString WIRELESS_SECURITY_PSK;
829+ static const QString WIRELESS_SECURITY_WEP_KEY0;
830+
831+ static const QString WIRELESS_SECURITY_KEY_MGMT;
832+
833+ static const QString KEY_MGMT_WPA_NONE;
834+ static const QString KEY_MGMT_WPA_PSK;
835+ static const QString KEY_MGMT_NONE;
836+
837+ explicit SecretAgent(const QDBusConnection &connection,
838+ QObject *parent = 0);
839+
840+ virtual ~SecretAgent();
841+
842+public Q_SLOTS:
843+ QVariantDictMap GetSecrets(const QVariantDictMap &connection,
844+ const QDBusObjectPath &connectionPath, const QString &settingName,
845+ const QStringList &hints, uint flags);
846+
847+ void FinishGetSecrets(SecretRequest &request);
848+
849+ void CancelGetSecrets(const QDBusObjectPath &connectionPath,
850+ const QString &settingName);
851+
852+ void DeleteSecrets(const QVariantDictMap &connection,
853+ const QDBusObjectPath &connectionPath);
854+
855+ void SaveSecrets(const QVariantDictMap &connection,
856+ const QDBusObjectPath &connectionPath);
857+
858+protected:
859+ QScopedPointer<SecretAgentAdaptor> m_adaptor;
860+
861+ QDBusConnection m_connection;
862+
863+ org::freedesktop::NetworkManager::AgentManager m_agentManager;
864+
865+ QMap<unsigned long long, SecretRequestPtr> m_requests;
866+
867+ unsigned long long m_requestCounter;
868+};
869+
870+#endif /* SECRETAGENT_H_ */
871
872=== added file 'secret-agent/SecretAgentInclude.h'
873--- secret-agent/SecretAgentInclude.h 1970-01-01 00:00:00 +0000
874+++ secret-agent/SecretAgentInclude.h 2013-08-27 16:07:33 +0000
875@@ -0,0 +1,25 @@
876+/*
877+ * Copyright (C) 2013 Canonical, Ltd.
878+ *
879+ * This program is free software: you can redistribute it and/or modify it
880+ * under the terms of the GNU General Public License version 3, as published
881+ * by the Free Software Foundation.
882+ *
883+ * This program is distributed in the hope that it will be useful, but
884+ * WITHOUT ANY WARRANTY; without even the implied warranties of
885+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
886+ * PURPOSE. See the GNU General Public License for more details.
887+ *
888+ * You should have received a copy of the GNU General Public License along
889+ * with this program. If not, see <http://www.gnu.org/licenses/>.
890+ *
891+ * Author: Pete Woods <pete.woods@canonical.com>
892+ */
893+
894+#ifndef SECRETAGENTINCLUDE_H_
895+#define SECRETAGENTINCLUDE_H_
896+
897+#include <DBusTypes.h>
898+#include <SecretAgent.h>
899+
900+#endif /* SECRETAGENTINCLUDE_H_ */
901
902=== added file 'secret-agent/SecretRequest.cpp'
903--- secret-agent/SecretRequest.cpp 1970-01-01 00:00:00 +0000
904+++ secret-agent/SecretRequest.cpp 2013-08-27 16:07:33 +0000
905@@ -0,0 +1,65 @@
906+/*
907+ * Copyright (C) 2013 Canonical, Ltd.
908+ *
909+ * This program is free software: you can redistribute it and/or modify it
910+ * under the terms of the GNU General Public License version 3, as published
911+ * by the Free Software Foundation.
912+ *
913+ * This program is distributed in the hope that it will be useful, but
914+ * WITHOUT ANY WARRANTY; without even the implied warranties of
915+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
916+ * PURPOSE. See the GNU General Public License for more details.
917+ *
918+ * You should have received a copy of the GNU General Public License along
919+ * with this program. If not, see <http://www.gnu.org/licenses/>.
920+ *
921+ * Author: Pete Woods <pete.woods@canonical.com>
922+ */
923+
924+#include "SecretRequest.h"
925+#include "SecretAgent.h"
926+
927+SecretRequest::SecretRequest(unsigned int requestId, SecretAgent &secretAgent,
928+ const QVariantDictMap &connection,
929+ const QDBusObjectPath &connectionPath, const QString &settingName,
930+ const QStringList &hints, uint flags, const QDBusMessage &message,
931+ QObject *parent) :
932+ QObject(parent), m_requestId(requestId), m_secretAgent(secretAgent), m_connection(
933+ connection), m_connectionPath(connectionPath), m_settingName(
934+ settingName), m_hints(hints), m_flags(flags), m_message(message) {
935+
936+ QTimer::singleShot(0, this, SLOT(FinishRequest()));
937+}
938+
939+SecretRequest::~SecretRequest() {
940+}
941+
942+void SecretRequest::FinishRequest() {
943+ //FIXME: Hard-coded - use system dialogue call to populate it
944+ QString key("hard-coded-password");
945+
946+ auto wirelessSecurity = m_connection.find(m_settingName);
947+ QString keyMgmt(
948+ wirelessSecurity->value(SecretAgent::WIRELESS_SECURITY_KEY_MGMT).toString());
949+
950+ if (keyMgmt == SecretAgent::KEY_MGMT_WPA_NONE
951+ || keyMgmt == SecretAgent::KEY_MGMT_WPA_PSK) {
952+ wirelessSecurity->insert(SecretAgent::WIRELESS_SECURITY_PSK, key);
953+ } else if (keyMgmt == SecretAgent::KEY_MGMT_NONE) {
954+ wirelessSecurity->insert(SecretAgent::WIRELESS_SECURITY_WEP_KEY0, key);
955+ }
956+
957+ m_secretAgent.FinishGetSecrets(*this);
958+}
959+
960+unsigned int SecretRequest::requestId() const {
961+ return m_requestId;
962+}
963+
964+const QVariantDictMap & SecretRequest::connection() const {
965+ return m_connection;
966+}
967+
968+const QDBusMessage & SecretRequest::message() const {
969+ return m_message;
970+}
971
972=== added file 'secret-agent/SecretRequest.h'
973--- secret-agent/SecretRequest.h 1970-01-01 00:00:00 +0000
974+++ secret-agent/SecretRequest.h 2013-08-27 16:07:33 +0000
975@@ -0,0 +1,71 @@
976+/*
977+ * Copyright (C) 2013 Canonical, Ltd.
978+ *
979+ * This program is free software: you can redistribute it and/or modify it
980+ * under the terms of the GNU General Public License version 3, as published
981+ * by the Free Software Foundation.
982+ *
983+ * This program is distributed in the hope that it will be useful, but
984+ * WITHOUT ANY WARRANTY; without even the implied warranties of
985+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
986+ * PURPOSE. See the GNU General Public License for more details.
987+ *
988+ * You should have received a copy of the GNU General Public License along
989+ * with this program. If not, see <http://www.gnu.org/licenses/>.
990+ *
991+ * Author: Pete Woods <pete.woods@canonical.com>
992+ */
993+
994+#ifndef SECRETREQUEST_H_
995+#define SECRETREQUEST_H_
996+
997+#include <DBusTypes.h>
998+
999+#include <QtDBus>
1000+#include <QSharedPointer>
1001+
1002+class SecretRequest;
1003+class SecretAgent;
1004+
1005+typedef QSharedPointer<SecretRequest> SecretRequestPtr;
1006+
1007+class SecretRequest: public QObject {
1008+Q_OBJECT
1009+public:
1010+ explicit SecretRequest(unsigned int requestId, SecretAgent &secretAgent,
1011+ const QVariantDictMap &connection,
1012+ const QDBusObjectPath &connectionPath, const QString &settingName,
1013+ const QStringList &hints, uint flags, const QDBusMessage &reply,
1014+ QObject *parent = 0);
1015+
1016+ virtual ~SecretRequest();
1017+
1018+public Q_SLOTS:
1019+ void FinishRequest();
1020+
1021+public:
1022+ unsigned int requestId() const;
1023+
1024+ const QVariantDictMap & connection() const;
1025+
1026+ const QDBusMessage & message() const;
1027+
1028+protected:
1029+ const unsigned int m_requestId;
1030+
1031+ SecretAgent &m_secretAgent;
1032+
1033+ QVariantDictMap m_connection;
1034+
1035+ QDBusObjectPath m_connectionPath;
1036+
1037+ QString m_settingName;
1038+
1039+ QStringList m_hints;
1040+
1041+ uint m_flags;
1042+
1043+ QDBusMessage m_message;
1044+};
1045+
1046+#endif /* SECRETREQUEST_H_ */
1047
1048=== added file 'secret-agent/main.cpp'
1049--- secret-agent/main.cpp 1970-01-01 00:00:00 +0000
1050+++ secret-agent/main.cpp 2013-08-27 16:07:33 +0000
1051@@ -0,0 +1,54 @@
1052+/*
1053+ * Copyright (C) 2013 Canonical, Ltd.
1054+ *
1055+ * This program is free software: you can redistribute it and/or modify it
1056+ * under the terms of the GNU General Public License version 3, as published
1057+ * by the Free Software Foundation.
1058+ *
1059+ * This program is distributed in the hope that it will be useful, but
1060+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1061+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1062+ * PURPOSE. See the GNU General Public License for more details.
1063+ *
1064+ * You should have received a copy of the GNU General Public License along
1065+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1066+ *
1067+ * Author: Pete Woods <pete.woods@canonical.com>
1068+ */
1069+
1070+#include <config.h>
1071+#include <Localisation.h>
1072+#include <SecretAgent.h>
1073+#include <DBusTypes.h>
1074+
1075+#include <QCoreApplication>
1076+#include <csignal>
1077+#include <iostream>
1078+
1079+using namespace std;
1080+
1081+static void exitQt(int sig) {
1082+ Q_UNUSED(sig);
1083+ QCoreApplication::exit(0);
1084+}
1085+
1086+int main(int argc, char *argv[]) {
1087+ QCoreApplication application(argc, argv);
1088+ DBusTypes::registerMetaTypes();
1089+
1090+ setlocale(LC_ALL, "");
1091+ bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
1092+ textdomain(GETTEXT_PACKAGE);
1093+
1094+ signal(SIGINT, &exitQt);
1095+ signal(SIGTERM, &exitQt);
1096+
1097+ SecretAgent secretAgent(QDBusConnection::systemBus());
1098+
1099+ if (argc == 2 && QString("--print-address") == argv[1]) {
1100+ cout << QDBusConnection::systemBus().baseService().toStdString()
1101+ << endl;
1102+ }
1103+
1104+ return application.exec();
1105+}
1106
1107=== removed directory 'test'
1108=== removed file 'test/network.py'
1109--- test/network.py 2013-07-30 14:52:40 +0000
1110+++ test/network.py 1970-01-01 00:00:00 +0000
1111@@ -1,105 +0,0 @@
1112-#!/usr/bin/env python3
1113-# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
1114-
1115-# Copyright 2013 Canonical Ltd.
1116-#
1117-# This program is free software; you can redistribute it and/or modify
1118-# it under the terms of the GNU Lesser General Public License as published by
1119-# the Free Software Foundation; version 3.
1120-#
1121-# This program is distributed in the hope that it will be useful,
1122-# but WITHOUT ANY WARRANTY; without even the implied warranty of
1123-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1124-# GNU Lesser General Public License for more details.
1125-#
1126-# You should have received a copy of the GNU Lesser General Public License
1127-# along with this program. If not, see <http://www.gnu.org/licenses/>.
1128-#
1129-# Authors:
1130-# Alberto Ruiz <alberto.ruizo@canonical.com>
1131-
1132-import unittest
1133-import dbus
1134-import dbusmock
1135-import subprocess
1136-import os
1137-import sys
1138-import time
1139-import functools
1140-
1141-ACTIVATED = 100
1142-AP_PREFIX = "/org/freedesktop/NetworkManager/AccessPoint/"
1143-
1144-def check_aps_actions(self, ret, aps):
1145- for ap in aps:
1146- ap_action = "wlan0." + AP_PREFIX + ap
1147- strength_action = ap_action + "::strength"
1148- self.assertTrue(ap_action in ret)
1149- self.assertTrue(strength_action in ret)
1150-
1151-def check_aps_in_menu(self, ret, aps):
1152- ap_items = []
1153- for group in ret:
1154- a, b, items = group
1155- for item in items:
1156- if 'x-canonical-wifi-ap-dbus-path' in item:
1157- print("Found AP item: %s" % (item['x-canonical-wifi-ap-dbus-path']))
1158- ap_items.append(item)
1159-
1160- self.assertTrue(len(ap_items) > 0)
1161-
1162- for ap in aps:
1163- ap_path = AP_PREFIX + ap
1164- items_map = map(lambda item: item['x-canonical-wifi-ap-dbus-path'] == ap_path, ap_items)
1165- has_ap = functools.reduce(lambda a, b: a or b, items_map)
1166- self.assertTrue (has_ap)
1167-
1168-
1169-class TestNetworkMenu(dbusmock.DBusTestCase):
1170- '''Test network menu'''
1171-
1172- @classmethod
1173- def setUpClass(klass):
1174- klass.start_system_bus()
1175- klass.dbus_con = klass.get_dbus(True)
1176-
1177- def setUp(self):
1178- (self.p_mock, self.obj_networkmanager) = self.spawn_server_template(
1179- 'networkmanager',
1180- {'NetworkingEnabled': True, 'WwanEnabled': False},
1181- stdout=subprocess.PIPE)
1182- self.dbusmock = dbus.Interface(self.obj_networkmanager,
1183- dbusmock.MOCK_IFACE)
1184-
1185- def tearDown(self):
1186- self.p_mock.terminate()
1187- self.p_mock.wait()
1188-
1189- def test_phone_one_wlan(self):
1190- aps = ['mock_ap',]
1191- wifi1 = self.dbusmock.AddWiFiDevice('mock_wifi0', 'wlan0', ACTIVATED)
1192-
1193- self.dbusmock.AddAccessPoint (wifi1, 'mock_ap',
1194- 'myap', '00:23:f8:7e:12:ba', 0, 2425, 5400, 80, 0x400)
1195-
1196- p = subprocess.Popen(['indicator-network-service'])
1197- time.sleep (0.6)
1198-
1199- bus = dbus.SessionBus ()
1200-
1201- actions = bus.get_object ('com.canonical.indicator.network',
1202- '/com/canonical/indicator/network')
1203- phone = bus.get_object ('com.canonical.indicator.network',
1204- '/com/canonical/indicator/network/phone')
1205-
1206- actions_iface = dbus.Interface(actions, dbus_interface='org.gtk.Actions')
1207- phone_menu_iface = dbus.Interface(phone, dbus_interface='org.gtk.Menus')
1208-
1209- check_aps_actions (self, actions_iface.List(), aps)
1210- check_aps_in_menu (self, phone_menu_iface.Start([0, 1]), aps)
1211-
1212- p.terminate()
1213- p.wait()
1214-
1215-if __name__ == '__main__':
1216- unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
1217
1218=== modified file 'tests/CMakeLists.txt'
1219--- tests/CMakeLists.txt 2013-08-27 13:48:41 +0000
1220+++ tests/CMakeLists.txt 2013-08-27 16:07:33 +0000
1221@@ -0,0 +1,61 @@
1222+
1223+set(CMAKE_AUTOMOC OFF)
1224+include(FindGMock)
1225+set(CMAKE_AUTOMOC ON)
1226+
1227+find_package("Valgrind" REQUIRED)
1228+
1229+include_directories("${CMAKE_SOURCE_DIR}/secret-agent")
1230+include_directories("${CMAKE_BINARY_DIR}/secret-agent")
1231+
1232+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
1233+include_directories(${GMOCK_INCLUDE_DIRS})
1234+include_directories(${GTEST_INCLUDE_DIRS})
1235+
1236+add_definitions(-DSECRET_AGENT_BIN="${CMAKE_BINARY_DIR}/secret-agent/indicator-secret-agent")
1237+add_definitions(-DNETWORK_SERVICE_BIN="${CMAKE_BINARY_DIR}/network/indicator-network-service")
1238+
1239+set(
1240+ UNIT_TESTS_SRC
1241+ TestIndicatorNetworkService.cpp
1242+ TestSecretAgent.cpp
1243+ main.cpp
1244+)
1245+
1246+set_source_files_properties(
1247+ "${DATA_DIR}/nm-secret-agent.xml"
1248+ PROPERTIES
1249+ INCLUDE "DBusTypes.h"
1250+)
1251+
1252+qt5_add_dbus_interface(
1253+ UNIT_TESTS_SRC
1254+ "${DATA_DIR}/nm-secret-agent.xml"
1255+ SecretAgentInterface
1256+)
1257+
1258+add_executable(
1259+ unit-tests
1260+ ${UNIT_TESTS_SRC}
1261+)
1262+
1263+qt5_use_modules(
1264+ unit-tests
1265+ Core
1266+ DBus
1267+ Test
1268+)
1269+
1270+target_link_libraries(
1271+ unit-tests
1272+ indicator-secret-agent
1273+ ${QTDBUSMOCK_LIBRARIES}
1274+ ${QTDBUSTEST_LIBRARIES}
1275+ ${GTEST_LIBRARIES}
1276+ ${GMOCK_LIBRARIES}
1277+)
1278+
1279+add_valgrind_test(
1280+ unit-tests
1281+ unit-tests
1282+)
1283
1284=== added file 'tests/TestIndicatorNetworkService.cpp'
1285--- tests/TestIndicatorNetworkService.cpp 1970-01-01 00:00:00 +0000
1286+++ tests/TestIndicatorNetworkService.cpp 2013-08-27 16:07:33 +0000
1287@@ -0,0 +1,60 @@
1288+/*
1289+ * Copyright (C) 2013 Canonical, Ltd.
1290+ *
1291+ * This program is free software: you can redistribute it and/or modify it
1292+ * under the terms of the GNU General Public License version 3, as published
1293+ * by the Free Software Foundation.
1294+ *
1295+ * This program is distributed in the hope that it will be useful, but
1296+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1297+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1298+ * PURPOSE. See the GNU General Public License for more details.
1299+ *
1300+ * You should have received a copy of the GNU General Public License along
1301+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1302+ *
1303+ * Author: Pete Woods <pete.woods@canonical.com>
1304+ */
1305+
1306+#include <libqtdbustest/DBusTestRunner.h>
1307+#include <libqtdbustest/QProcessDBusService.h>
1308+#include <libqtdbusmock/DBusMock.h>
1309+#include <NetworkManager.h>
1310+
1311+#include <gmock/gmock.h>
1312+#include <gtest/gtest.h>
1313+
1314+using namespace std;
1315+using namespace testing;
1316+using namespace QtDBusTest;
1317+using namespace QtDBusMock;
1318+
1319+namespace {
1320+
1321+class TestIndicatorNetworkService: public Test {
1322+protected:
1323+ TestIndicatorNetworkService() :
1324+ dbusMock(dbusTestRunner) {
1325+
1326+ dbusMock.registerNetworkManager();
1327+ dbusTestRunner.startServices();
1328+
1329+ DBusServicePtr indicator(
1330+ new QProcessDBusService("com.canonical.indicator.network",
1331+ QDBusConnection::SessionBus, NETWORK_SERVICE_BIN,
1332+ QStringList()));
1333+ }
1334+
1335+ virtual ~TestIndicatorNetworkService() {
1336+ }
1337+
1338+ DBusTestRunner dbusTestRunner;
1339+
1340+ DBusMock dbusMock;
1341+};
1342+
1343+TEST_F(TestIndicatorNetworkService, Foo) {
1344+ //FIXME: Port the python test
1345+}
1346+
1347+} // namespace
1348
1349=== added file 'tests/TestSecretAgent.cpp'
1350--- tests/TestSecretAgent.cpp 1970-01-01 00:00:00 +0000
1351+++ tests/TestSecretAgent.cpp 2013-08-27 16:07:33 +0000
1352@@ -0,0 +1,167 @@
1353+/*
1354+ * Copyright (C) 2013 Canonical, Ltd.
1355+ *
1356+ * This program is free software: you can redistribute it and/or modify it
1357+ * under the terms of the GNU General Public License version 3, as published
1358+ * by the Free Software Foundation.
1359+ *
1360+ * This program is distributed in the hope that it will be useful, but
1361+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1362+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1363+ * PURPOSE. See the GNU General Public License for more details.
1364+ *
1365+ * You should have received a copy of the GNU General Public License along
1366+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1367+ *
1368+ * Author: Pete Woods <pete.woods@canonical.com>
1369+ */
1370+
1371+#include <libqtdbustest/DBusTestRunner.h>
1372+#include <libqtdbusmock/DBusMock.h>
1373+#include <SecretAgent.h>
1374+#include <SecretAgentInterface.h>
1375+#include <NetworkManager.h>
1376+
1377+#include <gmock/gmock.h>
1378+#include <gtest/gtest.h>
1379+
1380+using namespace std;
1381+using namespace testing;
1382+using namespace QtDBusTest;
1383+using namespace QtDBusMock;
1384+
1385+namespace {
1386+
1387+class TestSecretAgentCommon {
1388+protected:
1389+ TestSecretAgentCommon() :
1390+ dbusMock(dbusTestRunner) {
1391+
1392+ dbusMock.registerNetworkManager();
1393+ dbusTestRunner.startServices();
1394+
1395+ secretAgent.start(SECRET_AGENT_BIN, QStringList() << "--print-address");
1396+ secretAgent.waitForStarted();
1397+ secretAgent.waitForReadyRead();
1398+ agentBus = secretAgent.readAll().trimmed();
1399+
1400+ interface.reset(
1401+ new OrgFreedesktopNetworkManagerSecretAgentInterface(agentBus,
1402+ NM_DBUS_PATH_SECRET_AGENT,
1403+ dbusTestRunner.systemConnection()));
1404+ }
1405+
1406+ virtual ~TestSecretAgentCommon() {
1407+ secretAgent.terminate();
1408+ secretAgent.waitForFinished();
1409+ }
1410+
1411+ QVariantDictMap connection(const QString &keyManagement) {
1412+ QVariantMap wirelessSecurity;
1413+ wirelessSecurity[SecretAgent::WIRELESS_SECURITY_KEY_MGMT] =
1414+ keyManagement;
1415+
1416+ QVariantDictMap connection;
1417+ connection[SecretAgent::WIRELESS_SECURITY_SETTING_NAME] =
1418+ wirelessSecurity;
1419+
1420+ return connection;
1421+ }
1422+
1423+ QVariantDictMap expected(const QString &keyManagement,
1424+ const QString &keyName, const QString &password) {
1425+
1426+ QVariantMap wirelessSecurity;
1427+ wirelessSecurity[SecretAgent::WIRELESS_SECURITY_KEY_MGMT] =
1428+ keyManagement;
1429+ wirelessSecurity[keyName] = password;
1430+
1431+ QVariantDictMap connection;
1432+ connection[SecretAgent::WIRELESS_SECURITY_SETTING_NAME] =
1433+ wirelessSecurity;
1434+
1435+ return connection;
1436+ }
1437+
1438+ DBusTestRunner dbusTestRunner;
1439+
1440+ DBusMock dbusMock;
1441+
1442+ QProcess secretAgent;
1443+
1444+ QString agentBus;
1445+
1446+ QScopedPointer<OrgFreedesktopNetworkManagerSecretAgentInterface> interface;
1447+};
1448+
1449+struct TestSecretAgentParams {
1450+ QString keyManagement;
1451+
1452+ QString passwordKey;
1453+
1454+ QString password;
1455+};
1456+
1457+class TestSecretAgentGetSecrets: public TestSecretAgentCommon,
1458+ public TestWithParam<TestSecretAgentParams> {
1459+};
1460+
1461+TEST_P(TestSecretAgentGetSecrets, ProvidesPasswordForWpaPsk) {
1462+ QVariantDictMap reply(
1463+ interface->GetSecrets(connection(GetParam().keyManagement),
1464+ QDBusObjectPath("/connection/foo"),
1465+ SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(),
1466+ 5));
1467+
1468+ EXPECT_EQ(
1469+ expected(GetParam().keyManagement, GetParam().passwordKey,
1470+ GetParam().password), reply);
1471+}
1472+
1473+INSTANTIATE_TEST_CASE_P(WpaPsk, TestSecretAgentGetSecrets,
1474+ Values(TestSecretAgentParams( { SecretAgent::KEY_MGMT_WPA_PSK,
1475+ SecretAgent::WIRELESS_SECURITY_PSK, "hard-coded-password" })));
1476+
1477+INSTANTIATE_TEST_CASE_P(WpaNone, TestSecretAgentGetSecrets,
1478+ Values(TestSecretAgentParams( { SecretAgent::KEY_MGMT_WPA_NONE,
1479+ SecretAgent::WIRELESS_SECURITY_PSK, "hard-coded-password" })));
1480+
1481+INSTANTIATE_TEST_CASE_P(None, TestSecretAgentGetSecrets,
1482+ Values(
1483+ TestSecretAgentParams( { SecretAgent::KEY_MGMT_NONE,
1484+ SecretAgent::WIRELESS_SECURITY_WEP_KEY0,
1485+ "hard-coded-password" })));
1486+
1487+class TestSecretAgent: public TestSecretAgentCommon, public Test {
1488+};
1489+
1490+TEST_F(TestSecretAgent, GetSecretsWithNone) {
1491+ QDBusPendingReply<QVariantDictMap> reply(
1492+ interface->GetSecrets(connection(SecretAgent::KEY_MGMT_WPA_PSK),
1493+ QDBusObjectPath("/connection/foo"),
1494+ SecretAgent::WIRELESS_SECURITY_SETTING_NAME, QStringList(),
1495+ 0));
1496+ reply.waitForFinished();
1497+
1498+ ASSERT_TRUE(reply.isError());
1499+ EXPECT_EQ(QDBusError::InternalError, reply.error().type());
1500+ EXPECT_EQ("No password found for this connection.",
1501+ reply.error().message());
1502+}
1503+
1504+TEST_F(TestSecretAgent, CancelGetSecrets) {
1505+ interface->CancelGetSecrets(QDBusObjectPath("/connection/foo"),
1506+ SecretAgent::WIRELESS_SECURITY_SETTING_NAME).waitForFinished();
1507+}
1508+
1509+TEST_F(TestSecretAgent, SaveSecrets) {
1510+ interface->SaveSecrets(QVariantDictMap(),
1511+ QDBusObjectPath("/connection/foo")).waitForFinished();
1512+}
1513+
1514+TEST_F(TestSecretAgent, DeleteSecrets) {
1515+ interface->DeleteSecrets(QVariantDictMap(),
1516+ QDBusObjectPath("/connection/foo")).waitForFinished();
1517+}
1518+
1519+} // namespace
1520
1521=== added directory 'tests/data'
1522=== added file 'tests/data/valgrind.suppression'
1523--- tests/data/valgrind.suppression 1970-01-01 00:00:00 +0000
1524+++ tests/data/valgrind.suppression 2013-08-27 16:07:33 +0000
1525@@ -0,0 +1,95 @@
1526+{
1527+ Ignore pthreads
1528+ Memcheck:Leak
1529+ ...
1530+ fun:pthread_create@@*
1531+}
1532+
1533+{
1534+ Glib memalign
1535+ Memcheck:Leak
1536+ ...
1537+ fun:posix_memalign
1538+}
1539+
1540+{
1541+ Ignore glib mainloop
1542+ Memcheck:Leak
1543+ ...
1544+ fun:g_main_context_push_thread_default
1545+}
1546+
1547+{
1548+ Ignore glib main context
1549+ Memcheck:Leak
1550+ ...
1551+ fun:g_main_context_new
1552+}
1553+
1554+###############################
1555+# GObject rules
1556+###############################
1557+
1558+{
1559+ <insert_a_suppression_name_here>
1560+ Memcheck:Leak
1561+ ...
1562+ fun:g_type_register_static
1563+}
1564+
1565+{
1566+ <insert_a_suppression_name_here>
1567+ Memcheck:Leak
1568+ ...
1569+ fun:g_type_register_fundamental
1570+}
1571+
1572+{
1573+ <insert_a_suppression_name_here>
1574+ Memcheck:Leak
1575+ ...
1576+ fun:type_node_fundamental_new_W
1577+}
1578+
1579+{
1580+ <insert_a_suppression_name_here>
1581+ Memcheck:Leak
1582+ ...
1583+ fun:type_data_make_W
1584+}
1585+
1586+{
1587+ <insert_a_suppression_name_here>
1588+ Memcheck:Leak
1589+ ...
1590+ fun:g_type_add_interface_static
1591+}
1592+
1593+{
1594+ <insert_a_suppression_name_here>
1595+ Memcheck:Leak
1596+ ...
1597+ fun:type_iface_vtable_base_init_Wm
1598+}
1599+
1600+{
1601+ <insert_a_suppression_name_here>
1602+ Memcheck:Leak
1603+ ...
1604+ fun:g_dbus_interface_skeleton_class_intern_init
1605+}
1606+
1607+{
1608+ <insert_a_suppression_name_here>
1609+ Memcheck:Leak
1610+ ...
1611+ fun:g_signal_type_cclosure_new
1612+}
1613+
1614+{
1615+ <insert_a_suppression_name_here>
1616+ Memcheck:Leak
1617+ fun:calloc
1618+ fun:g_malloc0
1619+ fun:g_type_class_ref
1620+}
1621
1622=== added file 'tests/main.cpp'
1623--- tests/main.cpp 1970-01-01 00:00:00 +0000
1624+++ tests/main.cpp 2013-08-27 16:07:33 +0000
1625@@ -0,0 +1,44 @@
1626+/*
1627+ * Copyright (C) 2013 Canonical, Ltd.
1628+ *
1629+ * This program is free software: you can redistribute it and/or modify it
1630+ * under the terms of the GNU General Public License version 3, as published
1631+ * by the Free Software Foundation.
1632+ *
1633+ * This program is distributed in the hope that it will be useful, but
1634+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1635+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1636+ * PURPOSE. See the GNU General Public License for more details.
1637+ *
1638+ * You should have received a copy of the GNU General Public License along
1639+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1640+ *
1641+ * Author: Pete Woods <pete.woods@canonical.com>
1642+ */
1643+
1644+#include <config.h>
1645+
1646+#include <QCoreApplication>
1647+#include <gtest/gtest.h>
1648+
1649+#include <libqtdbusmock/DBusMock.h>
1650+#include <DBusTypes.h>
1651+
1652+using namespace QtDBusMock;
1653+
1654+int main(int argc, char **argv) {
1655+ qputenv("LANG", "C.UTF-8");
1656+ unsetenv("LC_ALL");
1657+
1658+ setlocale(LC_ALL, "");
1659+ bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
1660+ textdomain(GETTEXT_PACKAGE);
1661+
1662+ QCoreApplication application(argc, argv);
1663+
1664+ DBusMock::registerMetaTypes();
1665+ DBusTypes::registerMetaTypes();
1666+
1667+ ::testing::InitGoogleTest(&argc, argv);
1668+ return RUN_ALL_TESTS();
1669+}

Subscribers

People subscribed via source and target branches

to all changes: