<commit_before>/* bzflag
 * Copyright (c) 1993-2015 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "CppUTest/TestHarness.h"

#include "AccessControlList.h"

TEST_GROUP(Bans)
{

};

TEST(Bans, IPBanComparisons)
{
  in_addr ip1, ip2, ip3;

#ifdef WIN32  
  ip1.S_un.S_addr = inet_addr("127.0.0.1");
  ip2.S_un.S_addr = inet_addr("127.0.0.1");
  ip3.S_un.S_addr = inet_addr("127.0.0.2");
#else
  ip1.s_addr = inet_addr("127.0.0.1");
  ip2.s_addr = inet_addr("127.0.0.1");
  ip3.s_addr = inet_addr("127.0.0.2");
#endif
  BanInfo a1(ip1, "nobody", 0, 32);
  BanInfo a2(ip2, "nobody", 0, 32);
  BanInfo a3(ip3, "nobody", 0, 32);
  BanInfo a4(ip2, "nobody", 0, 8);

  // 127.0.0.1/32 should equal 127.0.0.1/32
  CHECK_TEXT(a1 == a2, "Equality: Two equivilent bans were not equal.");
  CHECK_TEXT(!(a1 != a2), "Inequality: Two equivilent bans were not equal.");

  // 127.0.0.1/32 should not equal 127.0.0.2/32
  CHECK_TEXT(!(a1 == a3), "Equality: Two different bans were equal.");
  CHECK_TEXT(a1 != a3, "Inequality: Two different bans were equal.");

  // 127.0.0.1/32 should not equal 127.0.0.1/8
  CHECK_TEXT(!(a1 == a4), "Equality: Two different bans with the same IP but different CIDR were equal.");
  CHECK_TEXT(a1 != a4, "Inequality: Two different bans with the same IP but different CIDR were equal.");
}

TEST(Bans, IPBanContains)
{
  in_addr ip1, ip2, ip3, ip4, ip5;
#ifdef WIN32
  ip1.S_un.S_addr = inet_addr("127.0.0.1");
  ip2.S_un.S_addr = inet_addr("127.0.0.5");
  ip3.S_un.S_addr = inet_addr("127.0.5.5");
  ip4.S_un.S_addr = inet_addr("127.5.5.5");
  ip5.S_un.S_addr = inet_addr("192.168.3.11");
#else
  ip1.s_addr = inet_addr("127.0.0.1");
  ip2.s_addr = inet_addr("127.0.0.5");
  ip3.s_addr = inet_addr("127.0.5.5");
  ip4.s_addr = inet_addr("127.5.5.5");
  ip5.s_addr = inet_addr("192.168.3.11");
#endif

  BanInfo exact1(ip1, "nobody", 0, 32);
  BanInfo exact2(ip2, "nobody", 0, 32);

  BanInfo classC1(ip1, "nobody", 0, 24);
  BanInfo classB1(ip1, "nobody", 0, 16);
  BanInfo classA1(ip1, "nobody", 0, 8);

  BanInfo CIDR30(ip1, "nobody", 0, 30);
  BanInfo CIDR29(ip1, "nobody", 0, 30);

  // Exact matches should be contained
  CHECK_TEXT(exact1.contains(ip1), "First exact IP false negative.");
  CHECK_TEXT(exact2.contains(ip2), "Second exact IP false negative.");

  // But these should not (since we're using the opposite IPs)
  CHECK_TEXT(!exact1.contains(ip2), "First exact IP false positive.");<commit_msg>Seems that Visual C++ doesn't need to initialize the in_addr variables differently after all.<commit_after>/* bzflag
 * Copyright (c) 1993-2015 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "CppUTest/TestHarness.h"

#include "AccessControlList.h"

TEST_GROUP(Bans)
{

};

TEST(Bans, IPBanComparisons)
{
  in_addr ip1, ip2, ip3;
  ip1.s_addr = inet_addr("127.0.0.1");
  ip2.s_addr = inet_addr("127.0.0.1");
  ip3.s_addr = inet_addr("127.0.0.2");

  BanInfo a1(ip1, "nobody", 0, 32);
  BanInfo a2(ip2, "nobody", 0, 32);
  BanInfo a3(ip3, "nobody", 0, 32);
  BanInfo a4(ip2, "nobody", 0, 8);

  // 1172.16.58.3/32 should equal 127.0.0.1/32
  CHECK_TEXT(a1 == a2, "Equality: Two equivilent bans were not equal.");
  CHECK_TEXT(!(a1 != a2), "Inequality: Two equivilent bans were not equal.");

  // 127.0.0.1/32 should not equal 127.0.0.2/32
  CHECK_TEXT(!(a1 == a3), "Equality: Two different bans were equal.");
  CHECK_TEXT(a1 != a3, "Inequality: Two different bans were equal.");

  // 127.0.0.1/32 should not equal 127.0.0.1/8
  CHECK_TEXT(!(a1 == a4), "Equality: Two different bans with the same IP but different CIDR were equal.");
  CHECK_TEXT(a1 != a4, "Inequality: Two different bans with the same IP but different CIDR were equal.");
}

TEST(Bans, IPBanContains)
{
  in_addr ip1, ip2, ip3, ip4, ip5;
  ip1.s_addr = inet_addr("127.0.0.1");
  ip2.s_addr = inet_addr("127.0.0.5");
  ip3.s_addr = inet_addr("127.0.5.5");
  ip4.s_addr = inet_addr("127.5.5.5");
  ip5.s_addr = inet_addr("192.168.3.11");

  BanInfo exact1(ip1, "nobody", 0, 32);
  BanInfo exact2(ip2, "nobody", 0, 32);

  BanInfo classC1(ip1, "nobody", 0, 24);
  BanInfo classB1(ip1, "nobody", 0, 16);
  BanInfo classA1(ip1, "nobody", 0, 8);

  BanInfo CIDR30(ip1, "nobody", 0, 30);
  BanInfo CIDR29(ip1, "nobody", 0, 30);

  // Exact matches should be contained
  CHECK_TEXT(exact1.contains(ip1), "First exact IP false negative.");
  CHECK_TEXT(exact2.contains(ip2), "Second exact IP false negative.");

  // But these should not (since we're using the opposite IPs)
  CHECK_TEXT(!exact1.contains(ip2), "First exact IP false positive.");
{'fraction_non_alphanumeric': 0.15831435079726652, 'fraction_numerical': 0.08656036446469248, 'mean_word_length': 3.947417840375587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 36, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4773937', 'n_tokens_mistral': 2321, 'n_tokens_neox': 2095, 'n_words': 564}