author | Michael Krelin <hacker@klever.net> | 2007-09-11 22:01:00 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-09-11 22:01:00 (UTC) |
commit | 2c6565f363527142928062afe3d3101fdbb3c550 (patch) (unidiff) | |
tree | 7f5b26dad9a2870897ab4e63285fee4516881224 | |
parent | 5c41d9c975fc80495eebb0ac2cf062bf20c62d86 (diff) | |
download | libopkele-2c6565f363527142928062afe3d3101fdbb3c550.zip libopkele-2c6565f363527142928062afe3d3101fdbb3c550.tar.gz libopkele-2c6565f363527142928062afe3d3101fdbb3c550.tar.bz2 |
a quick set of tests for retrieve_links machinery
Signed-off-by: Michael Krelin <hacker@klever.net>
-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 @@ | |||
1 | 1 | ||
2 | SUBDIRS=include lib | 2 | SUBDIRS=include lib test |
3 | EXTRA_DIST= NEWS NEWS.xml NEWS.xsl | 3 | EXTRA_DIST= NEWS NEWS.xml NEWS.xsl |
4 | 4 | ||
5 | DISTCHECK_CONFIGURE_FLAGS=--with-pkgconfigdir=$${dc_install_base}/lib/pkgconfig | 5 | DISTCHECK_CONFIGURE_FLAGS=--with-pkgconfigdir=$${dc_install_base}/lib/pkgconfig |
6 | if HAVE_PKGCONFIG | 6 | if HAVE_PKGCONFIG |
7 | pkgconfigdir=@PKGCONFIG_DIR@ | 7 | pkgconfigdir=@PKGCONFIG_DIR@ |
8 | pkgconfig_DATA=libopkele.pc | 8 | pkgconfig_DATA=libopkele.pc |
9 | endif | 9 | endif |
10 | 10 | ||
11 | all-local: NEWS | 11 | all-local: NEWS |
12 | if HAVE_DOXYGEN | 12 | if HAVE_DOXYGEN |
13 | clean-local: | 13 | clean-local: |
14 | rm -rf doxydox | 14 | rm -rf doxydox |
15 | endif | 15 | endif |
16 | 16 | ||
17 | NEWS: NEWS.xsl NEWS.xml | 17 | NEWS: NEWS.xsl NEWS.xml |
18 | ${XSLTPROC} -o $@ NEWS.xsl NEWS.xml | 18 | ${XSLTPROC} -o $@ NEWS.xsl NEWS.xml |
19 | 19 | ||
20 | if HAVE_DOXYGEN | 20 | if HAVE_DOXYGEN |
21 | dox: Doxyfile | 21 | dox: Doxyfile |
22 | ${DOXYGEN} | 22 | ${DOXYGEN} |
23 | endif | 23 | endif |
diff --git a/configure.ac b/configure.ac index eb3f4d6..2094273 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -21,72 +21,75 @@ WANT_KONFORKA="yes" | |||
21 | AC_ARG_ENABLE([konforka], | 21 | AC_ARG_ENABLE([konforka], |
22 | AC_HELP_STRING([--disable-konforka],[do not use konforka library (default: use if found)]), | 22 | AC_HELP_STRING([--disable-konforka],[do not use konforka library (default: use if found)]), |
23 | [ | 23 | [ |
24 | test "${enableval}" = "no" && WANT_KONFORKA="no" | 24 | test "${enableval}" = "no" && WANT_KONFORKA="no" |
25 | ] | 25 | ] |
26 | ) | 26 | ) |
27 | if test "${WANT_KONFORKA}" = "yes" ; then | 27 | if test "${WANT_KONFORKA}" = "yes" ; then |
28 | PKG_CHECK_MODULES([KONFORKA],[konforka],[ | 28 | PKG_CHECK_MODULES([KONFORKA],[konforka],[ |
29 | AC_SUBST([KONFORKA_CFLAGS]) | 29 | AC_SUBST([KONFORKA_CFLAGS]) |
30 | AC_SUBST([KONFORKA_LIBS]) | 30 | AC_SUBST([KONFORKA_LIBS]) |
31 | AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library]) | 31 | AC_DEFINE([HAVE_KONFORKA],,[defined in presence of konforka library]) |
32 | AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library]) | 32 | AC_DEFINE([OPKELE_HAVE_KONFORKA],,[defined in presence of konforka library]) |
33 | AC_SUBST([KONFORKA_KONFORKA],[konforka]) | 33 | AC_SUBST([KONFORKA_KONFORKA],[konforka]) |
34 | ],[true]) | 34 | ],[true]) |
35 | fi | 35 | fi |
36 | 36 | ||
37 | WANT_DOXYGEN="yes" | 37 | WANT_DOXYGEN="yes" |
38 | AC_ARG_ENABLE([doxygen], | 38 | AC_ARG_ENABLE([doxygen], |
39 | AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), | 39 | AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), |
40 | [ | 40 | [ |
41 | test "${enableval}" = "no" && WANT_DOXYGEN="no" | 41 | test "${enableval}" = "no" && WANT_DOXYGEN="no" |
42 | ] | 42 | ] |
43 | ) | 43 | ) |
44 | if test "${WANT_DOXYGEN}" = "yes" ; then | 44 | if test "${WANT_DOXYGEN}" = "yes" ; then |
45 | AC_WITH_DOXYGEN | 45 | AC_WITH_DOXYGEN |
46 | AC_WITH_DOT | 46 | AC_WITH_DOT |
47 | else | 47 | else |
48 | AM_CONDITIONAL([HAVE_DOXYGEN],[false]) | 48 | AM_CONDITIONAL([HAVE_DOXYGEN],[false]) |
49 | AM_CONDITIONAL([HAVE_DOT],[false]) | 49 | AM_CONDITIONAL([HAVE_DOT],[false]) |
50 | fi | 50 | fi |
51 | 51 | ||
52 | LIBCURL_CHECK_CONFIG(,,,[ | 52 | LIBCURL_CHECK_CONFIG(,,,[ |
53 | AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/]) | 53 | AC_MSG_ERROR([no required libcurl library. get one from http://curl.haxx.se/]) |
54 | ]) | 54 | ]) |
55 | AC_WITH_PCRE([ | 55 | AC_WITH_PCRE([ |
56 | AC_WITH_PCREPP(,[ | 56 | AC_WITH_PCREPP(,[ |
57 | AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) | 57 | AC_MSG_ERROR([no pcre++ library found. get one at http://www.daemon.de/PCRE]) |
58 | ]) | 58 | ]) |
59 | ],[ | 59 | ],[ |
60 | AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/]) | 60 | AC_MSG_ERROR([no pcre library found. get one at http://www.pcre.org/]) |
61 | ] | 61 | ] |
62 | ) | 62 | ) |
63 | 63 | ||
64 | curl_ssl_verify_host="true" | 64 | curl_ssl_verify_host="true" |
65 | AC_ARG_ENABLE([ssl-verify-host], | 65 | AC_ARG_ENABLE([ssl-verify-host], |
66 | AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]), | 66 | AC_HELP_STRING([--disable-ssl-verify-host],[disable cURL cert/host relationships verification]), |
67 | [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ] | 67 | [ test "${enableval}" = "no" && curl_ssl_verify_host="false" ] |
68 | ) | 68 | ) |
69 | ${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host]) | 69 | ${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host]) |
70 | 70 | ||
71 | curl_ssl_verify_peer="true" | 71 | curl_ssl_verify_peer="true" |
72 | AC_ARG_ENABLE([ssl-verify-peer], | 72 | AC_ARG_ENABLE([ssl-verify-peer], |
73 | AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]), | 73 | AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]), |
74 | [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ] | 74 | [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ] |
75 | ) | 75 | ) |
76 | ${curl_ssl_verify_peer} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYPEER],,[defined if cURL is not to verify cert validity]) | 76 | ${curl_ssl_verify_peer} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYPEER],,[defined if cURL is not to verify cert validity]) |
77 | 77 | ||
78 | postels_law=true | 78 | postels_law=true |
79 | AC_ARG_ENABLE([postels-law], | 79 | AC_ARG_ENABLE([postels-law], |
80 | 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)]), | 80 | 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)]), |
81 | [ test "${enableval}" = "no" && postels_law=false ] | 81 | [ test "${enableval}" = "no" && postels_law=false ] |
82 | ) | 82 | ) |
83 | $postels_law && AC_DEFINE([POSTELS_LAW],,[defined if we want to adhere to Postel's Law]) | 83 | $postels_law && AC_DEFINE([POSTELS_LAW],,[defined if we want to adhere to Postel's Law]) |
84 | 84 | ||
85 | AC_DEFINE_UNQUOTED([OPKELE_SRC_DIR],["$PWD"],[source directory]) | ||
86 | |||
85 | AC_CONFIG_FILES([ | 87 | AC_CONFIG_FILES([ |
86 | Makefile | 88 | Makefile |
87 | libopkele.pc | 89 | libopkele.pc |
88 | Doxyfile | 90 | Doxyfile |
89 | include/Makefile | 91 | include/Makefile |
90 | lib/Makefile | 92 | lib/Makefile |
93 | test/Makefile | ||
91 | ]) | 94 | ]) |
92 | AC_OUTPUT | 95 | 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 @@ | |||
1 | /.deps | ||
2 | /.libs | ||
3 | /test | ||
4 | *.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 @@ | |||
1 | noinst_PROGRAMS = test | ||
2 | |||
3 | INCLUDES = -I${top_srcdir}/include/ | ||
4 | |||
5 | test_SOURCES = test.cc | ||
6 | test_LDADD = ${top_builddir}/lib/libopkele.la | ||
7 | |||
8 | 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 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | </head> | ||
4 | <body> | ||
5 | <head> | ||
6 | <link rel="openid.server" href="http://www.klever.net/openid.server" /> | ||
7 | <link rel="openid.delegate" href="http://hacker.klever.net/" /> | ||
8 | </head> | ||
9 | </body> | ||
10 | </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 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <link rel="openid.delegate" href="http://hacker.klever.net/" /> | ||
4 | </head> | ||
5 | <body> | ||
6 | </body> | ||
7 | </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 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <link rel="openid.server" href="http://www.klever.net/openid.server" /> | ||
4 | </head> | ||
5 | <body> | ||
6 | </body> | ||
7 | </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 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | <link rel="openid.server" href="http://www.klever.net/openid.server" /> | ||
4 | <link rel="openid.delegate" href="http://hacker.klever.net/" /> | ||
5 | </head> | ||
6 | <body> | ||
7 | </body> | ||
8 | </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 @@ | |||
1 | <html> | ||
2 | <head> | ||
3 | </head> | ||
4 | <body> | ||
5 | <link rel="openid.server" href="http://www.klever.net/openid.server" /> | ||
6 | <link rel="openid.delegate" href="http://hacker.klever.net/" /> | ||
7 | </body> | ||
8 | </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 @@ | |||
1 | #include <iostream> | ||
2 | #include <stdexcept> | ||
3 | using namespace std; | ||
4 | #include <opkele/exception.h> | ||
5 | #include <opkele/consumer.h> | ||
6 | |||
7 | #include "config.h" | ||
8 | |||
9 | class failed_test : public opkele::exception { | ||
10 | public: | ||
11 | failed_test(OPKELE_E_PARS) | ||
12 | : exception(OPKELE_E_CONS) { } | ||
13 | }; | ||
14 | |||
15 | class dummy_consumer_t : public opkele::consumer_t { | ||
16 | public: | ||
17 | virtual opkele::assoc_t store_assoc(const string& server,const string& handle,const opkele::secret_t& secret,int expires_in) { | ||
18 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); | ||
19 | } | ||
20 | virtual opkele::assoc_t retrieve_assoc(const string& server,const string& handle) { | ||
21 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); | ||
22 | } | ||
23 | virtual void invalidate_assoc(const string& server,const string& handle) { | ||
24 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); | ||
25 | } | ||
26 | }; | ||
27 | |||
28 | |||
29 | void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") { | ||
30 | dummy_consumer_t dc; | ||
31 | string server, delegate; | ||
32 | try { | ||
33 | dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate); | ||
34 | if(!success) | ||
35 | throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't"); | ||
36 | if(server!=s) | ||
37 | throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'"); | ||
38 | if(delegate!=d) | ||
39 | throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'"); | ||
40 | }catch(opkele::bad_input& obi) { | ||
41 | if(success) | ||
42 | throw failed_test(OPKELE_CP_ "Test failed"); | ||
43 | }catch(opkele::failed_assertion& ofa) { | ||
44 | if(success) | ||
45 | throw failed_test(OPKELE_CP_ "Test failed"); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | void test_retrieve_links() { | ||
50 | test_retrieve_links("empty.html",false); | ||
51 | test_retrieve_links("in-body.html",false); | ||
52 | test_retrieve_links("head-in-body.html",false); | ||
53 | test_retrieve_links("hkn.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); | ||
54 | test_retrieve_links("hkn-server.html",true,"http://www.klever.net/openid.server"); | ||
55 | test_retrieve_links("hkn-delegate.html",false); | ||
56 | } | ||
57 | |||
58 | main() { | ||
59 | try { | ||
60 | test_retrieve_links(); | ||
61 | }catch(failed_test& ft) { | ||
62 | cerr << "Test failed: " << ft.what() << endl; | ||
63 | }catch(exception& e) { | ||
64 | cerr << "oops: " << e.what() << endl; | ||
65 | _exit(1); | ||
66 | } | ||
67 | _exit(0); | ||
68 | } | ||