#include "assert.h"
#include <oauth2.h>
#include <string.h>
-#include <glib-2.0/glib.h>
-#include <dlog.h>
-#define OAUTH2_FREE(ptr) \
- if (ptr != NULL) { \
- free(ptr); \
+#define OAUTH2_FREE(ptr) \
+ if (ptr != NULL) { \
+ free(ptr); \
ptr = NULL; \
}
static bool request_created = false;
static oauth2_manager_h manager = NULL;
static oauth2_request_h request = NULL;
-static GMainLoop* mainloop = NULL;
static int _is_fail = true;
-static gboolean timeout_cb(gpointer data) {
- printf("timeout!\n");
- _is_fail = true;
- g_main_loop_quit((GMainLoop*)data);
- return FALSE;
-}
-
void utc_oauth2_startup(void)
{
int ret = OAUTH2_ERROR_NONE;
ret = oauth2_manager_create(&manager);
if (ret == OAUTH2_ERROR_NONE)
- {
manager_created = true;
- }
ret = oauth2_request_create(&request);
if (ret == OAUTH2_ERROR_NONE)
- {
request_created = true;
- }
}
void utc_oauth2_cleanup(void)
int ret = OAUTH2_ERROR_NONE;
ret = oauth2_manager_destroy(manager);
if (ret == OAUTH2_ERROR_NONE)
- {
manager_created = false;
- }
+
+ manager = NULL;
ret = oauth2_request_destroy(request);
if (ret == OAUTH2_ERROR_NONE)
- {
request_created = false;
- }
+
+ request = NULL;
}
int utc_oauth2_manager_create_p(void)
int oauth2_manager_destroy_p(void)
{
- assert(manager_created);
- utc_oauth2_cleanup();
+ oauth2_manager_h manager_local = NULL;
- assert(!manager_created);
+ int ret = oauth2_manager_create(&manager_local);
+ assert_eq(ret, OAUTH2_ERROR_NONE);
- utc_oauth2_startup();
+ ret = oauth2_manager_destroy(manager_local);
+ assert_eq(ret, OAUTH2_ERROR_NONE);
return 0;
}
int oauth2_manager_destroy_n(void)
{
- // TODO
- /*
int ret = OAUTH2_ERROR_NONE;
ret = oauth2_manager_destroy(NULL);
assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
- */
+
return 0;
}
int ret = OAUTH2_ERROR_NONE;
ret = oauth2_manager_is_request_in_progress(NULL);
- assert_eq(ret, FALSE);
-
- return 0;
-}
-
-int oauth2_manager_clear_cookies_p(void)
-{
- // TODO
-/*
- assert(manager_created);
- int ret = OAUTH2_ERROR_NONE;
+ assert_eq(ret, false);
- ret = oauth2_manager_clear_cookies(manager);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
return 0;
}
return 0;
}
-int oauth2_manager_clear_cache_p(void)
-{
- // TODO
-/*
- assert(manager_created);
- int ret = OAUTH2_ERROR_NONE;
-
- ret = oauth2_manager_clear_cache(manager);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_manager_clear_cache_n(void)
{
int ret = OAUTH2_ERROR_NONE;
int oauth2_request_destroy_n(void)
{
- // TODO
- /*
int ret = OAUTH2_ERROR_NONE;
ret = oauth2_request_destroy(NULL);
assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
- */
+
return 0;
}
int oauth2_request_add_custom_data_p(void)
{
- // TODO
assert(request);
int ret = OAUTH2_ERROR_NONE;
int oauth2_request_add_custom_data_n(void)
{
- // TODO
assert(request);
int ret = OAUTH2_ERROR_NONE;
assert_eq(strcmp("www.example.com", url), 0);
- OAUTH2_FREE(url);
return 0;
}
assert_eq(strcmp("www.example.com", url), 0);
- OAUTH2_FREE(url);
return 0;
}
assert_eq(strcmp("www.example.com", url), 0);
- OAUTH2_FREE(url);
return 0;
}
assert_eq(strcmp("www.example.com", url), 0);
- OAUTH2_FREE(url);
return 0;
}
assert_eq(strcmp("refresh_token", token), 0);
- OAUTH2_FREE(token);
return 0;
}
assert_eq(strcmp("client_id", id), 0);
- OAUTH2_FREE(id);
return 0;
}
assert_eq(strcmp("client_secret", secret), 0);
- OAUTH2_FREE(secret);
return 0;
}
assert_eq(strcmp("email", scope), 0);
- OAUTH2_FREE(scope);
return 0;
}
assert_eq(strcmp("sample_state", state), 0);
- OAUTH2_FREE(state);
return 0;
}
assert_eq(strcmp("auth_code", code), 0);
- OAUTH2_FREE(code);
return 0;
}
assert_eq(strcmp("user_name", user_name), 0);
- OAUTH2_FREE(user_name);
return 0;
}
assert_eq(strcmp("password", password), 0);
- OAUTH2_FREE(password);
return 0;
}
* response
*/
-int oauth2_response_destroy_p(void)
-{
- // TODO
-/*
- int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
-
- ret = oauth2_response_destroy(response);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_response_destroy_n(void)
{
int ret = OAUTH2_ERROR_NONE;
return 0;
}
-int oauth2_response_get_authorization_code_p(void)
-{
- // TODO
-/*
- int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- char *code = NULL;
-
- ret = oauth2_response_get_authorization_code(response, &code);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_response_get_authorization_code_n(void)
{
int ret = OAUTH2_ERROR_NONE;
return 0;
}
-int oauth2_response_get_state_p(void)
-{
- // TODO
-/*
- int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- char *state = NULL;
-
- ret = oauth2_response_get_state(response, &state);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_response_get_state_n(void)
{
int ret = OAUTH2_ERROR_NONE;
return 0;
}
-int oauth2_response_get_access_token_p(void)
-{
- // TODO
-/*
- int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- char *token = NULL;
-
- ret = oauth2_response_get_access_token(response, &token);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_response_get_access_token_n(void)
{
int ret = OAUTH2_ERROR_NONE;
return 0;
}
-int oauth2_response_get_token_type_p(void)
-{
- // TODO
-/*
- int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- char *type = NULL;
-
- ret = oauth2_response_get_token_type(response, &type);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_response_get_token_type_n(void)
{
int ret = OAUTH2_ERROR_NONE;
return 0;
}
-int oauth2_response_get_expires_in_p(void)
-{
- // TODO
-/*
- int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- long long expires_in = 0;
-
- ret = oauth2_response_get_expires_in(response, &expires_in);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
- return 0;
-}
-
int oauth2_response_get_expires_in_n(void)
{
int ret = OAUTH2_ERROR_NONE;
return 0;
}
-int oauth2_response_get_refresh_token_p(void)
+int oauth2_response_get_refresh_token_n(void)
{
- // TODO
-/*
int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
char *token = NULL;
- ret = oauth2_response_get_refresh_token(response, &token);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
+ ret = oauth2_response_get_refresh_token(NULL, &token);
+ assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
+
return 0;
}
-int oauth2_response_get_refresh_token_n(void)
+int oauth2_response_get_scope_n(void)
{
int ret = OAUTH2_ERROR_NONE;
- char *token = NULL;
+ char *scope = NULL;
- ret = oauth2_response_get_refresh_token(NULL, &token);
+ ret = oauth2_response_get_scope(NULL, &scope);
assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
return 0;
}
-int oauth2_response_get_scope_p(void)
+int oauth2_response_get_error_n(void)
{
- // TODO
-/*
int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- char *scope = NULL;
+ oauth2_error_h err = NULL;
+
+ ret = oauth2_response_get_error(NULL, &err);
+ assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
- ret = oauth2_response_get_scope(response, &scope);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
return 0;
}
-int oauth2_response_get_scope_n(void)
+int oauth2_response_get_custom_data_n(void)
{
+ assert(request);
+
int ret = OAUTH2_ERROR_NONE;
- char *scope = NULL;
- ret = oauth2_response_get_scope(NULL, &scope);
+ char *val = NULL;
+ ret = oauth2_response_get_custom_data(NULL, "key", &val);
assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
return 0;
}
-int oauth2_response_get_error_p(void)
-{
- // TODO
+
/*
+ * error
+ */
+
+int oauth2_error_get_code_n(void)
+{
int ret = OAUTH2_ERROR_NONE;
- oauth2_response_h response = NULL;
- oauth2_error_h err = NULL;
- ret = oauth2_response_get_error(response, &err);
- assert_eq(ret, OAUTH2_ERROR_NONE);
-*/
+ int val1 = 0;
+ int val2 = 0;
+
+ ret = oauth2_error_get_code(NULL, &val1, &val2);
+ assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
+
return 0;
}
-int oauth2_response_get_error_n(void)
+int oauth2_error_get_description_n(void)
{
int ret = OAUTH2_ERROR_NONE;
- oauth2_error_h err = NULL;
+ char *description = NULL;
- ret = oauth2_response_get_error(NULL, &err);
+ ret = oauth2_error_get_description(NULL, &description);
assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
return 0;
}
-int oauth2_response_get_custom_data_p(void)
+int oauth2_error_get_uri_n(void)
{
- // TODO
-/*
- assert(request);
-
int ret = OAUTH2_ERROR_NONE;
+ char *uri = NULL;
- char *val = NULL;
- ret = oauth2_response_get_custom_data(request, "c_key", &val);
- assert_eq(ret, OAUTH2_ERROR_NONE);
+ ret = oauth2_error_get_uri(NULL, &uri);
+ assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
- assert_eq(strcmp("c_val", val), 0);
-*/
return 0;
}
-int oauth2_response_get_custom_data_n(void)
+int oauth2_error_get_custom_data_n(void)
{
- assert(request);
-
int ret = OAUTH2_ERROR_NONE;
char *val = NULL;
- ret = oauth2_response_get_custom_data(NULL, "key", &val);
+ ret = oauth2_error_get_custom_data(NULL, "key", &val);
assert_eq(ret, OAUTH2_ERROR_INVALID_PARAMETER);
return 0;
}
+
*result = calloc(size * nmemb + 1, sizeof(char));
OAUTH2_RETURN_VAL(*result, {}, OAUTH2_ERROR_OUT_OF_MEMORY,
"Out of memory");
- memcpy(*result, ptr, size * nmemb);
+ memcpy(*result, ptr, size * nmemb);
} else {
size_t len = strlen(*result);
*result = realloc(*result, len + size * nmemb + 1);
/*
* Some svc providers (example: GitHub) do not send json
- * response, which violates
+ * response, which violates
* http://tools.ietf.org/html/rfc6749#section-4.1.4 and
* http://tools.ietf.org/html/rfc6749#section-5.1
*/
sizeof(oauth2_response_s));
/* Check if its error response or success resopnse */
- /*
+ /*
* FB sample error: YOUR_REDIRECT_URI?error_reason=user_denied&
* error=access_denied&
* error_description=The+user+denied+your+request.
elm_object_text_set(mgr_handle->loading_popup, OAUTH2_LOADING_POP_UP_TEXT);
elm_popup_orient_set(mgr_handle->loading_popup, ELM_POPUP_ORIENT_BOTTOM);
-// ewk_init();
+ /* ewk_init(); */
Evas *canvas = NULL;
* is mentioned
*/
else {
- /*
+ /*
* Here authorization grant handling is out of oauth 2.0 RFC, so
- * unless a custom auth grant handler is set, we will proceed
+ * unless a custom auth grant handler is set, we will proceed
* with access token request directly
*/
if (!strcmp(grant_type,
|| !strcmp(grant_type,
OAUTH2_PARAMETER_VAL_GRANT_TYPE_CLIENT_CREDENTIALS)) {
/*
- * No additional grant request needed as per RFC
- * (http://tools.ietf.org/html/rfc6749#section-4.3.1 and
+ * No additional grant request needed as per RFC
+ * (http://tools.ietf.org/html/rfc6749#section-4.3.1 and
* http://tools.ietf.org/html/rfc6749#section-4.4.1)
*/
return OAUTH2_ERROR_INVALID_PARAMETER;
/* TODO: TBD, extension grant_type / response_type support */
return OAUTH2_ERROR_NOT_SUPPORTED;
- /*LCOV_EXCL_STOP*/
+ /*LCOV_EXCL_STOP*/
}
OAUTH2_API int
* is mentioned
*/
- /*
+ /*
* Here authorization grant handling is out of oauth 2.0 RFC, so
* unless a custom auth grant handler is set, we will proceed
* with access token request directly
}
return OAUTH2_ERROR_NOT_SUPPORTED;
- /*LCOV_EXCL_STOP*/
+ /*LCOV_EXCL_STOP*/
}
/*LCOV_EXCL_START*/
}
OAUTH2_FREE(post_body);
}
-/*LCOV_EXCL_STOP*/
+/*LCOV_EXCL_STOP*/
OAUTH2_API int
oauth2_manager_refresh_access_token(oauth2_manager_h handle,
_request_refresh_token(mgr_impl);
return OAUTH2_ERROR_NONE;
- /*LCOV_EXCL_STOP*/
+ /*LCOV_EXCL_STOP*/
}
OAUTH2_API bool
/*LCOV_EXCL_START*/
return ((oauth2_manager_s *)handle)->is_active;
- /*LCOV_EXCL_STOP*/
+ /*LCOV_EXCL_STOP*/
}
OAUTH2_API int