~lukas-kde/unity8/dashboard

« back to all changes in this revision

Viewing changes to tests/mocks/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cpp

  • Committer: Lukáš Tinkl
  • Date: 2017-01-26 12:13:17 UTC
  • mfrom: (2749.1.49 unity8)
  • Revision ID: lukas.tinkl@canonical.com-20170126121317-qms39s9pikclidbe
merge trunk, fix conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 */
16
 
 
17
 
#include "Greeter.h"
18
 
#include "GreeterPrivate.h"
19
 
 
20
 
namespace QLightDM
21
 
{
22
 
 
23
 
GreeterPrivate::GreeterPrivate(Greeter* parent)
24
 
  : authenticated(false),
25
 
    authenticationUser(),
26
 
    twoFactorDone(false),
27
 
    mockMode("single"),
28
 
    q_ptr(parent)
29
 
{
30
 
    char *envMockMode = getenv("LIBLIGHTDM_MOCK_MODE");
31
 
    if (envMockMode) {
32
 
        mockMode = envMockMode;
33
 
    }
34
 
}
35
 
 
36
 
void GreeterPrivate::handleAuthenticate()
37
 
{
38
 
    Q_Q(Greeter);
39
 
 
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
 
    }
48
 
}
49
 
 
50
 
void GreeterPrivate::handleAuthenticate_full()
51
 
{
52
 
    Q_Q(Greeter);
53
 
 
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
 
    }
68
 
 
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
 
    }
83
 
}
84
 
 
85
 
void GreeterPrivate::handleRespond(QString const &response)
86
 
{
87
 
    Q_Q(Greeter);
88
 
 
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
 
    }
100
 
}
101
 
 
102
 
void GreeterPrivate::handleRespond_full(const QString &response)
103
 
{
104
 
    Q_Q(Greeter);
105
 
 
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
 
    }
123
 
 
124
 
    if (authenticationUser == "has-pin") {
125
 
        authenticated = (response == "1234");
126
 
    } else {
127
 
        authenticated = (response == "password");
128
 
    }
129
 
    q->sendAuthenticationComplete();
130
 
}
131
 
 
132
 
}