-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 20 | ||||
-rw-r--r-- | test/test-oauth-consumer.cc | 69 |
3 files changed, 83 insertions, 7 deletions
diff --git a/test/.gitignore b/test/.gitignore index 3d88495..7b234bd 100644 --- a/test/.gitignore +++ b/test/.gitignore | |||
@@ -7,3 +7,4 @@ | |||
7 | /RP-db.cc | 7 | /RP-db.cc |
8 | /OP.cgi | 8 | /OP.cgi |
9 | /OP-db.cc | 9 | /OP-db.cc |
10 | /test-oauth-consumer | ||
diff --git a/test/Makefile.am b/test/Makefile.am index 8fedf48..7cfe3a4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
@@ -1,4 +1,5 @@ | |||
1 | noinst_PROGRAMS = test idiscover RP.cgi OP.cgi | 1 | noinst_PROGRAMS = test idiscover test-oauth-consumer \ |
2 | ${_dependent_programs_} | ||
2 | 3 | ||
3 | AM_CPPFLAGS=${CPPFLAGS_DEBUG} | 4 | AM_CPPFLAGS=${CPPFLAGS_DEBUG} |
4 | DEFAULT_INCLUDES = -I${top_builddir} | 5 | DEFAULT_INCLUDES = -I${top_builddir} |
@@ -14,15 +15,20 @@ EXTRA_DIST= \ | |||
14 | idiscover_SOURCES = idiscover.cc | 15 | idiscover_SOURCES = idiscover.cc |
15 | idiscover_LDADD = ${top_builddir}/lib/libopkele.la | 16 | idiscover_LDADD = ${top_builddir}/lib/libopkele.la |
16 | 17 | ||
18 | test_oauth_consumer_SOURCES = test-oauth-consumer.cc | ||
19 | test_oauth_consumer_LDADD = ${top_builddir}/lib/libopkele.la | ||
20 | |||
17 | if HAVE_SQLITE3 | 21 | if HAVE_SQLITE3 |
18 | if HAVE_KINGATE | 22 | if HAVE_UUID |
19 | if HAVE_UUID | 23 | if HAVE_KINGATE |
24 | |||
25 | _dependent_programs_ = RP.cgi OP.cgi | ||
20 | 26 | ||
21 | RP_cgi_SOURCES = RP.cc | 27 | RP_cgi_SOURCES = RP.cc |
22 | nodist_RP_cgi_SOURCES = RP-db.cc | 28 | nodist_RP_cgi_SOURCES = RP-db.cc |
23 | RP_cgi_LDADD = ${top_builddir}/lib/libopkele.la \ | 29 | RP_cgi_LDADD = ${top_builddir}/lib/libopkele.la \ |
24 | ${SQLITE3_LIBS} ${KINGATE_LIBS} ${UUID_LIBS} | 30 | ${SQLITE3_LIBS} ${KINGATE_LIBS} |
25 | RP_cgi_CFLAGS = ${SQLITE3_CFLAGS} ${KINGATE_CFLAGS} ${UUID_CFLAGS} | 31 | RP_cgi_CFLAGS = ${SQLITE3_CFLAGS} ${KINGATE_CFLAGS} |
26 | 32 | ||
27 | RP-db.cc: RP-db.sql | 33 | RP-db.cc: RP-db.sql |
28 | ( \ | 34 | ( \ |
@@ -46,6 +52,6 @@ OP-db.cc: OP-db.sql | |||
46 | clean-local: | 52 | clean-local: |
47 | rm -f RP-db.cc OP-db.cc | 53 | rm -f RP-db.cc OP-db.cc |
48 | 54 | ||
49 | endif #HAVE_UUID | 55 | endif #HAVE_KINGATE |
50 | endif #HAVE_KINGATE | 56 | endif #HAVE_UUID |
51 | endif #HAVE_SQLITE3 | 57 | endif #HAVE_SQLITE3 |
diff --git a/test/test-oauth-consumer.cc b/test/test-oauth-consumer.cc new file mode 100644 index 0000000..b3ddef5 --- a/dev/null +++ b/test/test-oauth-consumer.cc | |||
@@ -0,0 +1,69 @@ | |||
1 | #include <iostream> | ||
2 | #include <cassert> | ||
3 | #include <stdexcept> | ||
4 | using namespace std; | ||
5 | #include <openssl/sha.h> | ||
6 | #include <openssl/evp.h> | ||
7 | #include <openssl/hmac.h> | ||
8 | #include <opkele/exception.h> | ||
9 | #include <opkele/debug.h> | ||
10 | #include <opkele/util.h> | ||
11 | #include <opkele/util-internal.h> | ||
12 | #include <opkele/curl.h> | ||
13 | #include <opkele/oauth/consumer.h> | ||
14 | |||
15 | ostream& operator<<(ostream& o,const opkele::oauth::token_t& t) { | ||
16 | o << "{ key: \"" << t.key << "\", secret: \"" << t.secret <<"\" }"; | ||
17 | return o; | ||
18 | } | ||
19 | |||
20 | int main(int,char**) { | ||
21 | try { | ||
22 | opkele::oauth::simple_consumer sc( | ||
23 | opkele::oauth::simple_provider_endpoints( | ||
24 | "http://term.ie/oauth/example/request_token.php", | ||
25 | "http://term.ie/oauth/example/user_authorization.php", | ||
26 | "http://term.ie/oauth/example/access_token.php", | ||
27 | "HMAC-SHA1", opkele::oauth::oauth_post_body, | ||
28 | opkele::oauth::oauth_auth_header), | ||
29 | opkele::oauth::token_t( "key","secret" ) ); | ||
30 | opkele::oauth::token_t rt = sc.get_request_token(); | ||
31 | cout << "Request token: " << rt << endl; | ||
32 | cout << "Authorize URL: " << sc.get_authorize_url(rt) << endl; | ||
33 | opkele::oauth::token_t at = sc.get_access_token(rt); | ||
34 | cout << "Access token: " << at << endl; | ||
35 | |||
36 | opkele::fields_t test; | ||
37 | test.set_field("foo","bar"); | ||
38 | opkele::util::curl_pick_t curl = opkele::util::curl_t::easy_init(); | ||
39 | opkele::oauth::http_request_t hr("POST", | ||
40 | "http://term.ie/oauth/example/echo_api.php"); | ||
41 | CURLcode r = curl.misc_sets(); | ||
42 | r || (r=curl.set_write()); | ||
43 | if(r) | ||
44 | throw opkele::exception_curl(OPKELE_CP_ "failed to set curly options",r); | ||
45 | sc.prepare_request(hr,opkele::fields_t(),test,&at).setup_curl(curl); | ||
46 | if( (r=curl.easy_perform()) ) | ||
47 | throw opkele::exception_curl(OPKELE_CP_ "failed to perform curly request",r); | ||
48 | cout << "Response: " << curl.response << endl; | ||
49 | |||
50 | #ifdef OPKELE_HAVE_KONFORKA | ||
51 | }catch(konforka::exception& e) { | ||
52 | cerr | ||
53 | << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl | ||
54 | << " what: " << e.what() << endl | ||
55 | << " where: " << e.where() << endl; | ||
56 | if(!e._seen.empty()) { | ||
57 | cerr << " seen:" << endl; | ||
58 | for(list<konforka::code_point>::const_iterator | ||
59 | i=e._seen.begin();i!=e._seen.end();++i) { | ||
60 | cerr << " " << i->c_str() << endl; | ||
61 | } | ||
62 | } | ||
63 | #endif | ||
64 | }catch(std::exception& e){ | ||
65 | cerr | ||
66 | << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl | ||
67 | << " what: " << e.what() << endl; | ||
68 | } | ||
69 | } | ||