summaryrefslogtreecommitdiffabout
path: root/test
Unidiff
Diffstat (limited to 'test') (more/less context) (ignore whitespace changes)
-rw-r--r--test/.gitignore1
-rw-r--r--test/Makefile.am17
-rw-r--r--test/test-oauth-consumer.cc83
3 files changed, 94 insertions, 7 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 3d88495..7b234bd 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -4,6 +4,7 @@
4*.o 4*.o
5/idiscover 5/idiscover
6/RP.cgi 6/RP.cgi
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..f0c0ea8 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,7 +1,7 @@
1noinst_PROGRAMS = test idiscover RP.cgi OP.cgi 1noinst_PROGRAMS = test idiscover RP.cgi OP.cgi test-oauth-consumer
2 2
3AM_CPPFLAGS=${CPPFLAGS_DEBUG} 3AM_CPPFLAGS=${CPPFLAGS_DEBUG}
4DEFAULT_INCLUDES = -I${top_builddir} 4DEFAULT_INCLUDES = -I${top_builddir}
5INCLUDES = -I${top_srcdir}/test/ -I${top_builddir}/include/ -I${top_srcdir}/include/ ${KONFORKA_CFLAGS} ${LIBCURL_CPPFLAGS} 5INCLUDES = -I${top_srcdir}/test/ -I${top_builddir}/include/ -I${top_srcdir}/include/ ${KONFORKA_CFLAGS} ${LIBCURL_CPPFLAGS}
6 6
7test_SOURCES = test.cc 7test_SOURCES = test.cc
@@ -11,21 +11,24 @@ EXTRA_DIST= \
11 sqlite.h kingate_openid_message.h \ 11 sqlite.h kingate_openid_message.h \
12 RP-db.sql OP-db.sql 12 RP-db.sql OP-db.sql
13 13
14idiscover_SOURCES = idiscover.cc 14idiscover_SOURCES = idiscover.cc
15idiscover_LDADD = ${top_builddir}/lib/libopkele.la 15idiscover_LDADD = ${top_builddir}/lib/libopkele.la
16 16
17test_oauth_consumer_SOURCES = test-oauth-consumer.cc
18test_oauth_consumer_LDADD = ${top_builddir}/lib/libopkele.la
19
17if HAVE_SQLITE3 20if HAVE_SQLITE3
18if HAVE_KINGATE 21if HAVE_UUID
19if HAVE_UUID 22if HAVE_KINGATE
20 23
21RP_cgi_SOURCES = RP.cc 24RP_cgi_SOURCES = RP.cc
22nodist_RP_cgi_SOURCES = RP-db.cc 25nodist_RP_cgi_SOURCES = RP-db.cc
23RP_cgi_LDADD = ${top_builddir}/lib/libopkele.la \ 26RP_cgi_LDADD = ${top_builddir}/lib/libopkele.la \
24 ${SQLITE3_LIBS} ${KINGATE_LIBS} ${UUID_LIBS} 27 ${SQLITE3_LIBS} ${KINGATE_LIBS}
25RP_cgi_CFLAGS = ${SQLITE3_CFLAGS} ${KINGATE_CFLAGS} ${UUID_CFLAGS} 28RP_cgi_CFLAGS = ${SQLITE3_CFLAGS} ${KINGATE_CFLAGS}
26 29
27RP-db.cc: RP-db.sql 30RP-db.cc: RP-db.sql
28 ( \ 31 ( \
29 echo 'const char * __RP_db_bootstrap = ' && \ 32 echo 'const char * __RP_db_bootstrap = ' && \
30 sed -e 's/^/"/' -e 's/$$/"/' $< && \ 33 sed -e 's/^/"/' -e 's/$$/"/' $< && \
31 echo ';' \ 34 echo ';' \
@@ -43,9 +46,9 @@ OP-db.cc: OP-db.sql
43 echo ';' \ 46 echo ';' \
44 ) >$@ 47 ) >$@
45 48
46clean-local: 49clean-local:
47 rm -f RP-db.cc OP-db.cc 50 rm -f RP-db.cc OP-db.cc
48 51
49endif #HAVE_UUID 52endif #HAVE_KINGATE
50endif #HAVE_KINGATE 53endif #HAVE_UUID
51endif #HAVE_SQLITE3 54endif #HAVE_SQLITE3
diff --git a/test/test-oauth-consumer.cc b/test/test-oauth-consumer.cc
new file mode 100644
index 0000000..3b3ca70
--- a/dev/null
+++ b/test/test-oauth-consumer.cc
@@ -0,0 +1,83 @@
1#include <iostream>
2#include <cassert>
3#include <stdexcept>
4using 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
15ostream& operator<<(ostream& o,const opkele::oauth::token_t& t) {
16 o << "{ key: \"" << t.key << "\", secret: \"" << t.secret <<"\" }";
17 return o;
18}
19
20int 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 sc.prepare_request(hr,
42 opkele::fields_t(),test,
43 opkele::oauth::oauth_auth_header,"HMAC-SHA1",
44 &at,"realm");
45 DOUT_("url: " << hr.url << endl
46 << "body: " << hr.body << endl
47 << "header: " << hr.authorize_header);
48 opkele::util::curl_slist_t rh;
49 rh.append("Authorization: "+hr.authorize_header);
50 CURLcode r;
51 (r=curl.misc_sets())
52 || (r=curl.set_write())
53 || (r=curl.easy_setopt(CURLOPT_HTTPHEADER,rh) )
54 || (r=curl.easy_setopt(CURLOPT_URL,hr.url.c_str()))
55 || (r=curl.easy_setopt(CURLOPT_POST,1))
56 || (r=curl.easy_setopt(CURLOPT_POSTFIELDS,hr.body.c_str()))
57 || (r=curl.easy_setopt(CURLOPT_POSTFIELDSIZE,hr.body.size()));
58 if(r)
59 throw opkele::exception_curl(OPKELE_CP_ "failed to set curly options",r);
60 if( (r=curl.easy_perform()) )
61 throw opkele::exception_curl(OPKELE_CP_ "failed to perform curly request",r);
62 DOUT_("Response: " << endl << curl.response);
63
64#ifdef OPKELE_HAVE_KONFORKA
65 }catch(konforka::exception& e) {
66 cerr
67 << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl
68 << " what: " << e.what() << endl
69 << " where: " << e.where() << endl;
70 if(!e._seen.empty()) {
71 cerr << " seen:" << endl;
72 for(list<konforka::code_point>::const_iterator
73 i=e._seen.begin();i!=e._seen.end();++i) {
74 cerr << " " << i->c_str() << endl;
75 }
76 }
77#endif
78 }catch(std::exception& e){
79 cerr
80 << "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl
81 << " what: " << e.what() << endl;
82 }
83}