on xenial help sign in
[DBusGreeterList] fix EntryIsLocked property

The property has been wired into Greeter's isAuthenticated(), in (merge) commit 6d9907ef7fdb ("Use a model for PAM prompts, supporting more possible interactions."). This changes its meaning; it's supposed to mean whether the account has a lock (i.e. password), not whether the screen is locked at the moment. This commit brings back Greeter's promptless() property and using it for EntryIsLocked, thus fixing the property's meaning. A regression test has been added, and 2 tests are updated for the change in change signaling order. Fixes https://github.com/ubports/ubuntu-touch/issues/1406

commit184b9d638f7dd4060be1d95ba14dcec36255c6d2 authorRatchanan Srirattanamet <ratchanan@ubports.com> dateMon 30 Mar 2020, 21:16 (7 years ago) parent8ae7d92
6 files changed+42−9
plugins/LightDM/DBusGreeterList.cpp+3−3 plugins/LightDM/DBusGreeterList.h+1−1 plugins/LightDM/Greeter.cpp+16 plugins/LightDM/Greeter.h+3 plugins/LightDM/GreeterPrivate.h+1 tests/plugins/LightDM/IntegratedLightDM/dbus.cpp+18−5
plugins/LightDM/DBusGreeterList.cpp+3−3
@@ -25,7 +25,7 @@ DBusGreeterList::DBusGreeterList(Greeter *greeter, const QString &path)
2525 m_greeter(greeter)
2626{
2727 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);
2929}
3030
3131QString DBusGreeterList::GetActiveEntry() const
@@ -40,7 +40,7 @@ void DBusGreeterList::SetActiveEntry(const QString &entry)
4040
4141bool DBusGreeterList::entryIsLocked() const
4242{
43− return !m_greeter->isAuthenticated();
43+ return !m_greeter->promptless();
4444}
4545
4646void DBusGreeterList::authenticationUserChangedHandler()
@@ -49,7 +49,7 @@ void DBusGreeterList::authenticationUserChangedHandler()
4949 Q_EMIT EntrySelected(m_greeter->authenticationUser());
5050}
5151
52−void DBusGreeterList::authenticatedChangedHandler()
52+void DBusGreeterList::promptlessChangedHandler()
5353{
5454 notifyPropertyChanged(QStringLiteral("EntryIsLocked"), entryIsLocked());
5555 Q_EMIT entryIsLockedChanged();
plugins/LightDM/DBusGreeterList.h+1−1
@@ -48,7 +48,7 @@ Q_SIGNALS:
4848
4949private Q_SLOTS:
5050 void authenticationUserChangedHandler();
51− void authenticatedChangedHandler();
51+ void promptlessChangedHandler();
5252
5353private:
5454 Greeter *m_greeter;
plugins/LightDM/Greeter.cpp+16
@@ -27,6 +27,7 @@ GreeterPrivate::GreeterPrivate(Greeter* parent)
2727 m_active(false),
2828 responded(false),
2929 everResponded(false),
30+ promptless(false),
3031 q_ptr(parent)
3132{
3233}
@@ -112,6 +113,12 @@ QString Greeter::defaultSessionHint() const
112113 return d->m_greeter->defaultSessionHint();
113114}
114115
116+bool Greeter::promptless() const
117+{
118+ Q_D(const Greeter);
119+ return d->promptless;
120+}
121+
115122QString Greeter::selectUser() const
116123{
117124 Q_D(const Greeter);
@@ -146,6 +153,10 @@ void Greeter::authenticate(const QString &username)
146153 d->prompts.clear();
147154 d->responded = false;
148155 d->everResponded = false;
156+ if (d->promptless) {
157+ d->promptless = false;
158+ Q_EMIT promptlessChanged();
159+ }
149160
150161 if (authenticationUser() == username) {
151162 d->prompts = d->leftovers;
@@ -235,6 +246,11 @@ void Greeter::authenticationCompleteFilter()
235246 bool automatic = !d->everResponded;
236247 bool pamHasLeftoverMessages = !d->prompts.hasPrompt() && d->prompts.rowCount() > 0;
237248
249+ if (isAuthenticated() && automatic) {
250+ d->promptless = true;
251+ Q_EMIT promptlessChanged();
252+ }
253+
238254 if (!isAuthenticated()) {
239255 if (pamHasLeftoverMessages) {
240256 d->leftovers = d->prompts; // Prefer PAM's messages
plugins/LightDM/Greeter.h+3
@@ -37,6 +37,7 @@ class Greeter : public QObject
3737 Q_PROPERTY(bool authenticated READ isAuthenticated NOTIFY isAuthenticatedChanged)
3838 Q_PROPERTY(QString authenticationUser READ authenticationUser NOTIFY authenticationUserChanged)
3939 Q_PROPERTY(QString defaultSession READ defaultSessionHint CONSTANT)
40+ Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
4041 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
4142
4243public:
@@ -47,6 +48,7 @@ public:
4748 bool isAuthenticated() const;
4849 QString authenticationUser() const;
4950 QString defaultSessionHint() const;
51+ bool promptless() const;
5052 QString selectUser() const;
5153 bool hasGuestAccount() const;
5254 bool showManualLoginHint() const;
@@ -64,6 +66,7 @@ Q_SIGNALS:
6466 void authenticationUserChanged();
6567 void isActiveChanged();
6668 void isAuthenticatedChanged();
69+ void promptlessChanged();
6770 void showGreeter();
6871 void hideGreeter();
6972 void loginError(bool automatic);
plugins/LightDM/GreeterPrivate.h+1
@@ -34,6 +34,7 @@ public:
3434 PromptsModel leftovers; // prompts to show during next auth for same user
3535 bool responded;
3636 bool everResponded;
37+ bool promptless;
3738 QString cachedAuthUser;
3839
3940protected:
tests/plugins/LightDM/IntegratedLightDM/dbus.cpp+18−5
@@ -15,6 +15,7 @@
1515 */
1616
1717#include "Greeter.h"
18+#include "PromptsModel.h"
1819
1920#include <QCoreApplication>
2021#include <QDBusInterface>
@@ -137,11 +138,13 @@ private Q_SLOTS:
137138 void testActiveEntryChanged()
138139 {
139140 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
141+
140142 greeter->authenticate("has-password");
141143
142− QTRY_COMPARE(spy.count(), 2); // EntryIsLocked then ActiveEntry
144+ // EntryIsLocked's default is true, thus only single property change.
145+ QTRY_COMPARE(spy.count(), 1);
143146
144− QList<QVariant> arguments = spy[1];
147+ QList<QVariant> arguments = spy[0];
145148 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
146149 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
147150 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
@@ -154,19 +157,29 @@ private Q_SLOTS:
154157 greeter->authenticate("no-password");
155158 QTRY_VERIFY(!dbusList->property("EntryIsLocked").toBool());
156159
160+ QSignalSpy promptSpy(greeter->promptsModel(), &PromptsModel::countChanged);
161+ QSignalSpy successSpy(greeter, &Greeter::loginSuccess);
162+
157163 greeter->authenticate("has-password");
158164 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());
159171 }
160172
161173 void testEntryIsLockedChanged()
162174 {
163175 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
176+
164177 greeter->authenticate("no-password");
165178
166− // EntryIsLocked=true, ActiveEntry, then EntryIsLocked=false
167− QTRY_COMPARE(spy.count(), 3);
179+ // ActiveEntry, then EntryIsLocked=false
180+ QTRY_COMPARE(spy.count(), 2);
168181
169− QList<QVariant> arguments = spy[2];
182+ QList<QVariant> arguments = spy[1];
170183 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
171184 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
172185 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);