Exemplo n.º 1
0
END_TEST

START_TEST(test_unregistered_auth_session)
{
    g_debug("%s", G_STRFUNC);
    g_type_init ();
    SignonIdentity *idty = signon_identity_new();
    fail_unless (idty != NULL);
    fail_unless (SIGNON_IS_IDENTITY (idty),
                 "Failed to initialize the Identity.");

    main_loop = g_main_loop_new (NULL, FALSE);

    GError *err = NULL;
    SignonAuthSession *as = signon_identity_create_session(idty,
                                                          "ssotest",
                                                           &err);
    /* give time to register the objects */
    g_timeout_add_seconds (2, test_quit_main_loop_cb, main_loop);
    g_main_loop_run (main_loop);

    /*
     * give the time for identity to became idle
     * */
    sleep(SIGNOND_IDLE_TIMEOUT);
    SignonIdentity *idty2 = signon_identity_new();

    /*
     * give time to handle unregistered signal
     * */
    g_timeout_add_seconds (5, test_quit_main_loop_cb, main_loop);
    g_main_loop_run (main_loop);


    gchar* patterns[4];
    patterns[0] = g_strdup("mech1");
    patterns[1] = g_strdup("mech2");
    patterns[2] = g_strdup("mech3");
    patterns[3] = NULL;

    signon_auth_session_query_available_mechanisms(as,
                                                  (const gchar**)patterns,
                                                  test_auth_session_query_mechanisms_cb,
                                                  (gpointer)patterns);
    g_main_loop_run (main_loop);

    g_object_unref (as);
    g_object_unref (idty);
    g_object_unref (idty2);

    g_free (patterns[0]);
    g_free (patterns[1]);
    g_free (patterns[2]);
    g_free (patterns[3]);
}
Exemplo n.º 2
0
static guint
new_identity()
{
    SignonIdentity *identity;
    GHashTable *methods;
    guint id = 0;

    if (main_loop == NULL)
        main_loop = g_main_loop_new (NULL, FALSE);

    identity = signon_identity_new(NULL, NULL);
    fail_unless (SIGNON_IS_IDENTITY (identity));
    methods = g_hash_table_new (g_str_hash, g_str_equal);
    signon_identity_store_credentials_with_args (identity,
                                                 "James Bond",
                                                 "007",
                                                 1,
                                                 methods,
                                                 "caption",
                                                 NULL,
                                                 NULL,
                                                 0,
                                                 new_identity_store_credentials_cb,
                                                 &id);
    g_hash_table_destroy (methods);

    if (id == 0)
        g_main_loop_run (main_loop);

    return id;

}
Exemplo n.º 3
0
END_TEST

START_TEST(test_unregistered_identity)
{
    g_type_init ();
    g_debug("%s", G_STRFUNC);
    SignonIdentity *idty = signon_identity_new();
    fail_unless (idty != NULL);
    fail_unless (SIGNON_IS_IDENTITY (idty),
                 "Failed to initialize the Identity.");

    SignonIdentityInfo *info = create_standard_info();
    main_loop = g_main_loop_new (NULL, FALSE);

    signon_identity_store_credentials_with_info (idty,
                                                 info,
                                                 store_credentials_identity_cb,
                                                 NULL);
    g_main_loop_run (main_loop);

    /*
     * give the time for identity to became idle
     * */
    sleep(SIGNOND_IDLE_TIMEOUT);
    SignonIdentity *idty2 = signon_identity_new();

    /*
     * give time to handle unregistered signal
     * */
    g_timeout_add_seconds (5, test_quit_main_loop_cb, main_loop);

    signon_identity_query_info (idty, identity_info_cb, &info);
    g_main_loop_run (main_loop);

    g_object_unref (idty);
    g_object_unref (idty2);
}
static void
uoa_set_account_password (TpAccount *tp_account,
    const gchar *password,
    gboolean remember,
    GSimpleAsyncResult *result)
{
  AgAccountService *service;
  AgAuthData *auth_data;
  guint cred_id;
  UoaChangePasswordData *data;
  SignonIdentity *identity;

  DEBUG ("Store password for %s in signond",
      tp_account_get_path_suffix (tp_account));

  service = uoa_password_common (tp_account, result, &auth_data);
  if (service == NULL)
    return;

  data = uoa_change_password_data_new (service, password, remember, result);

  cred_id = ag_auth_data_get_credentials_id (auth_data);
  if (cred_id == 0)
    {
      SignonIdentityInfo *info;
      const GHashTable *params;
      const gchar *username;
      const gchar *acl_all[] = { "*", NULL };

      /* This is the first time we store password for this account.
       * First check if we have an 'username' param as this is more accurate
       * in the tp-idle case. */
      params = tp_account_get_parameters (tp_account);
      username = tp_asv_get_string (params, "username");
      if (username == NULL)
        username = tp_asv_get_string (params, "account");

      identity = signon_identity_new ();
      info = signon_identity_info_new ();
      signon_identity_info_set_username (info, username);
      signon_identity_info_set_secret (info, password, remember);
      signon_identity_info_set_access_control_list (info, acl_all);

      /* Give identity and data ownership to the callback */
      signon_identity_store_credentials_with_info (identity, info,
          uoa_initial_identity_store_cb, data);

      signon_identity_info_free (info);
    }
  else
    {
      /* There is already a password stored, query info to update it.
       * Give identity and data ownership to the callback */
      identity = signon_identity_new_from_db (cred_id);
      signon_identity_query_info (identity,
          uoa_identity_query_info_cb, data);
    }

  g_object_unref (service);
  ag_auth_data_unref (auth_data);
}
Exemplo n.º 5
0
END_TEST

