Commit dab14c96 authored by Corentin Noël's avatar Corentin Noël

AuthSession: remove the mechanism getter that is already provided by AuthService

parent 2627b4eb
...@@ -41,8 +41,6 @@ signon_auth_session_get_method ...@@ -41,8 +41,6 @@ signon_auth_session_get_method
signon_auth_session_new signon_auth_session_new
signon_auth_session_process signon_auth_session_process
signon_auth_session_process_finish signon_auth_session_process_finish
signon_auth_session_list_available_mechanisms
signon_auth_session_list_available_mechanisms_finish
<SUBSECTION Private> <SUBSECTION Private>
SignonAuthSessionClass SignonAuthSessionClass
SignonAuthSessionPrivate SignonAuthSessionPrivate
......
...@@ -124,7 +124,6 @@ static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, gpointer ...@@ -124,7 +124,6 @@ static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, gpointer
static gboolean auth_session_priv_init (SignonAuthSession *self, guint id, const gchar *method_name, GError **err); static gboolean auth_session_priv_init (SignonAuthSession *self, guint id, const gchar *method_name, GError **err);
static void auth_session_set_id_ready_cb (gpointer object, const GError *error, gpointer user_data); static void auth_session_set_id_ready_cb (gpointer object, const GError *error, gpointer user_data);
static void auth_session_list_available_mechanisms_ready_cb (gpointer object, const GError *error, gpointer user_data);
static void auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data); static void auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data);
static void auth_session_check_remote_object(SignonAuthSession *self); static void auth_session_check_remote_object(SignonAuthSession *self);
...@@ -430,68 +429,6 @@ signon_auth_session_get_method (SignonAuthSession *self) ...@@ -430,68 +429,6 @@ signon_auth_session_get_method (SignonAuthSession *self)
return priv->method_name; return priv->method_name;
} }
/**
* signon_auth_session_list_available_mechanisms:
* @self: the #SignonAuthSession.
* @wanted_mechanisms: (array zero-terminated=1): a %NULL-terminated list of mechanisms supported by the client.
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
* @callback: a callback which will be called when the
* authentication reply is available.
* @user_data: user data to be passed to the callback.
*
* Queries the mechanisms available for this authentication session. the result
* will be the intersection between @wanted_mechanisms and the mechanisms
* supported by the authentication plugin.
*
* Since: 2.0
*/
void signon_auth_session_list_available_mechanisms (SignonAuthSession *self,
const gchar **wanted_mechanisms,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
SignonAuthSessionPrivate *priv;
GTask *res;
g_return_if_fail (SIGNON_IS_AUTH_SESSION (self));
priv = self->priv;
g_return_if_fail (priv != NULL);
res = g_task_new (self, cancellable, callback, user_data);
g_task_set_task_data (res, g_strdupv ((gchar**) wanted_mechanisms), (GDestroyNotify)g_strfreev);
priv->busy = TRUE;
signon_proxy_call_when_ready (self,
auth_session_object_quark(),
auth_session_list_available_mechanisms_ready_cb,
res);
}
/**
* signon_auth_session_list_available_mechanisms_finish:
* @self: the #SignonAuthSession.
* @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to
* signon_auth_session_list_available_mechanisms().
* @error: return location for error, or %NULL.
*
* Collect the result of the signon_auth_session_list_available_mechanisms()
* operation.
*
* Returns: (transfer full) (array zero-terminated=1): a list of available
* mechanisms.
*/
gchar **signon_auth_session_list_available_mechanisms_finish (SignonAuthSession *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (res, self), NULL);
return g_task_propagate_pointer (G_TASK (res), error);
}
/** /**
* signon_auth_session_process: * signon_auth_session_process:
* @self: the #SignonAuthSession. * @self: the #SignonAuthSession.
...@@ -521,26 +458,26 @@ signon_auth_session_process (SignonAuthSession *self, ...@@ -521,26 +458,26 @@ signon_auth_session_process (SignonAuthSession *self,
{ {
SignonAuthSessionPrivate *priv; SignonAuthSessionPrivate *priv;
AuthSessionProcessData *process_data; AuthSessionProcessData *process_data;
GTask *res; GTask *task = NULL;
g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); g_return_if_fail (SIGNON_IS_AUTH_SESSION (self));
priv = self->priv; priv = self->priv;
g_return_if_fail (session_data != NULL); g_return_if_fail (session_data != NULL);
res = g_task_new (self, cancellable, callback, user_data); task = g_task_new (self, cancellable, callback, user_data);
process_data = g_slice_new0 (AuthSessionProcessData); process_data = g_slice_new0 (AuthSessionProcessData);
process_data->session_data = g_variant_ref_sink (session_data); process_data->session_data = g_variant_ref_sink (session_data);
process_data->mechanism = g_strdup (mechanism); process_data->mechanism = g_strdup (mechanism);
g_task_set_task_data (res, process_data, (GDestroyNotify)auth_session_process_data_free); g_task_set_task_data (task, process_data, (GDestroyNotify)auth_session_process_data_free);
priv->busy = TRUE; priv->busy = TRUE;
signon_proxy_call_when_ready (self, signon_proxy_call_when_ready (self,
auth_session_object_quark(), auth_session_object_quark(),
auth_session_process_ready_cb, auth_session_process_ready_cb,
res); task);
} }
/** /**
...@@ -714,74 +651,6 @@ auth_session_priv_init (SignonAuthSession *self, guint id, ...@@ -714,74 +651,6 @@ auth_session_priv_init (SignonAuthSession *self, guint id,
return TRUE; return TRUE;
} }
static void
auth_session_query_mechanisms_reply (GObject *object,
GAsyncResult *res,
gpointer userdata)
{
SsoAuthSession *proxy = SSO_AUTH_SESSION (object);
gchar **mechanisms = NULL;
GError *error = NULL;
GTask *task = (GTask *)userdata;
g_return_if_fail (task != NULL);
if (g_task_return_error_if_cancelled (task))
{
g_object_unref (task);
return;
}
sso_auth_session_call_query_available_mechanisms_finish (proxy,
&mechanisms,
res,
&error);
if (error)
{
g_task_return_error (task, error);
g_object_unref (task);
return;
}
g_task_return_pointer (task, mechanisms, (GDestroyNotify)g_strfreev);
g_object_unref (task);
}
static void
auth_session_list_available_mechanisms_ready_cb (gpointer object,
const GError *error,
gpointer user_data)
{
g_return_if_fail (SIGNON_IS_AUTH_SESSION (object));
SignonAuthSession *self = SIGNON_AUTH_SESSION (object);
SignonAuthSessionPrivate *priv = self->priv;
g_return_if_fail (priv != NULL);
GTask *task = (GTask *)user_data;
g_return_if_fail (task != NULL);
if (error)
{
g_task_return_error (task, g_error_copy (error));
g_object_unref (task);
}
else
{
g_return_if_fail (priv->proxy != NULL);
sso_auth_session_call_query_available_mechanisms (
priv->proxy,
(const char **)g_task_get_task_data (task),
g_task_get_cancellable (task),
auth_session_query_mechanisms_reply,
task);
g_signal_emit (self,
auth_session_signals[STATE_CHANGED],
0,
SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING,
auth_session_process_pending_message);
}
}
static void static void
auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data) auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data)
{ {
......
...@@ -148,15 +148,6 @@ SignonAuthSession *signon_auth_session_new(gint id, ...@@ -148,15 +148,6 @@ SignonAuthSession *signon_auth_session_new(gint id,
const gchar *signon_auth_session_get_method (SignonAuthSession *self); const gchar *signon_auth_session_get_method (SignonAuthSession *self);
void signon_auth_session_list_available_mechanisms (SignonAuthSession *self,
const gchar **wanted_mechanisms,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar **signon_auth_session_list_available_mechanisms_finish (SignonAuthSession *self,
GAsyncResult *res,
GError **error);
void signon_auth_session_process (SignonAuthSession *self, void signon_auth_session_process (SignonAuthSession *self,
GVariant *session_data, GVariant *session_data,
const gchar *mechanism, const gchar *mechanism,
......
...@@ -251,13 +251,15 @@ START_TEST(test_query_mechanisms) ...@@ -251,13 +251,15 @@ START_TEST(test_query_mechanisms)
END_TEST END_TEST
static void static void
test_auth_session_query_mechanisms_cb (GObject *source_object, test_auth_session_process2_async_cb (GObject *source_object,
GAsyncResult *res, GAsyncResult *res,
gpointer user_data) gpointer user_data)
{ {
SignonAuthSession *self = (SignonAuthSession *)source_object; SignonAuthSession *self = (SignonAuthSession *)source_object;
GError *error = NULL; GError *error = NULL;
gchar **mechanisms = signon_auth_session_list_available_mechanisms_finish (self, res, &error); GVariant *reply = signon_auth_session_process_finish (self, res, &error);
gboolean ok;
if (error) if (error)
{ {
g_warning ("%s: %s", G_STRFUNC, error->message); g_warning ("%s: %s", G_STRFUNC, error->message);
...@@ -266,147 +268,19 @@ test_auth_session_query_mechanisms_cb (GObject *source_object, ...@@ -266,147 +268,19 @@ test_auth_session_query_mechanisms_cb (GObject *source_object,
fail(); fail();
} }
fail_unless (mechanisms != NULL, "The mechanisms does not exist"); fail_unless (reply != NULL, "Could not process the auth session");
gchar** patterns = (gchar**)user_data;
int i = g_strv_length(mechanisms);
fail_unless( i == g_strv_length(patterns), "The number of obtained methods is wrong: %d %s", i);
while ( i > 0 )
{
gchar* pattern = patterns[--i];
fail_unless(_contains(mechanisms, pattern), "The obtained mechanism list does not contain %s", pattern);
}
g_strfreev(mechanisms);
g_main_loop_quit (main_loop);
}
START_TEST(test_auth_session_query_mechanisms)
{
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, gchar* username2 = NULL;
"ssotest",
&err);
fail_unless (auth_session != NULL, "Cannot create AuthSession object");
g_clear_error(&err);
gchar* patterns[4]; ok = g_variant_lookup (reply, SIGNON_SESSION_DATA_USERNAME, "&s", &username2);
patterns[0] = g_strdup("mech1"); ck_assert (ok);
patterns[1] = g_strdup("mech2"); ck_assert_str_eq (username2, "test_username");
patterns[2] = g_strdup("mech3");
patterns[3] = NULL;
signon_auth_session_list_available_mechanisms (auth_session,
(const gchar**)patterns,
NULL,
test_auth_session_query_mechanisms_cb,
(gpointer)patterns);
if(!main_loop)
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
g_free(patterns[2]);
patterns[2] = NULL;
signon_auth_session_list_available_mechanisms (auth_session,
(const gchar**)patterns,
NULL,
test_auth_session_query_mechanisms_cb,
(gpointer)patterns);
g_main_loop_run (main_loop);
g_free(patterns[1]);
patterns[1] = NULL;
signon_auth_session_list_available_mechanisms (auth_session,
(const gchar**)patterns,
NULL,
test_auth_session_query_mechanisms_cb,
(gpointer)patterns);
g_main_loop_run (main_loop);
g_free(patterns[0]);
g_object_unref(auth_session);
g_object_unref(idty);
end_test ();
}
END_TEST
static void g_variant_unref (reply);
test_auth_session_query_mechanisms_nonexisting_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
SignonAuthSession *self = (SignonAuthSession *)source_object;
GError *error = NULL;
gchar **mechanisms = signon_auth_session_list_available_mechanisms_finish (self, res, &error);
if (!error)
{
g_strfreev (mechanisms);
g_main_loop_quit (main_loop);
fail();
return;
}
g_warning ("%s: %s", G_STRFUNC, error->message);
g_error_free (error);
g_main_loop_quit (main_loop); g_main_loop_quit (main_loop);
} }
START_TEST(test_auth_session_query_mechanisms_nonexisting)
{
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,
"nonexisting",
&err);
fail_unless (auth_session != NULL, "Cannot create AuthSession object");
g_clear_error(&err);
gchar* patterns[4];
patterns[0] = g_strdup("mech1");
patterns[1] = g_strdup("mech2");
patterns[2] = g_strdup("mech3");
patterns[3] = NULL;
signon_auth_session_list_available_mechanisms (auth_session,
(const gchar**)patterns,
NULL,
test_auth_session_query_mechanisms_nonexisting_cb,
(gpointer)patterns);
if(!main_loop)
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
g_free(patterns[0]);
g_free(patterns[1]);
g_free(patterns[2]);
g_object_unref(auth_session);
g_object_unref(idty);
end_test ();
}
END_TEST
static void static void
test_auth_session_states_cb (SignonAuthSession *self, test_auth_session_states_cb (SignonAuthSession *self,
gint state, gint state,
...@@ -475,7 +349,7 @@ START_TEST(test_auth_session_process_async) ...@@ -475,7 +349,7 @@ START_TEST(test_auth_session_process_async)
g_debug("%s", G_STRFUNC); g_debug("%s", G_STRFUNC);
SignonIdentity *idty = signon_identity_new(NULL, NULL); SignonIdentity *idty = signon_identity_new(NULL, NULL);
fail_unless (idty != NULL, "Cannot create Iddentity object"); fail_unless (idty != NULL, "Cannot create Identity object");
SignonAuthSession *auth_session = signon_identity_create_session(idty, SignonAuthSession *auth_session = signon_identity_create_session(idty,
"ssotest", "ssotest",
...@@ -654,7 +528,6 @@ test_auth_session_process_after_store_start_session (GObject *source_object, ...@@ -654,7 +528,6 @@ test_auth_session_process_after_store_start_session (GObject *source_object,
NULL, NULL,
test_auth_session_process_after_store_cb, test_auth_session_process_after_store_cb,
NULL); NULL);
g_object_unref (session_data);
} }
START_TEST(test_auth_session_process_after_store) START_TEST(test_auth_session_process_after_store)
...@@ -1328,7 +1201,7 @@ START_TEST(test_unregistered_auth_session) ...@@ -1328,7 +1201,7 @@ START_TEST(test_unregistered_auth_session)
SIGNON_SESSION_DATA_SECRET, SIGNON_SESSION_DATA_SECRET,
g_variant_new_string ("test_pw")); g_variant_new_string ("test_pw"));
session_data = g_variant_builder_end (&builder); session_data = g_variant_ref_sink (g_variant_builder_end (&builder));
signon_auth_session_process (as, signon_auth_session_process (as,
session_data, session_data,
...@@ -1339,7 +1212,6 @@ START_TEST(test_unregistered_auth_session) ...@@ -1339,7 +1212,6 @@ START_TEST(test_unregistered_auth_session)
g_main_loop_run (main_loop); g_main_loop_run (main_loop);
fail_unless (reply != NULL); fail_unless (reply != NULL);
session_data = NULL;
ok = g_variant_lookup (reply, SIGNON_SESSION_DATA_USERNAME, "&s", &username); ok = g_variant_lookup (reply, SIGNON_SESSION_DATA_USERNAME, "&s", &username);
ck_assert (ok); ck_assert (ok);
...@@ -1353,11 +1225,12 @@ START_TEST(test_unregistered_auth_session) ...@@ -1353,11 +1225,12 @@ START_TEST(test_unregistered_auth_session)
patterns[2] = g_strdup("mech3"); patterns[2] = g_strdup("mech3");
patterns[3] = NULL; patterns[3] = NULL;
signon_auth_session_list_available_mechanisms(as, signon_auth_session_process (as,
(const gchar**)patterns, session_data,
NULL, "mech1",
test_auth_session_query_mechanisms_cb, NULL,
(gpointer)patterns); test_auth_session_process2_async_cb,
NULL);
g_main_loop_run (main_loop); g_main_loop_run (main_loop);
g_object_unref (as); g_object_unref (as);
...@@ -1431,7 +1304,6 @@ START_TEST(test_regression_unref) ...@@ -1431,7 +1304,6 @@ START_TEST(test_regression_unref)
NULL, NULL,
test_regression_unref_process_cb, test_regression_unref_process_cb,
"Hi there!"); "Hi there!");
g_object_unref (session_data);
g_main_loop_run (main_loop); g_main_loop_run (main_loop);
end_test (); end_test ();
...@@ -1457,8 +1329,6 @@ signon_suite(void) ...@@ -1457,8 +1329,6 @@ signon_suite(void)
tcase_add_test (tc_core, test_get_nonexisting_identity); tcase_add_test (tc_core, test_get_nonexisting_identity);
tcase_add_test (tc_core, test_auth_session_creation); tcase_add_test (tc_core, test_auth_session_creation);
tcase_add_test (tc_core, test_auth_session_query_mechanisms);
tcase_add_test (tc_core, test_auth_session_query_mechanisms_nonexisting);
tcase_add_test (tc_core, test_auth_session_process_async); tcase_add_test (tc_core, test_auth_session_process_async);
tcase_add_test (tc_core, test_auth_session_process_failure); tcase_add_test (tc_core, test_auth_session_process_failure);
tcase_add_test (tc_core, test_auth_session_process_after_store); tcase_add_test (tc_core, test_auth_session_process_after_store);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment