The Poor Man's (or Woman's) Intrusion Detection System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
2.3 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // Test "data" module
  3. // Written by Jonathan A. Foster <ChipMaster@YeOlPiShack.net>
  4. // Started June 28th, 2021
  5. //
  6. // NOTE: This is really incomplete. More tests to come.
  7. //////////////////////////////////////////////////////////////////////
  8. #include <string>
  9. #include <iostream>
  10. #include <stdio.h>
  11. #include "testit.h"
  12. #include "../data.h"
  13. //////////////////////////////////////////////////////////////////////
  14. // TestIt Jig
  15. //////////////////////////////////////////////////////////////////////
  16. TestIt test;
  17. //////////////////////////////////////////////////////////////////////
  18. // Test 1 - Wild Card Address Comparisons
  19. //////////////////////////////////////////////////////////////////////
  20. /// Table ///
  21. struct WildAddrTest {
  22. std::string addr1, addr2;
  23. int result;
  24. };
  25. const int wild_addr_tests_ct = 13;
  26. WildAddrTest wild_addr_tests[wild_addr_tests_ct] = {
  27. // IPv4
  28. {"192.168.255." , "192.168.255.7", 0},
  29. {"192.168.255.7", "192.168.255." , 0},
  30. {"192.168.255.7", "192.168.255.7", 0},
  31. {"192.168.255.7", "192.168.255.8", -1},
  32. {"192.168.254.7", "192.168.255." , -1},
  33. {"192.168.256.7", "192.168.255." , 1},
  34. {"*" , "192.168.255." , 0},
  35. {"192.168.256.7", "*" , 0},
  36. //IPv6
  37. {"2001:0470:000a:0169:" , "2001:0470:000a:0169:0000:0000:0000:0001", 0},
  38. {"2001:0470:000a:0169:0000:0000:0000:0002", "2001:0470:000a:0169:" , 0},
  39. {"2001:0470:000a:0170:" , "2001:0470:000a:0169:0000:0000:0000:0003", 1},
  40. {"2001:0470:000a:0168:0000:0000:0000:0004", "2001:0470:000a:0169:" , -1},
  41. {"2001:0470:000a:0169:0000:0000:0000:0001", "2001:0470:000a:0169:0000:0000:0000:0001", 0},
  42. };
  43. bool wild_addr_test() {
  44. int i;
  45. bool ok = true;
  46. char s[256]; s[255]=0;
  47. test.module("Wild Card Address Match");
  48. for(i=0; i<wild_addr_tests_ct; i++) {
  49. snprintf(s, 255, "Test match %3d", i);
  50. if(!test.test(s,
  51. addr_wild_comp(wild_addr_tests[i].addr1, wild_addr_tests[i].addr2),
  52. wild_addr_tests[i].result
  53. ))
  54. ok = false;
  55. }
  56. return ok;
  57. }
  58. //////////////////////////////////////////////////////////////////////
  59. // Lets do it
  60. //////////////////////////////////////////////////////////////////////
  61. int main() {
  62. wild_addr_test();
  63. return !test.report();
  64. }