Esempio n. 1
0
// Trivial testcase to hit an invalid cell and check that error logging works.
TEST_F(QuiescingManagerTest, InvalidCells)
{
  CapturingTestLogger log;
  _qm->quiesce();
  _qm->quiesce();
  EXPECT_TRUE(log.contains("invalid input"));
}
Esempio n. 2
0
TEST_F(RPHServiceTest, ValidRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, clear()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_rph.json"));
  EXPECT_TRUE(log.contains("RPH configuration successfully updated"));

  // Check that the map is correctly populated. Mix up cases to check that case
  // insensitive matching works.
  EXPECT_EQ(rph.lookup_priority("wPs.4", 0), SIPEventPriorityLevel::HIGH_PRIORITY_1);
  EXPECT_EQ(rph.lookup_priority("EtS.4", 0), SIPEventPriorityLevel::HIGH_PRIORITY_1);
  EXPECT_EQ(rph.lookup_priority("WPS.3", 0), SIPEventPriorityLevel::HIGH_PRIORITY_3);
  EXPECT_EQ(rph.lookup_priority("ets.3", 0), SIPEventPriorityLevel::HIGH_PRIORITY_3);
  EXPECT_EQ(rph.lookup_priority("foo", 0), SIPEventPriorityLevel::HIGH_PRIORITY_4);
  EXPECT_EQ(rph.lookup_priority("WPs.2", 0), SIPEventPriorityLevel::HIGH_PRIORITY_5);
  EXPECT_EQ(rph.lookup_priority("eTS.2", 0), SIPEventPriorityLevel::HIGH_PRIORITY_5);
  EXPECT_EQ(rph.lookup_priority("wPs.1", 0), SIPEventPriorityLevel::HIGH_PRIORITY_7);
  EXPECT_EQ(rph.lookup_priority("ETS.1", 0), SIPEventPriorityLevel::HIGH_PRIORITY_7);
  EXPECT_EQ(rph.lookup_priority("wpS.0", 0), SIPEventPriorityLevel::HIGH_PRIORITY_9);
  EXPECT_EQ(rph.lookup_priority("ETs.0", 0), SIPEventPriorityLevel::HIGH_PRIORITY_9);
  EXPECT_EQ(rph.lookup_priority("dSn.flASH-OVerride", 0), SIPEventPriorityLevel::HIGH_PRIORITY_10);
  EXPECT_EQ(rph.lookup_priority("dRSn.flash-oVeRridE", 0), SIPEventPriorityLevel::HIGH_PRIORITY_13);
  EXPECT_EQ(rph.lookup_priority("dRsn.Flash-overrIde-OVERRIDE", 0), SIPEventPriorityLevel::HIGH_PRIORITY_15);

  // Check that if we lookup an unknown RPH value, that we get back the default
  // priority.
  EXPECT_EQ(rph.lookup_priority("unknown", 0), SIPEventPriorityLevel::NORMAL_PRIORITY);
}
Esempio n. 3
0
// Test that an invalid SIP URI doesn't get sent on third party registers.
TEST_F(DeregistrationTaskTest, InvalidIMPUTest)
{
  _hss->set_result("/impu/notavalidsipuri/reg-data", HSS_NOT_REG_STATE);
  CapturingTestLogger log;

  // Build the request
  std::string body = "{\"registrations\": [{\"primary-impu\": \"notavalidsipuri\"}]}";
  build_dereg_request(body, "false");

  // Set up the regstore expectations
  std::string aor_id = "notavalidsipuri";
  RegStore::AoR* aor = new RegStore::AoR(aor_id);
  RegStore::AoR* remote_aor = NULL;
  std::vector<std::string> aor_ids = {aor_id};
  std::vector<RegStore::AoR*> aors = {aor};

  expect_reg_store_updates(aor_ids, aors, remote_aor);

  // Run the task
  EXPECT_CALL(*_httpstack, send_reply(_, 200, _));
  _task->run();

  EXPECT_TRUE(log.contains("Unable to create third party registration"));
  _hss->flush_all();
}
Esempio n. 4
0
TEST_F(JSONEnumServiceTest, MissingFile)
{
  CapturingTestLogger log;
  JSONEnumService enum_(string(UT_DIR).append("/NONEXISTENT_FILE.json"));
  EXPECT_TRUE(log.contains("Failed to read ENUM configuration data"));
  ET("+15108580271", "").test(enum_);
}
Esempio n. 5
0
TEST_F(JSONEnumServiceTest, MissingBlock)
{
  CapturingTestLogger log;
  JSONEnumService enum_(string(UT_DIR).append("/test_enum_missing_block.json"));
  EXPECT_TRUE(log.contains("Badly formed ENUM configuration data - missing number_blocks object"));
  ET("+15108580271", "").test(enum_);
}
Esempio n. 6
0
TEST_F(JSONEnumServiceTest, ParseError)
{
  CapturingTestLogger log;
  JSONEnumService enum_(string(UT_DIR).append("/test_enum_parse_error.json"));
  EXPECT_TRUE(log.contains("Failed to read ENUM configuration data"));
  ET("+15108580271", "").test(enum_);
}
Esempio n. 7
0
TEST_F(RPHServiceTest, NonIntegerPriorityRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_non_integer_priority_rph.json"));
  EXPECT_TRUE(log.contains("Badly formed RPH priority block (hit error at"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 8
0
TEST_F(RPHServiceTest, InvalidPriorityRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_invalid_priority_rph.json"));
  EXPECT_TRUE(log.contains("RPH value block contains a priority not in the range 1-15"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 9
0
// Test that we cope with the case that the shared IFC file is valid but empty
TEST_F(SIFCServiceTest, NoEntries)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, clear()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/test_sifc_no_entries.xml"));
  EXPECT_FALSE(log.contains("Failed"));
  EXPECT_TRUE(sifc._shared_ifc_sets.empty());
}
Esempio n. 10
0
// Test that we log appropriately if the shared IFC file has the wrong syntax.
TEST_F(SIFCServiceTest, MissingSetBlock)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/test_sifc_missing_set.xml"));
  EXPECT_TRUE(log.contains("Invalid shared IFCs configuration file - missing SharedIFCsSets block"));
  EXPECT_TRUE(sifc._shared_ifc_sets.empty());
}
Esempio n. 11
0
// Test that we log appropriately if the shared IFC file is missing
TEST_F(SIFCServiceTest, MissingFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/non_existent_file.xml"));
  EXPECT_TRUE(log.contains("No shared IFCs configuration"));
  EXPECT_TRUE(sifc._shared_ifc_sets.empty());
}
Esempio n. 12
0
// Test that a dereg request where the JSON is missing the primary impu element get rejected.
TEST_F(DeregistrationTaskTest, MissingPrimaryIMPUJSONTest)
{
  CapturingTestLogger log;
  build_dereg_request("{\"registrations\": [{\"primary-imp\": \"sip:6505552001@homedomain\", \"impi\": \"6505552001\"}]}");
  EXPECT_CALL(*_httpstack, send_reply(_, 400, _));
  _task->run();
  EXPECT_TRUE(log.contains("Invalid JSON - registration doesn't contain primary-impu"));
}
Esempio n. 13
0
// Test that a dereg request where the JSON is missing the registration element get rejected.
TEST_F(DeregistrationTaskTest, MissingRegistrationsJSONTest)
{
  CapturingTestLogger log;
  build_dereg_request("{\"primary-impu\": \"sip:6505552001@homedomain\", \"impi\": \"6505552001\"}}");
  EXPECT_CALL(*_httpstack, send_reply(_, 400, _));
  _task->run();
  EXPECT_TRUE(log.contains("Registrations not available in JSON"));
}
Esempio n. 14
0
TEST_F(RPHServiceTest, DuplicatedValueRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_duplicated_value_rph.json"));
  EXPECT_TRUE(log.contains("Attempted to insert an RPH value into the map that already exists"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 15
0
TEST_F(RPHServiceTest, NoPriorityBlocksRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_no_priority_blocks_rph.json"));
  EXPECT_TRUE(log.contains("Badly formed RPH configuration data - missing priority_blocks array"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 16
0
TEST_F(RPHServiceTest, EmptyRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_empty_rph.json"));
  EXPECT_TRUE(log.contains("Failed to read RPH configuration data from ut/test_empty_rph.json"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 17
0
// Test that we log appropriately if the shared IFC file is unparseable.
TEST_F(SIFCServiceTest, ParseError)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/test_sifc_parse_error.xml"));
  EXPECT_TRUE(log.contains("Failed to parse the shared IFCs configuration data"));
  EXPECT_TRUE(sifc._shared_ifc_sets.empty());
}
Esempio n. 18
0
TEST_F(RPHServiceTest, BadlyOrderedRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_badly_ordered_rph.json"));
  EXPECT_TRUE(log.contains("RPH value \"wps.0\" has lower priority than a lower priority RPH value from the same namespace"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 19
0
TEST_F(RPHServiceTest, NoRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_non_existent_rph.json"));
  EXPECT_TRUE(log.contains("No RPH configuration (file ut/test_non_existent_rph.json does not exist)"));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 20
0
TEST_F(RPHServiceTest, InvalidRPHFile)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  RPHService rph(_mock_alarm, string(UT_DIR).append("/test_invalid_rph.json"));
  EXPECT_TRUE(log.contains("Failed to read RPH configuration data: {"));
  EXPECT_TRUE(log.contains("Error: Missing a name for object member."));
  EXPECT_TRUE(rph._rph_map.empty());
}
Esempio n. 21
0
/// XML parse errors are illegal and should give the default, with a log message.
TEST_F(SimServsTest, InvalidXml1) {
  CapturingTestLogger log;
  SCOPED_TRACE("");
  string xml = "<blah";
  simservs ss(xml);
  ss_values exp;
  expect_ss(exp, ss);
  EXPECT_TRUE(log.contains("Parse error"));
}
Esempio n. 22
0
TEST_F(JSONEnumServiceTest, MissingParts)
{
  CapturingTestLogger log;
  JSONEnumService enum_(string(UT_DIR).append("/test_enum_missing_parts.json"));
  EXPECT_TRUE(log.contains("Badly formed ENUM number block"));
  ET("+15108580271", "").test(enum_);
  ET("+15108580272", "").test(enum_);
  ET("+15108580273", "").test(enum_);
  ET("+15108580274", "sip:[email protected]").test(enum_);
}
Esempio n. 23
0
// Test that if an entry has an invalid Set ID we log and move on.
TEST_F(SIFCServiceTest, InvalidSetID)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/test_sifc_invalid_set_id.xml"));
  EXPECT_TRUE(log.contains("Invalid shared IFC block - SetID (NaN) isn't an int. Skipping this entry"));

  // The test file has an invalid entry, and an entry for ID 2. Check that this
  // was added to the map.
  std::set<int> single_ifc; single_ifc.insert(2);
  std::multimap<int32_t, Ifc> single_ifc_map;
  rapidxml::xml_document<>* root_underlying_ptr = new rapidxml::xml_document<>;
  std::shared_ptr<rapidxml::xml_document<> > root (root_underlying_ptr);
  sifc.get_ifcs_from_id(single_ifc_map, single_ifc, root, 0);
  EXPECT_EQ(single_ifc_map.size(), 1);
  EXPECT_EQ(get_server_name(single_ifc_map.find(0)->second), "register.example.com");
}
Esempio n. 24
0
// Test that if an entry has a Set ID that's already been used we log and move
// on. It doesn't override the existing value.
TEST_F(SIFCServiceTest, RepeatedSetID)
{
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/test_sifc_repeated_id.xml"));
  EXPECT_TRUE(log.contains("Invalid shared IFC block - SetID (1) is repeated. Skipping this entry"));

  // The test file has two entries for ID 1 (with different server names).
  // Check that the map entry has the correct server name.
  std::set<int> single_ifc; single_ifc.insert(1);
  std::multimap<int32_t, Ifc> single_ifc_map;
  rapidxml::xml_document<>* root_underlying_ptr = new rapidxml::xml_document<>;
  std::shared_ptr<rapidxml::xml_document<> > root (root_underlying_ptr);
  sifc.get_ifcs_from_id(single_ifc_map, single_ifc, root, 0);
  EXPECT_EQ(single_ifc_map.size(), 1);
  EXPECT_EQ(get_server_name(single_ifc_map.find(0)->second), "publish.example.com");
}
Esempio n. 25
0
TEST_F(JSONEnumServiceTest, BadRegex)
{
  CapturingTestLogger log;
  JSONEnumService enum_(string(UT_DIR).append("/test_enum_bad_regex.json"));
  // Unfortunately the logs here are hard to parse, so we just look for at least one instance of the
  // "badly formed regular expression" log, followed by a JSON expression for each of the bad number blocks.
  EXPECT_TRUE(log.contains("Badly formed regular expression in ENUM number block"));
  EXPECT_TRUE(log.contains("\"prefix\" : \"+15108580273\""));
  EXPECT_TRUE(log.contains("\"prefix\" : \"+15108580274\""));
  EXPECT_TRUE(log.contains("\"prefix\" : \"+15108580275\""));
  // First entry is valid to confirm basic regular expression is valid.
  ET("+15108580271", "sip:[email protected]").test(enum_);
  // Second entry is technically invalid but it works in the obvious way and it's easier to permit than to add code to reject.
  ET("+15108580272", "sip:[email protected]").test(enum_);
  // Remaining are not - they should fail.
  ET("+15108580273", "").test(enum_);
  ET("+15108580274", "").test(enum_);
  ET("+15108580275", "").test(enum_);
}
Esempio n. 26
0
// Test that the priorities are parsed correctly
TEST_F(SIFCServiceTest, SIFCPriorities)
{
  // The test file has 3 IFCs under ID 1. One IFC doesn't have the priority set,
  // one has it set to 200, and one has an invalid value.
  CapturingTestLogger log;
  EXPECT_CALL(*_mock_alarm, set()).Times(AtLeast(1));
  SIFCService sifc(_mock_alarm, &SNMP::FAKE_COUNTER_TABLE, string(UT_DIR).append("/test_sifc_priorities.xml"));
  EXPECT_TRUE(log.contains("Invalid shared IFC block - Priority (NaN) isn't an int. Skipping this entry"));

  // Get the IFCs for ID. There should be two (as one was invalid)
  std::set<int> id; id.insert(1);
  std::multimap<int32_t, Ifc> ifc_map;
  rapidxml::xml_document<>* root_underlying_ptr = new rapidxml::xml_document<>;
  std::shared_ptr<rapidxml::xml_document<> > root (root_underlying_ptr);
  sifc.get_ifcs_from_id(ifc_map, id, root, 0);
  EXPECT_EQ(ifc_map.size(), 2);
  EXPECT_EQ(get_server_name(ifc_map.find(0)->second), "invite.example.com");
  EXPECT_EQ(get_server_name(ifc_map.find(200)->second), "register.example.com");
}