| 1 |
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
| 2 |
/* test-secret-compat.c: Test secret compat files |
| 3 |
|
| 4 |
Copyright (C) 2008 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 |
<http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
Author: Stef Walter <[email protected]> |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
|
| 25 |
#include "secret-store/gkm-secret-compat.h" |
| 26 |
|
| 27 |
#include <glib.h> |
| 28 |
|
| 29 |
#include <stdlib.h> |
| 30 |
#include <stdio.h> |
| 31 |
#include <string.h> |
| 32 |
|
| 33 |
static void |
| 34 |
test_access_free (void) |
| 35 |
{ |
| 36 |
GkmSecretAccess *ac; |
| 37 |
|
| 38 |
ac = g_new0 (GkmSecretAccess, 1); |
| 39 |
ac->pathname = g_strdup ("/path"); |
| 40 |
ac->display_name = g_strdup ("Display"); |
| 41 |
ac->types_allowed = GKM_SECRET_ACCESS_READ; |
| 42 |
|
| 43 |
gkm_secret_compat_access_free (ac); |
| 44 |
} |
| 45 |
|
| 46 |
static void |
| 47 |
test_acl_free (void) |
| 48 |
{ |
| 49 |
GkmSecretAccess *ac; |
| 50 |
GList *acl = NULL; |
| 51 |
int i; |
| 52 |
|
| 53 |
for (i = 0; i < 10; ++i) { |
| 54 |
ac = g_new0 (GkmSecretAccess, 1); |
| 55 |
ac->pathname = g_strdup ("/path"); |
| 56 |
ac->display_name = g_strdup ("Display"); |
| 57 |
ac->types_allowed = GKM_SECRET_ACCESS_READ; |
| 58 |
acl = g_list_prepend (acl, ac); |
| 59 |
} |
| 60 |
|
| 61 |
gkm_secret_compat_acl_free (acl); |
| 62 |
} |
| 63 |
|
| 64 |
static void |
| 65 |
test_parse_item_type (void) |
| 66 |
{ |
| 67 |
guint type; |
| 68 |
|
| 69 |
type = gkm_secret_compat_parse_item_type ("org.freedesktop.Secret.Generic"); |
| 70 |
g_assert_cmpuint (type, ==, 0); |
| 71 |
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.NetworkPassword"); |
| 72 |
g_assert_cmpuint (type, ==, 1); |
| 73 |
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.Note"); |
| 74 |
g_assert_cmpuint (type, ==, 2); |
| 75 |
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.ChainedKeyring"); |
| 76 |
g_assert_cmpuint (type, ==, 3); |
| 77 |
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.EncryptionKey"); |
| 78 |
g_assert_cmpuint (type, ==, 4); |
| 79 |
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.PkStorage"); |
| 80 |
g_assert_cmpuint (type, ==, 0x100); |
| 81 |
|
| 82 |
/* Invalid returns generic secret */ |
| 83 |
type = gkm_secret_compat_parse_item_type ("invalid"); |
| 84 |
g_assert_cmpuint (type, ==, 0); |
| 85 |
|
| 86 |
/* Null returns generic secret */ |
| 87 |
type = gkm_secret_compat_parse_item_type (NULL); |
| 88 |
g_assert_cmpuint (type, ==, 0); |
| 89 |
} |
| 90 |
|
| 91 |
static void |
| 92 |
test_format_item_type (void) |
| 93 |
{ |
| 94 |
const gchar *type; |
| 95 |
|
| 96 |
type = gkm_secret_compat_format_item_type (0); |
| 97 |
g_assert_cmpstr (type, ==, "org.freedesktop.Secret.Generic"); |
| 98 |
type = gkm_secret_compat_format_item_type (1); |
| 99 |
g_assert_cmpstr (type, ==, "org.gnome.keyring.NetworkPassword"); |
| 100 |
type = gkm_secret_compat_format_item_type (2); |
| 101 |
g_assert_cmpstr (type, ==, "org.gnome.keyring.Note"); |
| 102 |
type = gkm_secret_compat_format_item_type (3); |
| 103 |
g_assert_cmpstr (type, ==, "org.gnome.keyring.ChainedKeyring"); |
| 104 |
type = gkm_secret_compat_format_item_type (4); |
| 105 |
g_assert_cmpstr (type, ==, "org.gnome.keyring.EncryptionKey"); |
| 106 |
type = gkm_secret_compat_format_item_type (0x100); |
| 107 |
g_assert_cmpstr (type, ==, "org.gnome.keyring.PkStorage"); |
| 108 |
|
| 109 |
/* Higher bits shouldn't make a difference */ |
| 110 |
type = gkm_secret_compat_format_item_type (0xF0000001); |
| 111 |
g_assert_cmpstr (type, ==, "org.gnome.keyring.NetworkPassword"); |
| 112 |
|
| 113 |
/* Unrecognized should be null */ |
| 114 |
type = gkm_secret_compat_format_item_type (32); |
| 115 |
g_assert (type == NULL); |
| 116 |
} |
| 117 |
|
| 118 |
int |
| 119 |
main (int argc, char **argv) |
| 120 |
{ |
| 121 |
g_test_init (&argc, &argv, NULL); |
| 122 |
|
| 123 |
g_test_add_func ("/secret-store/compat/access_free", test_access_free); |
| 124 |
g_test_add_func ("/secret-store/compat/acl_free", test_acl_free); |
| 125 |
g_test_add_func ("/secret-store/compat/parse_item_type", test_parse_item_type); |
| 126 |
g_test_add_func ("/secret-store/compat/format_item_type", test_format_item_type); |
| 127 |
|
| 128 |
return g_test_run (); |
| 129 |
} |