on xenial help sign in
[DBusGreeterList] fix EntryIsLocked property
184b9d6Ratchanan Srirattanamet
plugins/LightDM/DBusGreeterList.cpp+3−3
@@ -25,7 +25,7 @@ DBusGreeterList::DBusGreeterList(Greeter *greeter, const QString &path)
25 m_greeter(greeter)
25 m_greeter(greeter)
26{
26{
27 connect(m_greeter, &Greeter::authenticationUserChanged, this, &DBusGreeterList::authenticationUserChangedHandler);
27 connect(m_greeter, &Greeter::authenticationUserChanged, this, &DBusGreeterList::authenticationUserChangedHandler);
28− connect(m_greeter, &Greeter::isAuthenticatedChanged, this, &DBusGreeterList::authenticatedChangedHandler);
28+ connect(m_greeter, &Greeter::promptlessChanged, this, &DBusGreeterList::promptlessChangedHandler);
29}
29}
30
30
31QString DBusGreeterList::GetActiveEntry() const
31QString DBusGreeterList::GetActiveEntry() const
@@ -40,7 +40,7 @@ void DBusGreeterList::SetActiveEntry(const QString &entry)
40
40
41bool DBusGreeterList::entryIsLocked() const
41bool DBusGreeterList::entryIsLocked() const
42{
42{
43− return !m_greeter->isAuthenticated();
43+ return !m_greeter->promptless();
44}
44}
45
45
46void DBusGreeterList::authenticationUserChangedHandler()
46void DBusGreeterList::authenticationUserChangedHandler()
@@ -49,7 +49,7 @@ void DBusGreeterList::authenticationUserChangedHandler()
49 Q_EMIT EntrySelected(m_greeter->authenticationUser());
49 Q_EMIT EntrySelected(m_greeter->authenticationUser());
50}
50}
51
51
52−void DBusGreeterList::authenticatedChangedHandler()
52+void DBusGreeterList::promptlessChangedHandler()
53{
53{
54 notifyPropertyChanged(QStringLiteral("EntryIsLocked"), entryIsLocked());
54 notifyPropertyChanged(QStringLiteral("EntryIsLocked"), entryIsLocked());
55 Q_EMIT entryIsLockedChanged();
55 Q_EMIT entryIsLockedChanged();
plugins/LightDM/DBusGreeterList.h+1−1
@@ -48,7 +48,7 @@ Q_SIGNALS:
48
48
49private Q_SLOTS:
49private Q_SLOTS:
50 void authenticationUserChangedHandler();
50 void authenticationUserChangedHandler();
51− void authenticatedChangedHandler();
51+ void promptlessChangedHandler();
52
52
53private:
53private:
54 Greeter *m_greeter;
54 Greeter *m_greeter;
plugins/LightDM/Greeter.cpp+16
@@ -27,6 +27,7 @@ GreeterPrivate::GreeterPrivate(Greeter* parent)
27 m_active(false),
27 m_active(false),
28 responded(false),
28 responded(false),
29 everResponded(false),
29 everResponded(false),
30+ promptless(false),
30 q_ptr(parent)
31 q_ptr(parent)
31{
32{
32}
33}
@@ -112,6 +113,12 @@ QString Greeter::defaultSessionHint() const
112 return d->m_greeter->defaultSessionHint();
113 return d->m_greeter->defaultSessionHint();
113}
114}
114
115
116+bool Greeter::promptless() const
117+{
118+ Q_D(const Greeter);
119+ return d->promptless;
120+}
121+
115QString Greeter::selectUser() const
122QString Greeter::selectUser() const
116{
123{
117 Q_D(const Greeter);
124 Q_D(const Greeter);
@@ -146,6 +153,10 @@ void Greeter::authenticate(const QString &username)
146 d->prompts.clear();
153 d->prompts.clear();
147 d->responded = false;
154 d->responded = false;
148 d->everResponded = false;
155 d->everResponded = false;
156+ if (d->promptless) {
157+ d->promptless = false;
158+ Q_EMIT promptlessChanged();
159+ }
149
160
150 if (authenticationUser() == username) {
161 if (authenticationUser() == username) {
151 d->prompts = d->leftovers;
162 d->prompts = d->leftovers;
@@ -235,6 +246,11 @@ void Greeter::authenticationCompleteFilter()
235 bool automatic = !d->everResponded;
246 bool automatic = !d->everResponded;
236 bool pamHasLeftoverMessages = !d->prompts.hasPrompt() && d->prompts.rowCount() > 0;
247 bool pamHasLeftoverMessages = !d->prompts.hasPrompt() && d->prompts.rowCount() > 0;
237
248
249+ if (isAuthenticated() && automatic) {
250+ d->promptless = true;
251+ Q_EMIT promptlessChanged();
252+ }
253+
238 if (!isAuthenticated()) {
254 if (!isAuthenticated()) {
239 if (pamHasLeftoverMessages) {
255 if (pamHasLeftoverMessages) {
240 d->leftovers = d->prompts; // Prefer PAM's messages
256 d->leftovers = d->prompts; // Prefer PAM's messages
plugins/LightDM/Greeter.h+3
@@ -37,6 +37,7 @@ class Greeter : public QObject
37 Q_PROPERTY(bool authenticated READ isAuthenticated NOTIFY isAuthenticatedChanged)
37 Q_PROPERTY(bool authenticated READ isAuthenticated NOTIFY isAuthenticatedChanged)
38 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
38 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
39 Q_PROPERTY(QString defaultSession READ defaultSessionHint CONSTANT)
39 Q_PROPERTY(QString defaultSession READ defaultSessionHint CONSTANT)
40+ Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
40 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
41 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
41
42
42public:
43public:
@@ -47,6 +48,7 @@ public:
47 bool isAuthenticated() const;
48 bool isAuthenticated() const;
48 QString authenticationUser() const;
49 QString authenticationUser() const;
49 QString defaultSessionHint() const;
50 QString defaultSessionHint() const;
51+ bool promptless() const;
50 QString selectUser() const;
52 QString selectUser() const;
51 bool hasGuestAccount() const;
53 bool hasGuestAccount() const;
52 bool showManualLoginHint() const;
54 bool showManualLoginHint() const;
@@ -64,6 +66,7 @@ Q_SIGNALS:
64 void authenticationUserChanged();
66 void authenticationUserChanged();
65 void isActiveChanged();
67 void isActiveChanged();
66 void isAuthenticatedChanged();
68 void isAuthenticatedChanged();
69+ void promptlessChanged();
67 void showGreeter();
70 void showGreeter();
68 void hideGreeter();
71 void hideGreeter();
69 void loginError(bool automatic);
72 void loginError(bool automatic);
plugins/LightDM/GreeterPrivate.h+1
@@ -34,6 +34,7 @@ public:
34 PromptsModel leftovers; // prompts to show during next auth for same user
34 PromptsModel leftovers; // prompts to show during next auth for same user
35 bool responded;
35 bool responded;
36 bool everResponded;
36 bool everResponded;
37+ bool promptless;
37 QString cachedAuthUser;
38 QString cachedAuthUser;
38
39
39protected:
40protected:
tests/plugins/LightDM/IntegratedLightDM/dbus.cpp+18−5
@@ -15,6 +15,7 @@
15 */
15 */
16
16
17#include "Greeter.h"
17#include "Greeter.h"
18+#include "PromptsModel.h"
18
19
19#include <QCoreApplication>
20#include <QCoreApplication>
20#include <QDBusInterface>
21#include <QDBusInterface>
@@ -137,11 +138,13 @@ private Q_SLOTS:
137 void testActiveEntryChanged()
138 void testActiveEntryChanged()
138 {
139 {
139 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
140 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
141+
140 greeter->authenticate("has-password");
142 greeter->authenticate("has-password");
141
143
144+ // EntryIsLocked's default is true, thus only single property change.
142− QTRY_COMPARE(spy.count(), 2); // EntryIsLocked then ActiveEntry
145+ QTRY_COMPARE(spy.count(), 1);
143
146
144− QList<QVariant> arguments = spy[1];
147+ QList<QVariant> arguments = spy[0];
145 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
148 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
146 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
149 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
147 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
150 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
@@ -154,19 +157,29 @@ private Q_SLOTS:
154 greeter->authenticate("no-password");
157 greeter->authenticate("no-password");
155 QTRY_VERIFY(!dbusList->property("EntryIsLocked").toBool());
158 QTRY_VERIFY(!dbusList->property("EntryIsLocked").toBool());
156
159
160+ QSignalSpy promptSpy(greeter->promptsModel(), &PromptsModel::countChanged);
161+ QSignalSpy successSpy(greeter, &Greeter::loginSuccess);
162+
157 greeter->authenticate("has-password");
163 greeter->authenticate("has-password");
158 QTRY_VERIFY(dbusList->property("EntryIsLocked").toBool());
164 QTRY_VERIFY(dbusList->property("EntryIsLocked").toBool());
165+ // Make sure that EntryIsLocked stays `true` after authenticated.
166+ // Regression test for https://github.com/ubports/ubuntu-touch/issues/1406
167+ promptSpy.wait();
168+ greeter->respond(QStringLiteral("password"));
169+ successSpy.wait();
170+ QVERIFY(dbusList->property("EntryIsLocked").toBool());
159 }
171 }
160
172
161 void testEntryIsLockedChanged()
173 void testEntryIsLockedChanged()
162 {
174 {
163 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
175 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
176+
164 greeter->authenticate("no-password");
177 greeter->authenticate("no-password");
165
178
166− // EntryIsLocked=true, ActiveEntry, then EntryIsLocked=false
179+ // ActiveEntry, then EntryIsLocked=false
167− QTRY_COMPARE(spy.count(), 3);
180+ QTRY_COMPARE(spy.count(), 2);
168
181
169− QList<QVariant> arguments = spy[2];
182+ QList<QVariant> arguments = spy[1];
170 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
183 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
171 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
184 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
172 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
185 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);