summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <philip@tecnocode.co.uk>2014-08-30 23:29:18 +0100
committerPhilip Withnall <philip@tecnocode.co.uk>2014-09-15 18:42:51 +0100
commit5e9c4ff3adc83bb21ac7a7436dcb0637b3662342 (patch)
treed7bcc4923008b28d0561fc07016f95fa037d78ed
parentff6c831378848cce5622cea8fb1236154e83f9d2 (diff)
downloadlibgdata-5e9c4ff3adc83bb21ac7a7436dcb0637b3662342.tar.gz
tests: Split OAuth helper function out of oauth1-authorizer tests
Move it to the common test library, as it will be useful in future for testing services which require OAuth authentication (such as Google Tasks).
-rw-r--r--gdata/tests/common.c29
-rw-r--r--gdata/tests/common.h2
-rw-r--r--gdata/tests/oauth1-authorizer.c24
3 files changed, 33 insertions, 22 deletions
diff --git a/gdata/tests/common.c b/gdata/tests/common.c
index b5d2fc79..abbede3c 100644
--- a/gdata/tests/common.c
+++ b/gdata/tests/common.c
@@ -981,3 +981,32 @@ gdata_test_mock_server_handle_message_timeout (UhmServer *server, SoupMessage *m
return TRUE;
}
+
+/**
+ * gdata_test_query_user_for_verifier:
+ * @authentication_uri: authentication URI to present
+ *
+ * Given an authentication URI, prompt the user to go to that URI, grant access
+ * to the test application and enter the resulting verifier. This is to be used
+ * with interactive OAuth authorisation requests.
+ *
+ * Returns: (transfer full): verifier from the web page
+ */
+gchar *
+gdata_test_query_user_for_verifier (const gchar *authentication_uri)
+{
+ char verifier[100];
+
+ /* Wait for the user to retrieve and enter the verifier */
+ g_print ("Please navigate to the following URI and grant access: %s\n", authentication_uri);
+ g_print ("Enter verifier (EOF to skip test): ");
+ if (scanf ("%100s", verifier) != 1) {
+ /* Skip the test */
+ g_test_message ("Skipping test on user request.");
+ return NULL;
+ }
+
+ g_test_message ("Proceeding with user-provided verifier ā€œ%sā€.", verifier);
+
+ return g_strdup (verifier);
+}
diff --git a/gdata/tests/common.h b/gdata/tests/common.h
index 06319b3f..92ff7538 100644
--- a/gdata/tests/common.h
+++ b/gdata/tests/common.h
@@ -337,6 +337,8 @@ void gdata_test_mock_server_start_trace (UhmServer *server, const gchar *trace_f
gboolean gdata_test_mock_server_handle_message_error (UhmServer *server, SoupMessage *message, SoupClientContext *client, gpointer user_data);
gboolean gdata_test_mock_server_handle_message_timeout (UhmServer *server, SoupMessage *message, SoupClientContext *client, gpointer user_data);
+gchar *gdata_test_query_user_for_verifier (const gchar *authentication_uri) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
+
G_END_DECLS
#endif /* !GDATA_TEST_COMMON_H */
diff --git a/gdata/tests/oauth1-authorizer.c b/gdata/tests/oauth1-authorizer.c
index 30470ca5..46e723b3 100644
--- a/gdata/tests/oauth1-authorizer.c
+++ b/gdata/tests/oauth1-authorizer.c
@@ -145,26 +145,6 @@ set_up_oauth1_authorizer_data_locale (OAuth1AuthorizerData *data, gconstpointer
connect_to_oauth1_authorizer (data);
}
-/* Given an authentication URI, prompt the user to go to that URI, grant access to the test application and enter the resulting verifier */
-static gchar *
-query_user_for_verifier (const gchar *authentication_uri)
-{
- char verifier[100];
-
- /* Wait for the user to retrieve and enter the verifier */
- g_print ("Please navigate to the following URI and grant access: %s\n", authentication_uri);
- g_print ("Enter verifier (EOF to skip test): ");
- if (scanf ("%100s", verifier) != 1) {
- /* Skip the test */
- g_test_message ("Skipping test on user request.");
- return NULL;
- }
-
- g_test_message ("Proceeding with user-provided verifier ā€œ%sā€.", verifier);
-
- return g_strdup (verifier);
-}
-
static void
set_up_oauth1_authorizer_data_authenticated (OAuth1AuthorizerData *data, gconstpointer user_data)
{
@@ -181,7 +161,7 @@ set_up_oauth1_authorizer_data_authenticated (OAuth1AuthorizerData *data, gconstp
g_assert (authentication_uri != NULL);
/* Get the verifier off the user */
- verifier = query_user_for_verifier (authentication_uri);
+ verifier = gdata_test_query_user_for_verifier (authentication_uri);
g_free (authentication_uri);
@@ -689,7 +669,7 @@ set_up_oauth1_authorizer_interactive_data (OAuth1AuthorizerInteractiveData *data
g_assert (authentication_uri != NULL);
/* Wait for the user to retrieve and enter the verifier */
- data->verifier = query_user_for_verifier (authentication_uri);
+ data->verifier = gdata_test_query_user_for_verifier (authentication_uri);
g_free (authentication_uri);