-rw-r--r-- | lib/consumer.cc | 2 | ||||
-rw-r--r-- | lib/extension.cc | 6 | ||||
-rw-r--r-- | lib/sreg.cc | 6 | ||||
-rw-r--r-- | test/test.cc | 6 |
4 files changed, 10 insertions, 10 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index d578546..7881f5f 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -332,97 +332,97 @@ namespace opkele { | |||
332 | pcre_t bre(re_bre,PCRE_CASELESS); | 332 | pcre_t bre(re_bre,PCRE_CASELESS); |
333 | if(bre.exec(html,m1)>0) | 333 | if(bre.exec(html,m1)>0) |
334 | html.erase(m1.begin(0)); | 334 | html.erase(m1.begin(0)); |
335 | pcre_t hdre(re_hdre,PCRE_CASELESS); | 335 | pcre_t hdre(re_hdre,PCRE_CASELESS); |
336 | if(hdre.exec(html,m1)<=0) | 336 | if(hdre.exec(html,m1)<=0) |
337 | throw bad_input(OPKELE_CP_ "failed to find <head>"); | 337 | throw bad_input(OPKELE_CP_ "failed to find <head>"); |
338 | html.erase(0,m1.end(0)+1); | 338 | html.erase(0,m1.end(0)+1); |
339 | pcre_t lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS); | 339 | pcre_t lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS); |
340 | bool gotit = false; | 340 | bool gotit = false; |
341 | while( (!gotit) && lre.exec(html,m1)>=2 ) { | 341 | while( (!gotit) && lre.exec(html,m1)>=2 ) { |
342 | static const char *whitespace = " \t"; | 342 | static const char *whitespace = " \t"; |
343 | string attrs(html,m1.begin(1),m1.length(1)); | 343 | string attrs(html,m1.begin(1),m1.length(1)); |
344 | html.erase(0,m1.end(0)+1); | 344 | html.erase(0,m1.end(0)+1); |
345 | if(!( rre.exec(attrs,m1)>=2 && hre.exec(attrs,m2)>=2 )) | 345 | if(!( rre.exec(attrs,m1)>=2 && hre.exec(attrs,m2)>=2 )) |
346 | continue; | 346 | continue; |
347 | string rels(attrs,m1.begin(1),m1.length(1)); | 347 | string rels(attrs,m1.begin(1),m1.length(1)); |
348 | for(string::size_type ns = rels.find_first_not_of(whitespace); | 348 | for(string::size_type ns = rels.find_first_not_of(whitespace); |
349 | ns!=string::npos; | 349 | ns!=string::npos; |
350 | ns=rels.find_first_not_of(whitespace,ns)) { | 350 | ns=rels.find_first_not_of(whitespace,ns)) { |
351 | string::size_type s = rels.find_first_of(whitespace,ns); | 351 | string::size_type s = rels.find_first_of(whitespace,ns); |
352 | string rel; | 352 | string rel; |
353 | if(s==string::npos) { | 353 | if(s==string::npos) { |
354 | rel.assign(rels,ns,string::npos); | 354 | rel.assign(rels,ns,string::npos); |
355 | ns=string::npos; | 355 | ns=string::npos; |
356 | }else{ | 356 | }else{ |
357 | rel.assign(rels,ns,s-ns); | 357 | rel.assign(rels,ns,s-ns); |
358 | ns=s; | 358 | ns=s; |
359 | } | 359 | } |
360 | if(rel=="openid.server") { | 360 | if(rel=="openid.server") { |
361 | server.assign(attrs,m2.begin(1),m2.length(1)); | 361 | server.assign(attrs,m2.begin(1),m2.length(1)); |
362 | if(!delegate.empty()) { | 362 | if(!delegate.empty()) { |
363 | gotit = true; | 363 | gotit = true; |
364 | break; | 364 | break; |
365 | } | 365 | } |
366 | }else if(rel=="openid.delegate") { | 366 | }else if(rel=="openid.delegate") { |
367 | delegate.assign(attrs,m2.begin(1),m2.length(1)); | 367 | delegate.assign(attrs,m2.begin(1),m2.length(1)); |
368 | if(!server.empty()) { | 368 | if(!server.empty()) { |
369 | gotit = true; | 369 | gotit = true; |
370 | break; | 370 | break; |
371 | } | 371 | } |
372 | } | 372 | } |
373 | if(ns==string::npos) break; | 373 | if(ns==string::npos) break; |
374 | } | 374 | } |
375 | } | 375 | } |
376 | if(server.empty()) | 376 | if(server.empty()) |
377 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); | 377 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); |
378 | } | 378 | } |
379 | 379 | ||
380 | assoc_t consumer_t::find_assoc(const string& server) { | 380 | assoc_t consumer_t::find_assoc(const string& /* server */) { |
381 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); | 381 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); |
382 | } | 382 | } |
383 | 383 | ||
384 | string consumer_t::normalize(const string& url) { | 384 | string consumer_t::normalize(const string& url) { |
385 | string rv = url; | 385 | string rv = url; |
386 | // strip leading and trailing spaces | 386 | // strip leading and trailing spaces |
387 | string::size_type i = rv.find_first_not_of(" \t\r\n"); | 387 | string::size_type i = rv.find_first_not_of(" \t\r\n"); |
388 | if(i==string::npos) | 388 | if(i==string::npos) |
389 | throw bad_input(OPKELE_CP_ "empty URL"); | 389 | throw bad_input(OPKELE_CP_ "empty URL"); |
390 | if(i) | 390 | if(i) |
391 | rv.erase(0,i); | 391 | rv.erase(0,i); |
392 | i = rv.find_last_not_of(" \t\r\n"); | 392 | i = rv.find_last_not_of(" \t\r\n"); |
393 | assert(i!=string::npos); | 393 | assert(i!=string::npos); |
394 | if(i<(rv.length()-1)) | 394 | if(i<(rv.length()-1)) |
395 | rv.erase(i+1); | 395 | rv.erase(i+1); |
396 | // add missing http:// | 396 | // add missing http:// |
397 | i = rv.find("://"); | 397 | i = rv.find("://"); |
398 | if(i==string::npos) { // primitive. but do we need more? | 398 | if(i==string::npos) { // primitive. but do we need more? |
399 | rv.insert(0,"http://"); | 399 | rv.insert(0,"http://"); |
400 | i = sizeof("http://")-1; | 400 | i = sizeof("http://")-1; |
401 | }else{ | 401 | }else{ |
402 | i += sizeof("://")-1; | 402 | i += sizeof("://")-1; |
403 | } | 403 | } |
404 | string::size_type qm = rv.find('?',i); | 404 | string::size_type qm = rv.find('?',i); |
405 | string::size_type sl = rv.find('/',i); | 405 | string::size_type sl = rv.find('/',i); |
406 | if(qm!=string::npos) { | 406 | if(qm!=string::npos) { |
407 | if(sl==string::npos || sl>qm) | 407 | if(sl==string::npos || sl>qm) |
408 | rv.insert(qm,1,'/'); | 408 | rv.insert(qm,1,'/'); |
409 | }else{ | 409 | }else{ |
410 | if(sl==string::npos) | 410 | if(sl==string::npos) |
411 | rv += '/'; | 411 | rv += '/'; |
412 | } | 412 | } |
413 | return rv; | 413 | return rv; |
414 | } | 414 | } |
415 | 415 | ||
416 | string consumer_t::canonicalize(const string& url) { | 416 | string consumer_t::canonicalize(const string& url) { |
417 | string rv = normalize(url); | 417 | string rv = normalize(url); |
418 | curl_t curl = curl_easy_init(); | 418 | curl_t curl = curl_easy_init(); |
419 | if(!curl) | 419 | if(!curl) |
420 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); | 420 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_init()"); |
421 | string html; | 421 | string html; |
422 | CURLcode r; | 422 | CURLcode r; |
423 | (r=curl_misc_sets(curl)) | 423 | (r=curl_misc_sets(curl)) |
424 | || (r=curl_easy_setopt(curl,CURLOPT_URL,rv.c_str())) | 424 | || (r=curl_easy_setopt(curl,CURLOPT_URL,rv.c_str())) |
425 | || (r=curl_easy_setopt(curl,CURLOPT_NOBODY,1)) | 425 | || (r=curl_easy_setopt(curl,CURLOPT_NOBODY,1)) |
426 | ; | 426 | ; |
427 | if(r) | 427 | if(r) |
428 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); | 428 | throw exception_curl(OPKELE_CP_ "failed to curl_easy_setopt()",r); |
diff --git a/lib/extension.cc b/lib/extension.cc index 44cf0cb..8f22562 100644 --- a/lib/extension.cc +++ b/lib/extension.cc | |||
@@ -1,15 +1,15 @@ | |||
1 | #include <opkele/exception.h> | 1 | #include <opkele/exception.h> |
2 | #include <opkele/extension.h> | 2 | #include <opkele/extension.h> |
3 | 3 | ||
4 | namespace opkele { | 4 | namespace opkele { |
5 | 5 | ||
6 | void extension_t::checkid_hook(params_t& p,const string& identity) { | 6 | void extension_t::checkid_hook(params_t& /* p */,const string& /* identity */ ) { |
7 | throw not_implemented(OPKELE_CP_ "Consumer checkid_hook not implemented"); | 7 | throw not_implemented(OPKELE_CP_ "Consumer checkid_hook not implemented"); |
8 | } | 8 | } |
9 | void extension_t::id_res_hook(const params_t& p,const params_t& sp,const string& identity) { | 9 | void extension_t::id_res_hook(const params_t& /* p */,const params_t& /* sp */,const string& /* identity */) { |
10 | throw not_implemented(OPKELE_CP_ "Consumer id_res_hook not implemented"); | 10 | throw not_implemented(OPKELE_CP_ "Consumer id_res_hook not implemented"); |
11 | } | 11 | } |
12 | void extension_t::checkid_hook(const params_t& pin,params_t& pout) { | 12 | void extension_t::checkid_hook(const params_t& /* pin */,params_t& /* pout */) { |
13 | throw not_implemented(OPKELE_CP_ "Server checkid_hook not implemented"); | 13 | throw not_implemented(OPKELE_CP_ "Server checkid_hook not implemented"); |
14 | } | 14 | } |
15 | } | 15 | } |
diff --git a/lib/sreg.cc b/lib/sreg.cc index 08e66b7..60dc691 100644 --- a/lib/sreg.cc +++ b/lib/sreg.cc | |||
@@ -1,124 +1,124 @@ | |||
1 | #include <opkele/exception.h> | 1 | #include <opkele/exception.h> |
2 | #include <opkele/sreg.h> | 2 | #include <opkele/sreg.h> |
3 | #include <algorithm> | 3 | #include <algorithm> |
4 | 4 | ||
5 | namespace opkele { | 5 | namespace opkele { |
6 | using std::find; | 6 | using std::find; |
7 | 7 | ||
8 | static const struct _sreg_field { | 8 | static const struct _sreg_field { |
9 | const char *fieldname; | 9 | const char *fieldname; |
10 | sreg_t::fieldbit_t fieldbit; | 10 | sreg_t::fieldbit_t fieldbit; |
11 | }fields[] = { | 11 | }fields[] = { |
12 | { "nickname", sreg_t::field_nickname }, | 12 | { "nickname", sreg_t::field_nickname }, |
13 | { "email", sreg_t::field_email }, | 13 | { "email", sreg_t::field_email }, |
14 | { "fullname", sreg_t::field_fullname }, | 14 | { "fullname", sreg_t::field_fullname }, |
15 | { "dob", sreg_t::field_dob }, | 15 | { "dob", sreg_t::field_dob }, |
16 | { "gender", sreg_t::field_gender }, | 16 | { "gender", sreg_t::field_gender }, |
17 | { "postcode", sreg_t::field_postcode }, | 17 | { "postcode", sreg_t::field_postcode }, |
18 | { "country", sreg_t::field_country }, | 18 | { "country", sreg_t::field_country }, |
19 | { "language", sreg_t::field_language }, | 19 | { "language", sreg_t::field_language }, |
20 | { "timezone", sreg_t::field_timezone } | 20 | { "timezone", sreg_t::field_timezone } |
21 | }; | 21 | }; |
22 | # define fields_BEGINfields | 22 | # define fields_BEGINfields |
23 | # define fields_END &fields[sizeof(fields)/sizeof(*fields)] | 23 | # define fields_END &fields[sizeof(fields)/sizeof(*fields)] |
24 | typedef const struct _sreg_field *fields_iterator; | 24 | typedef const struct _sreg_field *fields_iterator; |
25 | 25 | ||
26 | bool operator==(const struct _sreg_field& fd,const string& fn) { | 26 | bool operator==(const struct _sreg_field& fd,const string& fn) { |
27 | return fd.fieldname==fn; | 27 | return fd.fieldname==fn; |
28 | } | 28 | } |
29 | 29 | ||
30 | void sreg_t::checkid_hook(params_t& p,const string& identity) { | 30 | void sreg_t::checkid_hook(params_t& p,const string& /* identity */) { |
31 | string fr, fo; | 31 | string fr, fo; |
32 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { | 32 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { |
33 | if(f->fieldbit&fields_required) { | 33 | if(f->fieldbit&fields_required) { |
34 | if(!fr.empty()) fr+=","; | 34 | if(!fr.empty()) fr+=","; |
35 | fr += f->fieldname; | 35 | fr += f->fieldname; |
36 | } | 36 | } |
37 | if(f->fieldbit&fields_optional) { | 37 | if(f->fieldbit&fields_optional) { |
38 | if(!fo.empty()) fo+=","; | 38 | if(!fo.empty()) fo+=","; |
39 | fo += f->fieldname; | 39 | fo += f->fieldname; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | if(!fr.empty()) p["sreg.required"]=fr; | 42 | if(!fr.empty()) p["sreg.required"]=fr; |
43 | if(!fo.empty()) p["sreg.optional"]=fo; | 43 | if(!fo.empty()) p["sreg.optional"]=fo; |
44 | if(!policy_url.empty()) p["sreg.policy_url"]=policy_url; | 44 | if(!policy_url.empty()) p["sreg.policy_url"]=policy_url; |
45 | } | 45 | } |
46 | 46 | ||
47 | void sreg_t::id_res_hook(const params_t& p,const params_t& sp,const string& identity) { | 47 | void sreg_t::id_res_hook(const params_t& /* p */,const params_t& sp,const string& /* identity */) { |
48 | clear(); | 48 | clear(); |
49 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { | 49 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { |
50 | string fn = "sreg."; fn+=f->fieldname; | 50 | string fn = "sreg."; fn+=f->fieldname; |
51 | if(!sp.has_param(fn)) continue; | 51 | if(!sp.has_param(fn)) continue; |
52 | has_fields |= f->fieldbit; | 52 | has_fields |= f->fieldbit; |
53 | response[f->fieldbit]=sp.get_param(fn); | 53 | response[f->fieldbit]=sp.get_param(fn); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | const string& sreg_t::get_field(fieldbit_t fb) const { | 57 | const string& sreg_t::get_field(fieldbit_t fb) const { |
58 | response_t::const_iterator i = response.find(fb); | 58 | response_t::const_iterator i = response.find(fb); |
59 | if(i==response.end()) | 59 | if(i==response.end()) |
60 | throw failed_lookup(OPKELE_CP_ "no field data available"); | 60 | throw failed_lookup(OPKELE_CP_ "no field data available"); |
61 | return i->second; | 61 | return i->second; |
62 | } | 62 | } |
63 | 63 | ||
64 | void sreg_t::set_field(fieldbit_t fb,const string& fv) { | 64 | void sreg_t::set_field(fieldbit_t fb,const string& fv) { |
65 | response[fb] = fv; | 65 | response[fb] = fv; |
66 | has_fields |= fb; | 66 | has_fields |= fb; |
67 | } | 67 | } |
68 | 68 | ||
69 | void sreg_t::reset_field(fieldbit_t fb) { | 69 | void sreg_t::reset_field(fieldbit_t fb) { |
70 | has_fields &= ~fb; | 70 | has_fields &= ~fb; |
71 | response.erase(fb); | 71 | response.erase(fb); |
72 | } | 72 | } |
73 | 73 | ||
74 | void sreg_t::clear() { | 74 | void sreg_t::clear() { |
75 | has_fields = 0; response.clear(); | 75 | has_fields = 0; response.clear(); |
76 | } | 76 | } |
77 | 77 | ||
78 | static long fields_list_to_bitmask(string& fl) { | 78 | static long fields_list_to_bitmask(string& fl) { |
79 | long rv = 0; | 79 | long rv = 0; |
80 | while(!fl.empty()) { | 80 | while(!fl.empty()) { |
81 | string::size_type co = fl.find(','); | 81 | string::size_type co = fl.find(','); |
82 | string fn; | 82 | string fn; |
83 | if(co==string::npos) { | 83 | if(co==string::npos) { |
84 | fn = fl; fl.erase(); | 84 | fn = fl; fl.erase(); |
85 | }else{ | 85 | }else{ |
86 | fn = fl.substr(0,co); fl.erase(0,co+1); | 86 | fn = fl.substr(0,co); fl.erase(0,co+1); |
87 | } | 87 | } |
88 | fields_iterator f = find(fields_BEGIN,fields_END,fn); | 88 | fields_iterator f = find(fields_BEGIN,fields_END,fn); |
89 | if(f!=fields_END) | 89 | if(f!=fields_END) |
90 | rv |= f->fieldbit; | 90 | rv |= f->fieldbit; |
91 | } | 91 | } |
92 | return rv; | 92 | return rv; |
93 | } | 93 | } |
94 | 94 | ||
95 | void sreg_t::checkid_hook(const params_t& pin,params_t& pout) { | 95 | void sreg_t::checkid_hook(const params_t& pin,params_t& pout) { |
96 | fields_optional = 0; fields_required = 0; policy_url.erase(); | 96 | fields_optional = 0; fields_required = 0; policy_url.erase(); |
97 | fields_response = 0; | 97 | fields_response = 0; |
98 | try { | 98 | try { |
99 | string fl = pin.get_param("openid.sreg.required"); | 99 | string fl = pin.get_param("openid.sreg.required"); |
100 | fields_required = fields_list_to_bitmask(fl); | 100 | fields_required = fields_list_to_bitmask(fl); |
101 | }catch(failed_lookup&) { } | 101 | }catch(failed_lookup&) { } |
102 | try { | 102 | try { |
103 | string fl = pin.get_param("openid.sreg.optional"); | 103 | string fl = pin.get_param("openid.sreg.optional"); |
104 | fields_optional = fields_list_to_bitmask(fl); | 104 | fields_optional = fields_list_to_bitmask(fl); |
105 | }catch(failed_lookup&) { } | 105 | }catch(failed_lookup&) { } |
106 | try { | 106 | try { |
107 | policy_url = pin.get_param("openid.sreg.policy_url"); | 107 | policy_url = pin.get_param("openid.sreg.policy_url"); |
108 | }catch(failed_lookup&) { } | 108 | }catch(failed_lookup&) { } |
109 | setup_response(pin,pout); | 109 | setup_response(pin,pout); |
110 | fields_response &= has_fields; | 110 | fields_response &= has_fields; |
111 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { | 111 | for(fields_iterator f=fields_BEGIN;f<fields_END;++f) { |
112 | if(!(f->fieldbit&fields_response)) continue; | 112 | if(!(f->fieldbit&fields_response)) continue; |
113 | if(!pout["signed"].empty()) | 113 | if(!pout["signed"].empty()) |
114 | pout["signed"] +=','; | 114 | pout["signed"] +=','; |
115 | string pn = "sreg."; pn += f->fieldname; | 115 | string pn = "sreg."; pn += f->fieldname; |
116 | pout["signed"] += pn; | 116 | pout["signed"] += pn; |
117 | pout[pn] = get_field(f->fieldbit); | 117 | pout[pn] = get_field(f->fieldbit); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | void sreg_t::setup_response(const params_t& pin,params_t& pout) { | 121 | void sreg_t::setup_response(const params_t& /* pin */,params_t& /* pout */) { |
122 | fields_response = (fields_required|fields_optional)&has_fields; | 122 | fields_response = (fields_required|fields_optional)&has_fields; |
123 | } | 123 | } |
124 | } | 124 | } |
diff --git a/test/test.cc b/test/test.cc index 0010f2b..f92284c 100644 --- a/test/test.cc +++ b/test/test.cc | |||
@@ -1,71 +1,71 @@ | |||
1 | #include <iostream> | 1 | #include <iostream> |
2 | #include <stdexcept> | 2 | #include <stdexcept> |
3 | using namespace std; | 3 | using namespace std; |
4 | #include <opkele/exception.h> | 4 | #include <opkele/exception.h> |
5 | #include <opkele/consumer.h> | 5 | #include <opkele/consumer.h> |
6 | 6 | ||
7 | #include "config.h" | 7 | #include "config.h" |
8 | 8 | ||
9 | class failed_test : public opkele::exception { | 9 | class failed_test : public opkele::exception { |
10 | public: | 10 | public: |
11 | failed_test(OPKELE_E_PARS) | 11 | failed_test(OPKELE_E_PARS) |
12 | : exception(OPKELE_E_CONS) { } | 12 | : exception(OPKELE_E_CONS) { } |
13 | }; | 13 | }; |
14 | 14 | ||
15 | class dummy_consumer_t : public opkele::consumer_t { | 15 | class dummy_consumer_t : public opkele::consumer_t { |
16 | public: | 16 | public: |
17 | virtual opkele::assoc_t store_assoc(const string& server,const string& handle,const opkele::secret_t& secret,int expires_in) { | 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"); | 18 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); |
19 | } | 19 | } |
20 | virtual opkele::assoc_t retrieve_assoc(const string& server,const string& handle) { | 20 | virtual opkele::assoc_t retrieve_assoc(const string& /* server */ ,const string& /* handle */) { |
21 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); | 21 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); |
22 | } | 22 | } |
23 | virtual void invalidate_assoc(const string& server,const string& handle) { | 23 | virtual void invalidate_assoc(const string& /* server */,const string& /* handle */) { |
24 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); | 24 | throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); |
25 | } | 25 | } |
26 | }; | 26 | }; |
27 | 27 | ||
28 | 28 | ||
29 | void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") { | 29 | void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") { |
30 | dummy_consumer_t dc; | 30 | dummy_consumer_t dc; |
31 | string server, delegate; | 31 | string server, delegate; |
32 | try { | 32 | try { |
33 | dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate); | 33 | dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate); |
34 | if(!success) | 34 | if(!success) |
35 | throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't"); | 35 | throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't"); |
36 | if(server!=s) | 36 | if(server!=s) |
37 | throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'"); | 37 | throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'"); |
38 | if(delegate!=d) | 38 | if(delegate!=d) |
39 | throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'"); | 39 | throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'"); |
40 | }catch(opkele::bad_input& obi) { | 40 | }catch(opkele::bad_input& obi) { |
41 | if(success) | 41 | if(success) |
42 | throw failed_test(OPKELE_CP_ "Test '"+f+"' failed due to 'bad_input'["+obi.what()+"]"); | 42 | throw failed_test(OPKELE_CP_ "Test '"+f+"' failed due to 'bad_input'["+obi.what()+"]"); |
43 | }catch(opkele::failed_assertion& ofa) { | 43 | }catch(opkele::failed_assertion& ofa) { |
44 | if(success) | 44 | if(success) |
45 | throw failed_test(OPKELE_CP_ "Test '"+f+"' failed due to 'failed_assertion'["+ofa.what()+"]"); | 45 | throw failed_test(OPKELE_CP_ "Test '"+f+"' failed due to 'failed_assertion'["+ofa.what()+"]"); |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | void test_retrieve_links() { | 49 | void test_retrieve_links() { |
50 | test_retrieve_links("empty.html",false); | 50 | test_retrieve_links("empty.html",false); |
51 | test_retrieve_links("in-body.html",false); | 51 | test_retrieve_links("in-body.html",false); |
52 | test_retrieve_links("head-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/"); | 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"); | 54 | test_retrieve_links("hkn-server.html",true,"http://www.klever.net/openid.server"); |
55 | test_retrieve_links("hkn-delegate.html",false); | 55 | test_retrieve_links("hkn-delegate.html",false); |
56 | test_retrieve_links("unclosed-head.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); | 56 | test_retrieve_links("unclosed-head.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); |
57 | test_retrieve_links("spaced-links.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); | 57 | test_retrieve_links("spaced-links.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); |
58 | test_retrieve_links("spaced-link-attrs.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); | 58 | test_retrieve_links("spaced-link-attrs.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); |
59 | test_retrieve_links("2rels.html",true,"http://www.klever.net/openid.server","http://www.klever.net/openid.server"); | 59 | test_retrieve_links("2rels.html",true,"http://www.klever.net/openid.server","http://www.klever.net/openid.server"); |
60 | } | 60 | } |
61 | 61 | ||
62 | int main() { | 62 | int main() { |
63 | try { | 63 | try { |
64 | test_retrieve_links(); | 64 | test_retrieve_links(); |
65 | }catch(failed_test& ft) { | 65 | }catch(failed_test& ft) { |
66 | cerr << "Test failed: " << ft.what() << endl; | 66 | cerr << "Test failed: " << ft.what() << endl; |
67 | }catch(exception& e) { | 67 | }catch(exception& e) { |
68 | cerr << "oops: " << e.what() << endl; | 68 | cerr << "oops: " << e.what() << endl; |
69 | _exit(1); | 69 | _exit(1); |
70 | } | 70 | } |
71 | _exit(0); | 71 | _exit(0); |