ESAPI-C 1.0
The OWASP Enterprise Security API for C
|
00001 #include <stdio.h> 00002 #include <string.h> 00003 #include <regex.h> 00004 #include "minunit.h" 00005 #include "validate.h" 00006 00007 #define REG_FLAGS REG_EXTENDED | REG_NOSUB 00008 00009 int tests_run = 0; 00010 00011 void test_esapi_strip_chars(void) { 00012 00013 (void)fprintf(stdout,"Testing %s\n", __func__); 00014 char *original = "Valid"; 00015 char *stripped = 0; 00016 00017 TEST((stripped = strip_chars(original, "id")) != 0); 00018 TEST(strcmp(stripped, "Val") == 0); 00019 free(stripped); 00020 00021 TEST((stripped = strip_chars(original, "Val")) != 0); 00022 TEST(strcmp(stripped, "id") == 0); 00023 free(stripped); 00024 00025 TEST((stripped = strip_chars(original, "a")) != 0); 00026 TEST(strcmp(stripped, "Vlid") == 0); 00027 free(stripped); 00028 00029 TEST((stripped = strip_chars("1234567890", "24680")) != 0); 00030 TEST(strcmp(stripped, "13579") == 0); 00031 free(stripped); 00032 00033 TEST((stripped = strip_chars("223344556677889900", "2345678")) != 0); 00034 TEST(strcmp(stripped, "9900") == 0); 00035 free(stripped); 00036 } 00037 00038 void test_esapi_is_valid(void) { 00039 00040 (void)fprintf(stdout,"Testing %s\n", __func__); 00041 TEST(is_valid("Valid", "[0-9a-zA-Z]{1,6}", REG_FLAGS) == 0); 00042 TEST(is_valid("Not valid", "[0-9a-zA-Z]{1,6}", 0) != 0 ); 00043 TEST(is_valid("*&!@", "[0-9a-zA-Z]{1,6}", 0) != 0); 00044 TEST(is_valid(0, "[0-9a-zA-Z]{1,6}", 0) != 0); 00045 00046 } 00047 00048 int main(void) { 00049 test_esapi_strip_chars(); 00050 test_esapi_is_valid(); 00051 (void)fprintf(stdout, "%s: Pass <%i>, Fail<%i>\n", __FILE__, passed, failed); 00052 return (EXIT_SUCCESS); 00053 } 00054