on fe71e21 help sign in
unity8/tests/mocks/liblightdm/GreeterPrivate.cpp
132 lines 4.5 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "Greeter.h"
18#include "GreeterPrivate.h"
20namespace QLightDM
23GreeterPrivate::GreeterPrivate(Greeter* parent)
24 : authenticated(false),
25 authenticationUser(),
26 twoFactorDone(false),
27 mockMode("single"),
28 q_ptr(parent)
30 char *envMockMode = getenv("LIBLIGHTDM_MOCK_MODE");
31 if (envMockMode) {
32 mockMode = envMockMode;
33 }
36void GreeterPrivate::handleAuthenticate()
38 Q_Q(Greeter);
40 if (mockMode == "single") {
41 authenticated = true;
42 Q_EMIT q->authenticationComplete();
43 } else if (mockMode == "single-passphrase" || mockMode == "single-pin") {
44 Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
45 } else if (mockMode == "full") {
46 handleAuthenticate_full();
47 }
50void GreeterPrivate::handleAuthenticate_full()
52 Q_Q(Greeter);
54 // Send out any messages we need to
55 if (authenticationUser == "info-prompt")
56 Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
57 else if (authenticationUser == "wide-info-prompt")
58 Q_EMIT q->showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
59 else if (authenticationUser == "html-info-prompt")
60 Q_EMIT q->showMessage("<b>&</b>", Greeter::MessageTypeInfo);
61 else if (authenticationUser == "long-info-prompt")
62 Q_EMIT q->showMessage("Welcome to Unity Greeter\n\nWe like to annoy you with super ridiculously long messages.\nLike this one\n\nThis is the last line of a multiple line message.", Greeter::MessageTypeInfo);
63 else if (authenticationUser == "multi-info-prompt") {
64 Q_EMIT q->showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
65 Q_EMIT q->showMessage("This is an error", Greeter::MessageTypeError);
66 Q_EMIT q->showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
67 }
69 // OK, now actually do the prompt
70 if (authenticationUser == "no-password") {
71 authenticated = true;
72 Q_EMIT q->authenticationComplete();
73 } else if (authenticationUser == "has-pin"){
74 Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
75 } else if (authenticationUser == "auth-error") {
76 authenticated = false;
77 Q_EMIT q->authenticationComplete();
78 } else if (authenticationUser == "different-prompt") {
79 Q_EMIT q->showPrompt("Secret word: ", Greeter::PromptTypeSecret);
80 } else {
81 Q_EMIT q->showPrompt("Password: ", Greeter::PromptTypeSecret);
82 }
85void GreeterPrivate::handleRespond(QString const &response)
87 Q_Q(Greeter);
89 if (mockMode == "single") {
90 // NOOP
91 } else if (mockMode == "single-passphrase") {
92 authenticated = (response == "password");
93 q->sendAuthenticationComplete();
94 } else if (mockMode == "single-pin") {
95 authenticated = (response == "1234");
96 q->sendAuthenticationComplete();
97 } else if (mockMode == "full") {
98 handleRespond_full(response);
99 }
102void GreeterPrivate::handleRespond_full(const QString &response)
104 Q_Q(Greeter);
106 if (authenticationUser == "no-response")
107 return;
108 else if (authenticationUser == "two-factor") {
109 if (!twoFactorDone) {
110 if (response == "password") {
111 twoFactorDone = true;
112 Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
113 } else {
114 authenticated = false;
115 q->sendAuthenticationComplete();
116 }
117 } else {
118 authenticated = (response == "otp");
119 q->sendAuthenticationComplete();
120 }
121 return;
122 }
124 if (authenticationUser == "has-pin") {
125 authenticated = (response == "1234");
126 } else {
127 authenticated = (response == "password");
128 }
129 q->sendAuthenticationComplete();