summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2016-04-23 16:16:38 +0200
committerChristophe Fergeau <cfergeau@redhat.com>2016-06-20 12:39:44 +0200
commitef8530b0a3557e15b5cea8d12c5557dde7fad1f8 (patch)
treef0e606203e832e417aaa81e260be216be1d52773
parent5c98143086a37b728ac187a934028e650d1a6c0f (diff)
downloadlibrest-ef8530b0a3557e15b5cea8d12c5557dde7fad1f8.tar.gz
tests/oauth2: Convert to GTest api
-rw-r--r--tests/oauth2.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/tests/oauth2.c b/tests/oauth2.c
index 292ace3..23e609f 100644
--- a/tests/oauth2.c
+++ b/tests/oauth2.c
@@ -22,32 +22,45 @@
#include <rest/oauth2-proxy.h>
#include <string.h>
-void
-test_extract_token ()
+static void
+test_url_no_fragment ()
{
- char *token;
+ char *token = oauth2_proxy_extract_access_token ("http://example.com");
- /* test a url without a fragment */
- token = oauth2_proxy_extract_access_token ("http://example.com/");
- g_assert (token == NULL);
+ g_assert_null (token);
+}
- /* test a url with a fragment but without an access_token parameter */
- token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#bar");
- g_assert (token == NULL);
+static void
+test_url_fragment_no_access_token ()
+{
+ char *token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#bar");
- /* test simple access_token */
- token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#access_token=1234567890_12.34561abcdefg&bar");
- g_assert (strcmp(token, "1234567890_12.34561abcdefg") == 0);
+ g_assert_null (token);
+}
+
+static void
+test_access_token_simple ()
+{
+ char *token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#access_token=1234567890_12.34561abcdefg&bar");
+
+ g_assert_cmpstr (token, ==, "1234567890_12.34561abcdefg");
+}
+
+static void test_url_encoding_access_token ()
+{
+ char *token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#access_token=1234567890%5F12%2E34561abcdefg&bar");
- /* test access_token with url encoding */
- token = oauth2_proxy_extract_access_token ("http://example.com/foo?foo=1#access_token=1234567890%5F12%2E34561abcdefg&bar");
- g_assert (strcmp(token, "1234567890_12.34561abcdefg") == 0);
+ g_assert_cmpstr (token, ==, "1234567890_12.34561abcdefg");
}
int
main (int argc, char **argv)
{
- test_extract_token ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/oauth2/url-no-fragment", test_url_no_fragment);
+ g_test_add_func ("/oauth2/url-fragment-no-access-token", test_url_fragment_no_access_token);
+ g_test_add_func ("/oauth2/access-token-simple", test_access_token_simple);
+ g_test_add_func ("/oauth2/access-token-url-encoding", test_url_encoding_access_token);
- return 0;
+ return g_test_run ();
}