diff options
Diffstat (limited to 'tinyHTTP/test/test_auth.h')
-rwxr-xr-x | tinyHTTP/test/test_auth.h | 225 |
1 files changed, 108 insertions, 117 deletions
diff --git a/tinyHTTP/test/test_auth.h b/tinyHTTP/test/test_auth.h index 4a707f1..c5b9efb 100755 --- a/tinyHTTP/test/test_auth.h +++ b/tinyHTTP/test/test_auth.h @@ -2,19 +2,19 @@ * Copyright (C) 2009 Mamadou Diop. * * Contact: Mamadou Diop <diopmamadou(at)doubango.org> -* +* * This file is part of Open Source Doubango Framework. * * DOUBANGO is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * DOUBANGO is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with DOUBANGO. * @@ -22,68 +22,62 @@ #ifndef _TEST_AUTH_H_ #define _TEST_AUTH_H_ -struct auth_basic_msg -{ - const char* userid; - const char* password; +struct auth_basic_msg { + const char* userid; + const char* password; - const char* xres; + const char* xres; }; -struct auth_basic_msg auth_basic_msgs[] = -{ - { "Aladdin"/*Ali baba*/, "open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }, +struct auth_basic_msg auth_basic_msgs[] = { + { "Aladdin"/*Ali baba*/, "open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }, }; void test_basic_auth() { - char *response = tsk_null; - size_t i, size; - - for(i=0; i<sizeof(auth_basic_msgs)/sizeof(struct auth_basic_msg); i++) - { - size = thttp_auth_basic_response(auth_basic_msgs[i].userid, auth_basic_msgs[i].password, &response); - if(tsk_striequals(auth_basic_msgs[i].xres, response)){ - TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> OK", i); - } - else{ - TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> NOK", i); - } - - TSK_FREE(response); - } + char *response = tsk_null; + size_t i, size; + + for(i=0; i<sizeof(auth_basic_msgs)/sizeof(struct auth_basic_msg); i++) { + size = thttp_auth_basic_response(auth_basic_msgs[i].userid, auth_basic_msgs[i].password, &response); + if(tsk_striequals(auth_basic_msgs[i].xres, response)) { + TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> NOK", i); + } + + TSK_FREE(response); + } } //======================================================================== -struct auth_ws -{ - const char* key; - const char* xres; +struct auth_ws { + const char* key; + const char* xres; }; -struct auth_ws auth_ws_msgs[] = -{ - { "dGhlIHNhbXBsZSBub25jZQ==", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=" }, - { "x3JJHMbDL1EzLkh9GBhXDw==", "HSmrc0sMlYUkAGmm5OPpG2HaGWk=" }, +struct auth_ws auth_ws_msgs[] = { + { "dGhlIHNhbXBsZSBub25jZQ==", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=" }, + { "x3JJHMbDL1EzLkh9GBhXDw==", "HSmrc0sMlYUkAGmm5OPpG2HaGWk=" }, }; void test_ws_auth() { - thttp_auth_ws_keystring_t response = {0}; - size_t i, size; - - for(i=0; i<sizeof(auth_ws_msgs)/sizeof(struct auth_ws); i++) - { - size = thttp_auth_ws_response(auth_ws_msgs[i].key, &response); - if(tsk_striequals(auth_ws_msgs[i].xres, response)){ - TSK_DEBUG_INFO("[WS_AUTH-%d] ==> OK", i); - } - else{ - TSK_DEBUG_INFO("[WS_AUTH-%d] ==> NOK", i); - } - } + thttp_auth_ws_keystring_t response = {0}; + size_t i, size; + + for(i=0; i<sizeof(auth_ws_msgs)/sizeof(struct auth_ws); i++) { + size = thttp_auth_ws_response(auth_ws_msgs[i].key, &response); + if(tsk_striequals(auth_ws_msgs[i].xres, response)) { + TSK_DEBUG_INFO("[WS_AUTH-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[WS_AUTH-%d] ==> NOK", i); + } + } } @@ -91,84 +85,81 @@ void test_ws_auth() //======================================================================== -struct auth_digest_msg -{ - const char* username; - const char* password; - const char* realm; - const char* nonce; - const char* method; - const char* uri; - const char* qop; - const char* nc; - const char* cnonce; - const char* opaque; - const char* entitybody; - - const char* response; +struct auth_digest_msg { + const char* username; + const char* password; + const char* realm; + const char* nonce; + const char* method; + const char* uri; + const char* qop; + const char* nc; + const char* cnonce; + const char* opaque; + const char* entitybody; + + const char* response; }; -struct auth_digest_msg auth_digest_msgs[] = -{ - { - "Mufasa", - "Circle Of Life", - "testrealm@host.com", - "dcd98b7102dd2f0e8b11d0f600bfb0c093", - "GET", - "/dir/index.html", - "auth", - "00000001", - "0a4f113b", - "5ccc069c403ebaf9f0171e9517f40e41", - 0, - - "6629fae49393a05397450978507c4ef1" - } - , +struct auth_digest_msg auth_digest_msgs[] = { + { + "Mufasa", + "Circle Of Life", + "testrealm@host.com", + "dcd98b7102dd2f0e8b11d0f600bfb0c093", + "GET", + "/dir/index.html", + "auth", + "00000001", + "0a4f113b", + "5ccc069c403ebaf9f0171e9517f40e41", + 0, + + "6629fae49393a05397450978507c4ef1" + } + , }; void test_digest_auth() { - tsk_md5string_t response, ha1, ha2; - size_t i; - - for(i=0; i<sizeof(auth_digest_msgs)/sizeof(struct auth_digest_msg); i++) - { - tsk_buffer_t* entitybody; - /* HA1 */ - thttp_auth_digest_HA1(auth_digest_msgs[i].username, - auth_digest_msgs[i].realm, - auth_digest_msgs[i].password, - &ha1); - - /* HA2 */ - entitybody = tsk_buffer_create(auth_digest_msgs[i].entitybody, strlen(auth_digest_msgs[i].entitybody)); - thttp_auth_digest_HA2(auth_digest_msgs[i].method, - auth_digest_msgs[i].uri, - entitybody, - auth_digest_msgs[i].qop, - &ha2); - TSK_OBJECT_SAFE_FREE(entitybody); - - /* RESPONSE */ - thttp_auth_digest_response(&ha1, - auth_digest_msgs[i].nonce, - auth_digest_msgs[i].nc, - auth_digest_msgs[i].cnonce, - auth_digest_msgs[i].qop, - &ha2, - &response); - - if(tsk_striequals(auth_digest_msgs[i].response, response)){ - TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> OK", i); - } - else{ - TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> NOK", i); - } - } + tsk_md5string_t response, ha1, ha2; + size_t i; + + for(i=0; i<sizeof(auth_digest_msgs)/sizeof(struct auth_digest_msg); i++) { + tsk_buffer_t* entitybody; + /* HA1 */ + thttp_auth_digest_HA1(auth_digest_msgs[i].username, + auth_digest_msgs[i].realm, + auth_digest_msgs[i].password, + &ha1); + + /* HA2 */ + entitybody = tsk_buffer_create(auth_digest_msgs[i].entitybody, strlen(auth_digest_msgs[i].entitybody)); + thttp_auth_digest_HA2(auth_digest_msgs[i].method, + auth_digest_msgs[i].uri, + entitybody, + auth_digest_msgs[i].qop, + &ha2); + TSK_OBJECT_SAFE_FREE(entitybody); + + /* RESPONSE */ + thttp_auth_digest_response(&ha1, + auth_digest_msgs[i].nonce, + auth_digest_msgs[i].nc, + auth_digest_msgs[i].cnonce, + auth_digest_msgs[i].qop, + &ha2, + &response); + + if(tsk_striequals(auth_digest_msgs[i].response, response)) { + TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> OK", i); + } + else { + TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> NOK", i); + } + } } |