Ejemplo n.º 1
0
TEST_F(LoggingTest, SetLogger_NewLoggerIsUsed) {
    setLogger(spdlog::stderr_logger_mt("MyTestLog2"));
    string output = captureStderr([]{
        LOG(INFO) << "My log message";
    });
    EXPECT_THAT(output, MatchesRegex(".*\\[MyTestLog2\\].*\\[info\\].*My log message.*"));
}
Ejemplo n.º 2
0
TEST(AssertTest_ReleaseBuild, AssertMessage) {
  try {
    ASSERT(2==5, "my message");
    FAIL();
  } catch (const cpputils::AssertFailed &e) {
    EXPECT_THAT(e.what(), MatchesRegex(
        "Assertion \\[2==5\\] failed in .*/assert_release_test.cpp:25: my message.*"
    ));
  }
}
TEST_F(HTTPDigestAuthenticateTest, RequestStoreDigest)
{
    std::vector<std::string> test;
    test.push_back("digest_1");
    test.push_back("realm");
    _hc->set_result("/impi/1231231231%40home.domain/av?impu=sip%3A1231231231%40home.domain", test);

    // set the _impu/_impi
    _auth_mod->set_members("sip:[email protected]", "GET", "*****@*****.**", 0);

    // Request the digest.
    std::string www_auth_header;
    long rc = _auth_mod->request_digest_and_store(www_auth_header, false, _response);

    EXPECT_THAT(www_auth_header,
                MatchesRegex("Digest realm=\"home\\.domain\",qop=\"auth\",nonce=\".*\",opaque=\".*\""));
    ASSERT_EQ(rc, 401);
}
TEST_F(SessionExpiresHelperTest, ClientSupportsTimerSEModified)
{
  Message msg1;
  msg1._uac_supports_timer = true;
  msg1._se = "Session-Expires: 800";
  do_request_flow(&msg1);

  EXPECT_EQ(get_headers(current_txdata()->msg, "Session-Expires"),
            "Session-Expires: 600");

  do_response_flow();

  EXPECT_EQ(get_headers(current_txdata()->msg, "Session-Expires"),
            "Session-Expires: 600;refresher=uac");
  EXPECT_THAT(get_headers(current_txdata()->msg, "Require"),
              MatchesRegex("Require:.*[ ,]timer($|[ ,])"));

  free_txdata();
}
// This test checks the behaviour when the authenticator tries to update the
// nonce count in the auth store, and the set fails with DATA_CONTENTION. This
// simulates the case where the nonce has already been used to authenticate a
// request, and is now stale. The authenticator therefore rechallenges the
// request with the stale flag set.
TEST_F(HTTPDigestAuthenticateMockStoreTest, CheckIfMatches_NonceUpdateFails_RaceCondition)
{
    // Set up an existing digest to pass into `check_if_matches`.
    AuthStore::Digest *digest = new AuthStore::Digest();
    digest->_impi = "*****@*****.**";
    digest->_nonce = "nonce";
    digest->_ha1 = "123123123";
    digest->_opaque = "opaque";
    digest->_realm = "home.domain";
    digest->_impu = "sip:[email protected]";

    // The authenticator will request a new digest from homestead. Prepare for
    // this.
    std::vector<std::string> test;
    test.push_back("digest_1");
    test.push_back("realm");
    _hc->set_result("/impi/1231231231%40home.domain/av?impu=sip%3A1231231231%40home.domain", test);

    // Set the _impu
    _auth_mod->set_members("sip:[email protected]", "GET", "*****@*****.**", 0);
    _response->set_members("1231231231","home.domain","nonce","org.projectclearwater.call-list/users/[email protected]/call-list.xml","qop","00001","cnonce","242c99c1e20618147c6a325c09720664","opaque");

    // The auth store is called twice:
    // - Once to update the nonce count on the existing digest (which fails with
    //   DATA_CONTENTION).
    // - Once to store the new digest from homestead (which succeeds).
    EXPECT_CALL(_mock_auth_store, set_digest(_, _, _, _))
    .WillOnce(Return(Store::DATA_CONTENTION))
    .WillOnce(Return(Store::OK));

    // Run through check if matches. This should rechallenge the request.
    std::string www_auth_header;
    long rc = _auth_mod->check_if_matches(digest, www_auth_header, _response);

    EXPECT_THAT(www_auth_header,
                MatchesRegex("Digest realm=\"home\\.domain\",qop=\"auth\",nonce=\".*\",opaque=\".*\",stale=TRUE"));
    ASSERT_EQ(rc, 401);

    delete digest;
    digest = NULL;
}
Ejemplo n.º 6
0
TEST_F(RegistrarTest, MultipleRegistrations)
{
  // First registration OK.
  Message msg;
  inject_msg(msg.get());
  ASSERT_EQ(1, txdata_count());
  pjsip_msg* out = current_txdata()->msg;
  EXPECT_EQ(200, out->line.status.code);
  free_txdata();

  // Second registration also OK.  Bindings are ordered by binding ID.
  Message msg0;
  msg = msg0;
  msg._contact = "sip:[email protected]:5061;transport=tcp;ob";
  msg._contact_instance = ";+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-a55444444440>\"";
  msg._path = "Path: sip:XxxxxxxXXXXXXAW4z38AABcUwStNKgAAa3WOL+1v72nFJg==@ec2-107-22-156-119.compute-1.amazonaws.com:5060;lr;ob";
  inject_msg(msg.get());
  ASSERT_EQ(1, txdata_count());
  out = current_txdata()->msg;
  EXPECT_EQ(200, out->line.status.code);
  EXPECT_EQ("OK", str_pj(out->line.status.reason));
  EXPECT_EQ("Supported: outbound", get_headers(out, "Supported"));
  // Expires timer for first contact may have ticked down, so give it some leeway.
  EXPECT_THAT(get_headers(out, "Contact"),
              MatchesRegex("Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-a55444444440>\"\r\n"
                           "Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-b665231f1213>\""));
  //          get_headers(out, "Contact"));
  EXPECT_EQ("Require: outbound", get_headers(out, "Require")); // because we have path
  EXPECT_EQ(msg._path, get_headers(out, "Path"));
  EXPECT_EQ("P-Associated-URI: sip:6505550231@homedomain", get_headers(out, "P-Associated-URI"));
  EXPECT_EQ("Service-Route: <sip:all.the.sprout.nodes:5058;transport=TCP;lr;orig>", get_headers(out, "Service-Route"));
  free_txdata();

  // Reregistration of first binding is OK but doesn't add a new one.
  msg = msg0;
  inject_msg(msg.get());
  ASSERT_EQ(1, txdata_count());
  out = current_txdata()->msg;
  EXPECT_EQ(200, out->line.status.code);
  EXPECT_EQ("OK", str_pj(out->line.status.reason));
  EXPECT_EQ("Supported: outbound", get_headers(out, "Supported"));
  EXPECT_THAT(get_headers(out, "Contact"),
              MatchesRegex("Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-a55444444440>\"\r\n"
                           "Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-b665231f1213>\""));
  EXPECT_EQ("Require: outbound", get_headers(out, "Require")); // because we have path
  EXPECT_EQ(msg._path, get_headers(out, "Path"));
  EXPECT_EQ("P-Associated-URI: sip:6505550231@homedomain", get_headers(out, "P-Associated-URI"));
  EXPECT_EQ("Service-Route: <sip:all.the.sprout.nodes:5058;transport=TCP;lr;orig>", get_headers(out, "Service-Route"));
  free_txdata();

  // Registering the first binding again but without the binding ID counts as a separate binding (named by the contact itself).  Bindings are ordered by binding ID.
  msg = msg0;
  msg._contact_instance = "";
  inject_msg(msg.get());
  ASSERT_EQ(1, txdata_count());
  out = current_txdata()->msg;
  EXPECT_EQ(200, out->line.status.code);
  EXPECT_EQ("OK", str_pj(out->line.status.reason));
  EXPECT_EQ("Supported: outbound", get_headers(out, "Supported"));
  EXPECT_THAT(get_headers(out, "Contact"),
              MatchesRegex("Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-a55444444440>\"\r\n"
                           "Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-b665231f1213>\"\r\n"
                           "Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1"));
  EXPECT_EQ("Require: outbound", get_headers(out, "Require")); // because we have path
  EXPECT_EQ(msg._path, get_headers(out, "Path"));
  EXPECT_EQ("P-Associated-URI: sip:6505550231@homedomain", get_headers(out, "P-Associated-URI"));
  EXPECT_EQ("Service-Route: <sip:all.the.sprout.nodes:5058;transport=TCP;lr;orig>", get_headers(out, "Service-Route"));
  free_txdata();

  // Reregistering that yields no change.
  inject_msg(msg.get());
  ASSERT_EQ(1, txdata_count());
  out = current_txdata()->msg;
  EXPECT_EQ(200, out->line.status.code);
  EXPECT_EQ("OK", str_pj(out->line.status.reason));
  EXPECT_EQ("Supported: outbound", get_headers(out, "Supported"));
  EXPECT_THAT(get_headers(out, "Contact"),
              MatchesRegex("Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-a55444444440>\"\r\n"
                           "Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1;\\+sip.instance=\"<urn:uuid:00000000-0000-0000-0000-b665231f1213>\"\r\n"
                           "Contact: sip:[email protected]:5061;transport=tcp;ob;expires=(300|[1-2][0-9][0-9]|[1-9][0-9]|[1-9]);\\+sip.ice;reg-id=1"));
  EXPECT_EQ("Require: outbound", get_headers(out, "Require")); // because we have path
  EXPECT_EQ(msg._path, get_headers(out, "Path"));
  EXPECT_EQ("P-Associated-URI: sip:6505550231@homedomain", get_headers(out, "P-Associated-URI"));
  EXPECT_EQ("Service-Route: <sip:all.the.sprout.nodes:5058;transport=TCP;lr;orig>", get_headers(out, "Service-Route"));
  free_txdata();

  // Registration of star clears all bindings.
  msg = msg0;
  msg._contact = "*";
  msg._contact_instance = "";
  msg._contact_params = "";
  inject_msg(msg.get());
  ASSERT_EQ(1, txdata_count());
  out = current_txdata()->msg;
  EXPECT_EQ(200, out->line.status.code);
  EXPECT_EQ("OK", str_pj(out->line.status.reason));
  EXPECT_EQ("Supported: outbound", get_headers(out, "Supported"));
  EXPECT_EQ("", get_headers(out, "Contact"));
  EXPECT_EQ("", get_headers(out, "Require")); // even though we have path, we have no bindings
  EXPECT_EQ(msg._path, get_headers(out, "Path"));
  EXPECT_EQ("P-Associated-URI: sip:6505550231@homedomain", get_headers(out, "P-Associated-URI"));
  EXPECT_EQ("Service-Route: <sip:all.the.sprout.nodes:5058;transport=TCP;lr;orig>", get_headers(out, "Service-Route"));
  free_txdata();
}
Ejemplo n.º 7
0
TEST_F(LoggingTest, ErrorLog) {
    setLogger(mockLogger.get());
    LOG(ERROR) << "My log message";
    EXPECT_THAT(mockLogger.capturedLog(), MatchesRegex(".*\\[MockLogger\\].*\\[error\\].*My log message.*"));
}
Ejemplo n.º 8
0
TEST_F(LoggingTest, DebugLog) {
    setLevel(DEBUG);
    setLogger(mockLogger.get());
    LOG(DEBUG) << "My log message";
    EXPECT_THAT(mockLogger.capturedLog(), MatchesRegex(".*\\[MockLogger\\].*\\[debug\\].*My log message.*"));
}
Ejemplo n.º 9
0
TEST_F(LoggingTest, WarningLog) {
    setLogger(mockLogger.get());
    LOG(WARN) << "My log message";
    EXPECT_THAT(mockLogger.capturedLog(), MatchesRegex(".*\\[MockLogger\\].*\\[warning\\].*My log message.*"));
}
Ejemplo n.º 10
0
TEST_F(LoggingTest, InfoLog) {
    setLogger(mockLogger.get());
    LOG(INFO) << "My log message";
    EXPECT_THAT(mockLogger.capturedLog(), MatchesRegex(".*\\[MockLogger\\].*\\[info\\].*My log message.*"));
}
Ejemplo n.º 11
0
TEST_F(LoggingTest, SetNonStderrLogger_LogsToNewLogger) {
    setLogger(mockLogger.get());
    logger()->info() << "My log message";
    EXPECT_THAT(mockLogger.capturedLog(), MatchesRegex(".*\\[MockLogger\\].*\\[info\\].*My log message.*"));
}
Ejemplo n.º 12
0
TEST_F(LoggingTest, DefaultLoggerIsStderr) {
    string output = captureStderr([]{
        LOG(INFO) << "My log message";
    });
    EXPECT_THAT(output, MatchesRegex(".*\\[Log\\].*\\[info\\].*My log message.*"));
}