-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | test/.gitignore | 4 | ||||
-rw-r--r-- | test/Makefile.am | 8 | ||||
-rw-r--r-- | test/html/empty.html | 0 | ||||
-rw-r--r-- | test/html/head-in-body.html | 10 | ||||
-rw-r--r-- | test/html/hkn-delegate.html | 7 | ||||
-rw-r--r-- | test/html/hkn-server.html | 7 | ||||
-rw-r--r-- | test/html/hkn.html | 8 | ||||
-rw-r--r-- | test/html/in-body.html | 8 | ||||
-rw-r--r-- | test/test.cc | 68 |
11 files changed, 124 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index c577ef8..741d585 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,23 +1,23 @@ -SUBDIRS=include lib +SUBDIRS=include lib test EXTRA_DIST= NEWS NEWS.xml NEWS.xsl DISTCHECK_CONFIGURE_FLAGS=--with-pkgconfigdir=$${dc_install_base}/lib/pkgconfig if HAVE_PKGCONFIG pkgconfigdir=@PKGCONFIG_DIR@ pkgconfig_DATA=libopkele.pc endif all-local: NEWS if HAVE_DOXYGEN clean-local: rm -rf doxydox endif NEWS: NEWS.xsl NEWS.xml ${XSLTPROC} -o $@ NEWS.xsl NEWS.xml if HAVE_DOXYGEN dox: Doxyfile ${DOXYGEN} endif diff --git a/configure.ac b/configure.ac index eb3f4d6..2094273 100644 --- a/configure.ac +++ b/configure.ac @@ -1,92 +1,95 @@ AC_INIT([libopkele], [0.3], [libopkele-bugs@klever.net]) AC_CONFIG_SRCDIR([include/opkele/opkele-config.h]) AC_CONFIG_HEADERS([config.h include/opkele/acconfig.h]) AM_INIT_AUTOMAKE([dist-bzip2]) AC_PROG_INSTALL AC_PROG_CXX AC_PROG_CC AC_PROG_LIBTOOL AC_HEADER_STDC AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) AC_WITH_PKGCONFIG PKG_CHECK_MODULES([OPENSSL],[openssl],,[ AC_MSG_ERROR([no openssl library found. get one from http://www.openssl.org/]) ]) WANT_KONFORKA="yes" AC_ARG_ENABLE([konforka], AC_HELP_STRING([--disable-konforka],[do not use konforka library (default: use if found)]), [ test "${enableval}" = "no" && WANT_KONFORKA="no" ] ) if test "${WANT_KONFORKA}" = "yes" ; then PKG_CHECK_MODULES([KONFORKA],[konforka],[ AC_SUBST([KONFORKA_CFLAGS]) AC_SUBST([KONFORKA_LIBS]) AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library]) AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library]) AC_SUBST([KONFORKA_KONFORKA],[konforka]) ],[true]) fi WANT_DOXYGEN="yes" AC_ARG_ENABLE([doxygen], AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), [ test "${enableval}" = "no" && WANT_DOXYGEN="no" ] ) if test "${WANT_DOXYGEN}" = "yes" ; then AC_WITH_DOXYGEN AC_WITH_DOT else AM_CONDITIONAL([HAVE_DOXYGEN],[false]) AM_CONDITIONAL([HAVE_DOT],[false]) fi LIBCURL_CHECK_CONFIG(,,,[ AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/]) ]) AC_WITH_PCRE([ AC_WITH_PCREPP(,[ AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) ]) ],[ AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/]) ] ) curl_ssl_verify_host="true" AC_ARG_ENABLE([ssl-verify-host], AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]), [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ] ) ${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host]) curl_ssl_verify_peer="true" AC_ARG_ENABLE([ssl-verify-peer], AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]), [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ] ) ${curl_ssl_verify_peer} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYPEER],,[defined if cURL is not to verify cert validity]) postels_law=true AC_ARG_ENABLE([postels-law], AC_HELP_STRING([--disable-postels-law],[Be strict, do not adhere to Postel's Law ("be conservative in what you do, be liberal in what you accept from others", RFC 793)]), [ test "${enableval}" = "no" && postels_law=false ] ) $postels_law && AC_DEFINE([POSTELS_LAW],,[defined if we want to adhere to Postel's Law]) +AC_DEFINE_UNQUOTED([OPKELE_SRC_DIR],["$PWD"],[source directory]) + AC_CONFIG_FILES([ Makefile libopkele.pc Doxyfile include/Makefile lib/Makefile + test/Makefile ]) AC_OUTPUT diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..918b3c9 --- a/dev/null +++ b/test/.gitignore @@ -0,0 +1,4 @@ +/.deps +/.libs +/test +*.o diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..0dbba65 --- a/dev/null +++ b/test/Makefile.am @@ -0,0 +1,8 @@ +noinst_PROGRAMS = test + +INCLUDES = -I${top_srcdir}/include/ + +test_SOURCES = test.cc +test_LDADD = ${top_builddir}/lib/libopkele.la + +EXTRA_DIST=$(addsuffix .html,$(addprefix html/, empty head-in-body hkn-delegate hkn-server hkn in-body)) diff --git a/test/html/empty.html b/test/html/empty.html new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/test/html/empty.html diff --git a/test/html/head-in-body.html b/test/html/head-in-body.html new file mode 100644 index 0000000..0f778f3 --- a/dev/null +++ b/test/html/head-in-body.html @@ -0,0 +1,10 @@ +<html> + <head> + </head> + <body> + <head> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </head> + </body> +</html> diff --git a/test/html/hkn-delegate.html b/test/html/hkn-delegate.html new file mode 100644 index 0000000..62e25a3 --- a/dev/null +++ b/test/html/hkn-delegate.html @@ -0,0 +1,7 @@ +<html> + <head> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </head> + <body> + </body> +</html> diff --git a/test/html/hkn-server.html b/test/html/hkn-server.html new file mode 100644 index 0000000..e6b64e8 --- a/dev/null +++ b/test/html/hkn-server.html @@ -0,0 +1,7 @@ +<html> + <head> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + </head> + <body> + </body> +</html> diff --git a/test/html/hkn.html b/test/html/hkn.html new file mode 100644 index 0000000..8d6e409 --- a/dev/null +++ b/test/html/hkn.html @@ -0,0 +1,8 @@ +<html> + <head> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </head> + <body> + </body> +</html> diff --git a/test/html/in-body.html b/test/html/in-body.html new file mode 100644 index 0000000..53bc06d --- a/dev/null +++ b/test/html/in-body.html @@ -0,0 +1,8 @@ +<html> + <head> + </head> + <body> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </body> +</html> diff --git a/test/test.cc b/test/test.cc new file mode 100644 index 0000000..f0526c6 --- a/dev/null +++ b/test/test.cc @@ -0,0 +1,68 @@ +#include <iostream> +#include <stdexcept> +using namespace std; +#include <opkele/exception.h> +#include <opkele/consumer.h> + +#include "config.h" + +class failed_test : public opkele::exception { + public: + failed_test(OPKELE_E_PARS) + : exception(OPKELE_E_CONS) { } +}; + +class dummy_consumer_t : public opkele::consumer_t { + public: + virtual opkele::assoc_t store_assoc(const string& server,const string& handle,const opkele::secret_t& secret,int expires_in) { + throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); + } + virtual opkele::assoc_t retrieve_assoc(const string& server,const string& handle) { + throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); + } + virtual void invalidate_assoc(const string& server,const string& handle) { + throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); + } +}; + + +void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") { + dummy_consumer_t dc; + string server, delegate; + try { + dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate); + if(!success) + throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't"); + if(server!=s) + throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'"); + if(delegate!=d) + throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'"); + }catch(opkele::bad_input& obi) { + if(success) + throw failed_test(OPKELE_CP_ "Test failed"); + }catch(opkele::failed_assertion& ofa) { + if(success) + throw failed_test(OPKELE_CP_ "Test failed"); + } +} + +void test_retrieve_links() { + test_retrieve_links("empty.html",false); + test_retrieve_links("in-body.html",false); + test_retrieve_links("head-in-body.html",false); + test_retrieve_links("hkn.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); + test_retrieve_links("hkn-server.html",true,"http://www.klever.net/openid.server"); + test_retrieve_links("hkn-delegate.html",false); +} + +main() { + try { + test_retrieve_links(); + }catch(failed_test& ft) { + cerr << "Test failed: " << ft.what() << endl; + }catch(exception& e) { + cerr << "oops: " << e.what() << endl; + _exit(1); + } + _exit(0); +} |