on xenial help sign in
Add a test to make sure the shell always starts disabled until it is enabled by a complete PAM interaction.

Approved by: Michał Sawicz

commit68d04cc432fa543d71e1bdee112d842b155454f5 authorMichael Terry <michael.terry@canonical.com> dateFri 9 Jan 2015, 10:42 (12 years ago) parentcb1ecc15c12379
4 files changed+44−1
tests/mocks/LightDM/Greeter.cpp+6 tests/mocks/LightDM/Greeter.h+3 tests/plugins/LightDM/dbus.cpp+4−1 tests/qmltests/tst_ShellWithPin.qml+31
tests/mocks/LightDM/Greeter.cpp+6
@@ -129,6 +129,12 @@ void Greeter::authenticate(const QString &username)
129129 d->authenticated = false;
130130 d->authenticationUser = username;
131131 d->twoFactorDone = false;
132+ QTimer::singleShot(0, this, SLOT(delayedAuthentication()));
133+}
134+
135+void Greeter::delayedAuthentication()
136+{
137+ Q_D(Greeter);
132138 d->handleAuthenticate();
133139}
134140
tests/mocks/LightDM/Greeter.h+3
@@ -99,6 +99,9 @@ Q_SIGNALS:
9999protected:
100100 void sendAuthenticationComplete();
101101
102+private Q_SLOTS:
103+ void delayedAuthentication();
104+
102105private:
103106 GreeterPrivate *d_ptr;
104107 Q_DECLARE_PRIVATE(Greeter)
tests/plugins/LightDM/dbus.cpp+4−1
@@ -16,6 +16,7 @@
1616
1717#include "Greeter.h"
1818
19+#include <QCoreApplication>
1920#include <QDBusInterface>
2021#include <QDBusReply>
2122#include <QSignalSpy>
@@ -149,9 +150,11 @@ private Q_SLOTS:
149150 QVERIFY(dbusList->property("EntryIsLocked").toBool());
150151
151152 greeter->authenticate("no-password");
153+ QCoreApplication::processEvents(); // wait for auth to finish
152154 QVERIFY(!dbusList->property("EntryIsLocked").toBool());
153155
154156 greeter->authenticate("has-password");
157+ QCoreApplication::processEvents(); // wait for auth to finish
155158 QVERIFY(dbusList->property("EntryIsLocked").toBool());
156159 }
157160
@@ -168,7 +171,7 @@ private Q_SLOTS:
168171 }
169172 QCOMPARE(spy.count(), 2);
170173
171− QList<QVariant> arguments = spy.takeFirst();
174+ QList<QVariant> arguments = spy.takeLast();
172175 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
173176 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
174177 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
tests/qmltests/tst_ShellWithPin.qml+31
@@ -116,6 +116,12 @@ Item {
116116 signalName: "resettingDevice"
117117 }
118118
119+ SignalSpy {
120+ id: promptSpy
121+ target: LightDM.Greeter
122+ signalName: "showPrompt"
123+ }
124+
119125 Telephony.CallEntry {
120126 id: phoneCall
121127 phoneNumber: "+447812221111"
@@ -472,5 +478,30 @@ Item {
472478
473479 }
474480
481+ /* We had a bug (1395075) where if a user kept swiping as the greeter
482+ loaded, they would be able to get into the session before the
483+ lockscreen appeared. Make sure that doesn't happen. */
484+ function test_earlyDisable() {
485+ // Kill current shell
486+ shellLoader.itemDestroyed = false;
487+ shellLoader.active = false;
488+ tryCompare(shellLoader, "itemDestroyed", true);
489+ LightDM.Greeter.authenticate(""); // reset greeter
490+
491+ // Create new shell
492+ promptSpy.clear();
493+ shellLoader.active = true;
494+ tryCompareFunction(function() {return shell !== null}, true);
495+
496+ // Confirm that we start disabled
497+ compare(promptSpy.count, 0);
498+ verify(!shell.enabled);
499+
500+ // And that we only become enabled once the lockscreen is up
501+ tryCompare(shell, "enabled", true);
502+ verify(promptSpy.count > 0);
503+ var lockscreen = findChild(shell, "lockscreen");
504+ verify(lockscreen.shown);
505+ }
475506 }
476507}