1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
/* unit-test-keyrings-prompt.c: Test basic prompt functionality
4
Copyright (C) 2007 Stefan Walter
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.
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.
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.
21
Author: Stef Walter <stef@memberwebs.com>
29
#include "run-prompt-test.h"
31
#include "library/gnome-keyring.h"
34
TELL(const char* what)
36
printf("INTERACTION: %s\n", what);
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"
47
DEFINE_TEST(create_unlock_login)
49
GnomeKeyringResult res;
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);
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);
61
DEFINE_TEST(auto_keyring)
63
GnomeKeyringResult res;
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);
70
res = gnome_keyring_create_sync (KEYRING_NAME, THE_PASSWORD);
71
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
73
res = gnome_keyring_lock_sync (KEYRING_NAME);
74
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
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);
81
res = gnome_keyring_lock_sync (KEYRING_NAME);
82
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
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);
90
DEFINE_TEST(auto_keyring_stale)
92
GnomeKeyringResult res;
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);
98
res = gnome_keyring_lock_sync (KEYRING_NAME);
99
g_assert_cmpint (GNOME_KEYRING_RESULT_OK, ==, res);
101
TELL("Press 'deny' here");
102
res = gnome_keyring_unlock_sync (KEYRING_NAME, NULL);
103
g_assert_cmpint (GNOME_KEYRING_RESULT_DENIED, ==, res);