]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Add regression test for PAM conversations that have an informational prompt
authorRobert Ancell <robert.ancell@canonical.com>
Thu, 15 Mar 2012 01:51:38 +0000 (12:51 +1100)
committerRobert Ancell <robert.ancell@canonical.com>
Thu, 15 Mar 2012 01:51:38 +0000 (12:51 +1100)
tests/Makefile.am
tests/scripts/login-info-prompt.conf [new file with mode: 0644]
tests/src/libsystem.c
tests/src/test-runner.c
tests/test-login-gobject-info-prompt [new file with mode: 0755]
tests/test-login-python-info-prompt [new file with mode: 0755]
tests/test-login-qt-info-prompt [new file with mode: 0755]

index 99d91175cfda8a48275e347f6cf7fd560417a63e..328d8596639633b902c5002c19dd279698907c82 100644 (file)
@@ -41,6 +41,7 @@ TESTS = \
        test-login-gobject-manual-previous-session \
        test-login-gobject-no-password \
        test-login-gobject-new-authtok \
+       test-login-gobject-info-prompt \
        test-login-gobject-pick-session \
        test-login-gobject-previous-session \
        test-login-gobject-wrong-password \
@@ -57,6 +58,7 @@ TESTS = \
        test-login-python-manual-previous-session \
        test-login-python-no-password \
        test-login-python-new-authtok \
+       test-login-python-info-prompt \
        test-login-python-previous-session \
        test-login-python-wrong-password \
        test-login-python-invalid-user \
@@ -108,6 +110,7 @@ TESTS += \
        test-login-qt-manual-previous-session \
        test-login-qt-no-password \
        test-login-qt-new-authtok \
+       test-login-qt-info-prompt \
        test-login-qt-previous-session \
        test-login-qt-wrong-password \
        test-login-qt-invalid-user \
@@ -163,6 +166,7 @@ EXTRA_DIST = \
        scripts/login-guest-fail-setup-script.conf \
        scripts/login-guest-logout.conf \
        scripts/login-guest-no-setup-script.conf \
+       scripts/login-info-prompt.conf \
        scripts/login-invalid-session.conf \
        scripts/login-invalid-user.conf \
        scripts/login-logout.conf \
diff --git a/tests/scripts/login-info-prompt.conf b/tests/scripts/login-info-prompt.conf
new file mode 100644 (file)
index 0000000..8df67e5
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# Check a PAM informational message on login is passed to a greeter
+#
+
+[LightDM]
+minimum-display-number=50
+
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER :50 START
+#?XSERVER :50 INDICATE-READY
+
+# LightDM connects to X server
+#?XSERVER :50 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER :50 START
+#?XSERVER :50 ACCEPT-CONNECT
+#?GREETER :50 CONNECT-XSERVER
+#?GREETER :50 CONNECT-TO-DAEMON
+#?GREETER :50 CONNECTED-TO-DAEMON
+
+# Log into account and see an informational prompt
+#?*GREETER :50 AUTHENTICATE USERNAME=info-prompt
+#?GREETER :50 SHOW-MESSAGE TEXT="Welcome to LightDM"
+#?GREETER :50 SHOW-PROMPT TEXT="Password:"
+
+# Respond with password and check response is correctly handled
+#?*GREETER :50 RESPOND TEXT="password"
+#?GREETER :50 AUTHENTICATION-COMPLETE USERNAME=info-prompt AUTHENTICATED=TRUE
+
+# Cleanup
+#?*STOP-DAEMON
+# Don't know what order they will terminate
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?(GREETER :50 TERMINATE SIGNAL=15|XSERVER :50 TERMINATE SIGNAL=15)
+#?RUNNER DAEMON-EXIT STATUS=0
index fde2cec8d03573e8bf7e13d872e6d03f42fdc80a..c2968733cddc757cb4c460d37abc49b15a56623f 100644 (file)
@@ -331,31 +331,45 @@ pam_authenticate (pam_handle_t *pamh, int flags)
         password_matches = TRUE;
     else
     {
-        int result;
+        int i, n_messages = 0, password_index, result;
         struct pam_message **msg;
         struct pam_response *resp = NULL;
-    
-        msg = malloc (sizeof (struct pam_message *) * 1);
-        msg[0] = malloc (sizeof (struct pam_message));
-        msg[0]->msg_style = PAM_PROMPT_ECHO_OFF;
-        msg[0]->msg = "Password:";
-        result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
-        free (msg[0]);
+
+        msg = malloc (sizeof (struct pam_message *) * 2);
+        if (strcmp (pamh->user, "info-prompt") == 0)
+        {
+            msg[n_messages] = malloc (sizeof (struct pam_message));
+            msg[n_messages]->msg_style = PAM_TEXT_INFO;
+            msg[n_messages]->msg = "Welcome to LightDM";
+            n_messages++;
+        }
+        msg[n_messages] = malloc (sizeof (struct pam_message));
+        msg[n_messages]->msg_style = PAM_PROMPT_ECHO_OFF;
+        msg[n_messages]->msg = "Password:";
+        password_index = n_messages;
+        n_messages++;
+        result = pamh->conversation.conv (n_messages, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
+        for (i = 0; i < n_messages; i++)
+            free (msg[i]);
         free (msg);
         if (result != PAM_SUCCESS)
             return result;
 
         if (resp == NULL)
             return PAM_CONV_ERR;
-        if (resp[0].resp == NULL)
+        if (resp[password_index].resp == NULL)
         {
             free (resp);
             return PAM_CONV_ERR;
         }
 
         if (entry)
-            password_matches = strcmp (entry->pw_passwd, resp[0].resp) == 0;
-        free (resp[0].resp);  
+            password_matches = strcmp (entry->pw_passwd, resp[password_index].resp) == 0;
+        for (i = 0; i < n_messages; i++)
+        {
+            if (resp[i].resp)
+                free (resp[i].resp);
+        }
         free (resp);
     }
 
index e40452906b405919d592564075a6983f1d52e1ba..a2061bf78cc8cda0dac432bdb1311a1aa836c26d 100644 (file)
@@ -1366,6 +1366,8 @@ main (int argc, char **argv)
         {"change-user-invalid", "",      TRUE,  "Invalid Change User",NULL,  NULL, NULL,          NULL,          1019},
         /* This account crashes on authentication */
         {"crash-authenticate", "",       TRUE,  "Crash Auth User",    NULL,  NULL, NULL,          NULL,          1020},
+        /* This account shows an informational prompt on login */
+        {"info-prompt",      "password", TRUE,  "Info Prompt",        NULL,  NULL, NULL,          NULL,          1021},
         {NULL,               NULL,       FALSE, NULL,                 NULL,  NULL, NULL,          NULL,             0}
     };
     passwd_data = g_string_new ("");
diff --git a/tests/test-login-gobject-info-prompt b/tests/test-login-gobject-info-prompt
new file mode 100755 (executable)
index 0000000..5f97568
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner login-info-prompt test-gobject-greeter
diff --git a/tests/test-login-python-info-prompt b/tests/test-login-python-info-prompt
new file mode 100755 (executable)
index 0000000..275429d
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner login-info-prompt test-python-greeter
diff --git a/tests/test-login-qt-info-prompt b/tests/test-login-qt-info-prompt
new file mode 100755 (executable)
index 0000000..29df469
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner login-info-prompt test-qt-greeter