| 1 | /* Replaces only the keyring calls at link time. The executable under test uses |
| 2 | * the real libsecret schema/values and GLib ownership, without a desktop bus. */ |
| 3 | #include <libsecret/secret.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | static const char *scenario; |
| 7 | |
| 8 | GList *__wrap_secret_service_search_sync(SecretService *service, const SecretSchema *schema, |
| 9 | GHashTable *attributes, SecretSearchFlags flags, |
| 10 | GCancellable *cancellable, GError **error) { |
| 11 | g_assert_null(service); |
| 12 | g_assert_null(cancellable); |
| 13 | g_assert_cmpstr(schema->name, ==, "chrome_libsecret_os_crypt_password_v2"); |
| 14 | g_assert_cmpint(schema->flags, ==, SECRET_SCHEMA_DONT_MATCH_NAME); |
| 15 | g_assert_cmpint(flags, ==, SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS); |
| 16 | g_assert_cmpuint(g_hash_table_size(attributes), ==, 1); |
| 17 | scenario = g_intern_string(g_hash_table_lookup(attributes, "application")); |
| 18 | if (strcmp(scenario, "missing") == 0) return NULL; |
| 19 | if (strcmp(scenario, "cancelled") == 0) { |
| 20 | g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_CANCELLED, "cancelled"); |
| 21 | return NULL; |
| 22 | } |
| 23 | if (strcmp(scenario, "denied") == 0) { |
| 24 | g_set_error_literal(error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED, "denied"); |
| 25 | return NULL; |
| 26 | } |
| 27 | if (strcmp(scenario, "unavailable") == 0) { |
| 28 | g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED, "unavailable"); |
| 29 | return NULL; |
| 30 | } |
| 31 | return g_list_append(NULL, g_object_new(SECRET_TYPE_ITEM, NULL)); |
| 32 | } |
| 33 | |
| 34 | gboolean __wrap_secret_item_get_locked(SecretItem *item) { |
| 35 | g_assert_true(SECRET_IS_ITEM(item)); |
| 36 | return strcmp(scenario, "locked") == 0; |
| 37 | } |
| 38 | |
| 39 | SecretValue *__wrap_secret_item_get_secret(SecretItem *item) { |
| 40 | g_assert_true(SECRET_IS_ITEM(item)); |
| 41 | if (strcmp(scenario, "unloaded") == 0) return NULL; |
| 42 | if (strcmp(scenario, "empty") == 0) return secret_value_new("", 0, "text/plain"); |
| 43 | const char value[] = "secret\0with whitespace \t\r\n"; |
| 44 | return secret_value_new(value, sizeof(value) - 1, "application/octet-stream"); |
| 45 | } |