Merge lp:~ubuntu-terminal-dev/ubuntu-terminal-app/fix-add-forceAuth into lp:ubuntu-terminal-app

Proposed by Carla Sella
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 151
Merged at revision: 153
Proposed branch: lp:~ubuntu-terminal-dev/ubuntu-terminal-app/fix-add-forceAuth
Merge into: lp:ubuntu-terminal-app
Diff against target: 139 lines (+81/-3)
3 files modified
src/app/main.cpp (+22/-0)
src/app/qml/AuthenticationService.qml (+1/-1)
tests/autopilot/ubuntu_terminal_app/tests/__init__.py (+58/-2)
To merge this branch: bzr merge lp:~ubuntu-terminal-dev/ubuntu-terminal-app/fix-add-forceAuth
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Alan Pope 🍺🐧🐱 🦄 Pending
Nicholas Skaggs Pending
Review via email: mp+235711@code.launchpad.net

Commit message

Add the --forceAuth flag to terminal-app

Description of the change

This should add the --forceAuth flag to launch the application bypassing the authentication.
Sadly tonight the emulator is not working for me so I could only check that the code actually compiles, so please use extra care.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/main.cpp'
2--- src/app/main.cpp 2014-04-27 20:38:52 +0000
3+++ src/app/main.cpp 2014-09-23 19:58:09 +0000
4@@ -47,12 +47,23 @@
5 qDebug() << "usage: " + args.at(0) + " [-p|--phone] [-t|--tablet] [-h|--help] [-I <path>]";
6 qDebug() << " -p|--phone If running on Desktop, start in a phone sized window.";
7 qDebug() << " -t|--tablet If running on Desktop, start in a tablet sized window.";
8+ qDebug() << " --forceAuth <true|false> Force authentication on or off.";
9 qDebug() << " -h|--help Print this help.";
10 qDebug() << " -I <path> Give a path for an additional QML import directory. May be used multiple times.";
11 qDebug() << " -q <qmlfile> Give an alternative location for the main qml file.";
12 return 0;
13 }
14
15+ // Desktop doesn't have yet Unity8 and so no unity greeter either. Consequently it doesn't
16+ // also have any "PIN code" or "Password" extra authentication. Don't require any extra
17+ // authentication there by default
18+ if (qgetenv("QT_QPA_PLATFORM") != "ubuntumirclient") {
19+ qDebug() << Q_FUNC_INFO << "Running on non-MIR desktop, not requiring authentication by default";
20+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(true));
21+ } else {
22+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(false));
23+ }
24+
25 QString qmlfile;
26 for (int i = 0; i < args.count(); i++) {
27 if (args.at(i) == "-I" && args.count() > i + 1) {
28@@ -64,6 +75,17 @@
29 importPathList.append(addedPath);
30 } else if (args.at(i) == "-q" && args.count() > i + 1) {
31 qmlfile = args.at(i+1);
32+ } else if (args.at(i) == "--forceAuth" && args.count() > i + 1) {
33+ QString value = args.at(i+1);
34+ if (value == "true") {
35+ qDebug() << Q_FUNC_INFO << "Forcing authentication on";
36+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(false));
37+ } else if (value == "false") {
38+ qDebug() << Q_FUNC_INFO << "Forcing authentication off";
39+ view.engine()->rootContext()->setContextProperty("noAuthentication", QVariant(true));
40+ } else {
41+ qWarning() << Q_FUNC_INFO << "Invalid forceAuth option '" << value << "', keeping default";
42+ }
43 }
44 }
45
46
47=== modified file 'src/app/qml/AuthenticationService.qml'
48--- src/app/qml/AuthenticationService.qml 2014-08-26 18:48:18 +0000
49+++ src/app/qml/AuthenticationService.qml 2014-09-23 19:58:09 +0000
50@@ -30,7 +30,7 @@
51 signal denied()
52
53 Component.onCompleted: {
54- if ( systemAuthentication.requireAuthentication() ) {
55+ if ( systemAuthentication.requireAuthentication() && !noAuthentication) {
56 displayLoginDialog();
57 }
58 }
59
60=== modified file 'tests/autopilot/ubuntu_terminal_app/tests/__init__.py'
61--- tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2014-08-29 18:33:30 +0000
62+++ tests/autopilot/ubuntu_terminal_app/tests/__init__.py 2014-09-23 19:58:09 +0000
63@@ -10,11 +10,14 @@
64 import os.path
65 import fixtures
66 import logging
67+import tempfile
68+
69 from autopilot import logging as autopilot_logging
70 from autopilot.testcase import AutopilotTestCase
71 import ubuntuuitoolkit
72
73 import ubuntu_terminal_app
74+from gi.repository import Click
75
76 logger = logging.getLogger(__name__)
77
78@@ -70,6 +73,59 @@
79
80 @autopilot_logging.log_action(logger.info)
81 def launch_test_click(self):
82- return self.launch_click_package(
83- "com.ubuntu.terminal",
84+ # We need to pass the "--forceAuth false" argument to the terminal app
85+ # binary, but ubuntu-app-launch doesn't pass arguments to the exec line
86+ # on the desktop file. So we make a test desktop file that has the
87+ # "--forceAuth false" on the exec line.
88+ desktop_file_path = self.write_sandbox_desktop_file()
89+ desktop_file_name = os.path.basename(desktop_file_path)
90+ application_name, _ = os.path.splitext(desktop_file_name)
91+ return self.launch_upstart_application(
92+ application_name,
93 emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
94+
95+ def write_sandbox_desktop_file(self):
96+ desktop_file_dir = self.get_local_desktop_file_directory()
97+ desktop_file = self.get_named_temporary_file(
98+ suffix='.desktop', dir=desktop_file_dir)
99+ desktop_file.write('[Desktop Entry]\n')
100+ version, installed_path = self.get_installed_version_and_directory()
101+ terminal_sandbox_exec = (
102+ 'aa-exec-click -p com.ubuntu.terminal_terminal_{}'
103+ ' -- terminal --forceAuth false'.format(version))
104+ desktop_file_dict = {
105+ 'Type': 'Application',
106+ 'Name': 'terminal',
107+ 'Exec': terminal_sandbox_exec,
108+ 'Icon': 'Not important',
109+ 'Path': installed_path
110+ }
111+ for key, value in desktop_file_dict.items():
112+ desktop_file.write('{key}={value}\n'.format(key=key, value=value))
113+ desktop_file.close()
114+ logger.debug(terminal_sandbox_exec)
115+ for key, value in desktop_file_dict.items():
116+ logger.debug("%s: %s" % (key, value))
117+ return desktop_file.name
118+
119+ def get_local_desktop_file_directory(self):
120+ return os.path.join(
121+ self.real_home_dir, '.local', 'share', 'applications')
122+
123+ def get_named_temporary_file(
124+ self, dir=None, mode='w+t', delete=False, suffix=''):
125+ # Discard files with underscores which look like an APP_ID to Unity
126+ # See https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1329141
127+ chars = tempfile._RandomNameSequence.characters.strip("_")
128+ tempfile._RandomNameSequence.characters = chars
129+ return tempfile.NamedTemporaryFile(
130+ dir=dir, mode=mode, delete=delete, suffix=suffix)
131+
132+ def get_installed_version_and_directory(self):
133+ db = Click.DB()
134+ db.read()
135+ package_name = 'com.ubuntu.terminal'
136+ registry = Click.User.for_user(db, name=os.environ.get('USER'))
137+ version = registry.get_version(package_name)
138+ directory = registry.get_path(package_name)
139+ return version, directory

Subscribers

People subscribed via source and target branches