START_TEST(test_auth_session_process)
{
    g_type_init();
    gint state_counter = 0;
    GError *err = NULL;

    g_debug("%s", G_STRFUNC);
    SignonIdentity *idty = signon_identity_new(NULL, NULL);
    fail_unless (idty != NULL, "Cannot create Iddentity object");

    SignonAuthSession *auth_session = signon_identity_create_session(idty,
                                                                     "ssotest",
                                                                     &err);

    fail_unless (auth_session != NULL, "Cannot create AuthSession object");

    g_clear_error(&err);

    g_signal_connect(auth_session, "state-changed",
                     G_CALLBACK(test_auth_session_states_cb), &state_counter);

    GHashTable* sessionData = g_hash_table_new(g_str_hash,
                                               g_str_equal);
    GValue* usernameVa = g_new0(GValue, 1);
    gchar* usernameKey = g_strdup(SIGNON_SESSION_DATA_USERNAME);
    g_value_init (usernameVa, G_TYPE_STRING);
    g_value_set_static_string(usernameVa, "test_username");

    g_hash_table_insert (sessionData,
                         usernameKey,
                         usernameVa);

    GValue* passwordVa = g_new0(GValue, 1);
    gchar* passwordKey = g_strdup(SIGNON_SESSION_DATA_SECRET);

    g_value_init (passwordVa, G_TYPE_STRING);
    g_value_set_static_string(passwordVa, "test_username");

    g_hash_table_insert (sessionData,
                         passwordKey,
                         passwordVa);

    signon_auth_session_process(auth_session,
                               sessionData,
                               "mech1",
                               test_auth_session_process_cb,
                               sessionData);
    if(!main_loop)
        main_loop = g_main_loop_new (NULL, FALSE);


    g_main_loop_run (main_loop);
    fail_unless (state_counter == 12, "Wrong numer of state change signals: %d", state_counter);
    state_counter = 0;

    signon_auth_session_process(auth_session,
                               sessionData,
                               "mech1",
                               test_auth_session_process_cb,
                               sessionData);

    g_main_loop_run (main_loop);
    fail_unless (state_counter == 12, "Wrong numer of state change signals: %d", state_counter);
    state_counter = 0;

    signon_auth_session_process(auth_session,
                               sessionData,
                               "mech1",
                               test_auth_session_process_cb,
                               sessionData);

    g_main_loop_run (main_loop);
    fail_unless (state_counter == 12, "Wrong numer of state change signals: %d", state_counter);
    state_counter = 0;

    g_object_unref (auth_session);
    g_object_unref (idty);

    g_value_unset(usernameVa);
    g_free(usernameVa);
    g_free(usernameKey);

    g_value_unset(passwordVa);
    g_free(passwordVa);
    g_free(passwordKey);


}