~ubuntu-branches/ubuntu/natty/gnome-keyring/natty

« back to all changes in this revision

Viewing changes to library/tests/unit-test-login-prompt.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-02-16 19:00:06 UTC
  • mfrom: (1.1.58 upstream)
  • Revision ID: james.westby@ubuntu.com-20100216190006-cqpnic4zxlkmmi0o
Tags: 2.29.90git20100218-0ubuntu1
Updated to a git snapshot version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
/* unit-test-keyrings-prompt.c: Test basic prompt functionality
3
 
 
4
 
   Copyright (C) 2007 Stefan Walter
5
 
 
6
 
   The Gnome Keyring Library is free software; you can redistribute it and/or
7
 
   modify it under the terms of the GNU Library General Public License as
8
 
   published by the Free Software Foundation; either version 2 of the
9
 
   License, or (at your option) any later version.
10
 
 
11
 
   The Gnome Keyring Library is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
   Library General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU Library General Public
17
 
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
18
 
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
 
   Boston, MA 02111-1307, USA.
20
 
 
21
 
   Author: Stef Walter <stef@memberwebs.com>
22
 
*/
23
 
 
24
 
#include <stdlib.h>
25
 
#include <stdio.h>
26
 
#include <string.h>
27
 
#include <unistd.h>
28
 
 
29
 
#include "run-prompt-test.h"
30
 
 
31
 
#include "library/gnome-keyring.h"
32
 
 
33
 
static void 
34
 
TELL(const char* what)
35
 
{
36
 
        printf("INTERACTION: %s\n", what);
37
 
}
38
 
 
39
 
 
40
 
#define THE_PASSWORD "test"
41
 
#define OTHER_PASSWORD "other"
42
 
#define KEYRING_LOGIN "login"
43
 
#define KEYRING_NAME "auto-unlock-keyring"
44
 
#define DISPLAY_NAME "Item Display Name"
45
 
#define SECRET "item-secret"
46
 
 
47
 
DEFINE_TEST(create_unlock_login)
48
 
{
49
 
        GnomeKeyringResult res;
50
 
        
51
 
        /* Remove the login keyring */
52
 
        res = gnome_keyring_delete_sync (KEYRING_LOGIN);
53
 
        if (res != GNOME_KEYRING_RESULT_NO_SUCH_KEYRING)
54
 
                g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
55
 
        
56
 
        /* Now create it with our password */
57
 
        res = gnome_keyring_create_sync (KEYRING_LOGIN, THE_PASSWORD);
58
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
59
 
}
60
 
 
61
 
DEFINE_TEST(auto_keyring)
62
 
{
63
 
        GnomeKeyringResult res;
64
 
 
65
 
        /* Remove the auto unlock keyring */
66
 
        res = gnome_keyring_delete_sync (KEYRING_NAME);
67
 
        if (res != GNOME_KEYRING_RESULT_NO_SUCH_KEYRING)
68
 
                g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
69
 
        
70
 
        res = gnome_keyring_create_sync (KEYRING_NAME, THE_PASSWORD);
71
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
72
 
        
73
 
        res = gnome_keyring_lock_sync (KEYRING_NAME);
74
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
75
 
 
76
 
        /* Prompt the user to unlock, and check the option */
77
 
        TELL("type 'test' as the password and check the 'Automatically unlock' option");
78
 
        res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
79
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
80
 
 
81
 
        res = gnome_keyring_lock_sync (KEYRING_NAME);
82
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
83
 
 
84
 
        TELL("No prompt should show up at this point");
85
 
        res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
86
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
87
 
        sleep(2);
88
 
}
89
 
 
90
 
DEFINE_TEST(auto_keyring_stale)
91
 
{
92
 
        GnomeKeyringResult res;
93
 
        
94
 
        /* Remove the auto unlock keyring */
95
 
        res = gnome_keyring_change_password_sync (KEYRING_NAME, THE_PASSWORD, OTHER_PASSWORD);
96
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
97
 
 
98
 
        res = gnome_keyring_lock_sync (KEYRING_NAME);
99
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
100
 
        
101
 
        TELL("Press 'deny' here");      
102
 
        res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
103
 
        g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);
104
 
}