src/net/cert/internal/verify_name_match_unittest.cc
TEST(VerifyNameMatchInvalidDataTest, FailOnInvalidPrintableStringChars) {
  std::string der;
  ASSERT_TRUE(LoadTestData("ascii", "PRINTABLESTRING", "unmangled", &der));
  // Find a known location inside a PrintableString in the DER-encoded data.
  size_t replace_location = der.find("0123456789");
  ASSERT_NE(std::string::npos, replace_location);
  for (int c = 0; c < 256; ++c) {
    SCOPED_TRACE(base::NumberToString(c));
    if (base::IsAsciiAlpha(c) || base::IsAsciiDigit(c))
      continue;
    switch (c) {
      case ' ':
      case '\'':
      case '(':
      case ')':
      case '*':
      case '+':
      case ',':
      case '-':
      case '.':
      case '/':
      case ':':
      case '=':
      case '?':
        continue;
    }
    der.replace(replace_location, 1, 1, c);
    // Verification should fail due to the invalid character.
    EXPECT_FALSE(VerifyNameMatch(SequenceValueFromString(&der),
                                 SequenceValueFromString(&der)));
    std::string normalized_der;
    CertErrors errors;
    EXPECT_FALSE(
        NormalizeName(SequenceValueFromString(&der), &normalized_der, &errors));
  }
}
// Matching should fail if a PrintableString contains invalid characters.
Matching should fail if a PrintableString contains invalid characters.
Matching should fail if a PrintableString contains invalid characters .
TEST(VerifyNameMatchInvalidDataTest, FailOnInvalidPrintableStringChars) {
  std::string der;
  ASSERT_TRUE(LoadTestData("ascii", "PRINTABLESTRING", "unmangled", &der));
  size_t replace_location = der.find("0123456789");
  ASSERT_NE(std::string::npos, replace_location);
  for (int c = 0; c < 256; ++c) {
    SCOPED_TRACE(base::NumberToString(c));
    if (base::IsAsciiAlpha(c) || base::IsAsciiDigit(c))
      continue;
    switch (c) {
      case ' ':
      case '\'':
      case '(':
      case ')':
      case '*':
      case '+':
      case ',':
      case '-':
      case '.':
      case '/':
      case ':':
      case '=':
      case '?':
        continue;
    }
    der.replace(replace_location, 1, 1, c);
    EXPECT_FALSE(VerifyNameMatch(SequenceValueFromString(&der),
                                 SequenceValueFromString(&der)));
    std::string normalized_der;
    CertErrors errors;
    EXPECT_FALSE(
        NormalizeName(SequenceValueFromString(&der), &normalized_der, &errors));
  }
}
TEST ( VerifyNameMatchInvalidDataTest , FailOnInvalidPrintableStringChars ) { std :: string der ; ASSERT_TRUE ( LoadTestData ( " " , " " , " " , & der ) ) ; size_t replace_location = der . find ( " " ) ; ASSERT_NE ( std :: string :: npos , replace_location ) ; for ( int c = 0 ; c < 256 ; ++ c ) { SCOPED_TRACE ( base :: NumberToString ( c ) ) ; if ( base :: IsAsciiAlpha ( c ) || base :: IsAsciiDigit ( c ) ) continue ; switch ( c ) { case ' ' : case ' \' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : continue ; } der . replace ( replace_location , 1 , 1 , c ) ; EXPECT_FALSE ( VerifyNameMatch ( SequenceValueFromString ( & der ) , SequenceValueFromString ( & der ) ) ) ; std :: string normalized_der ; CertErrors errors ; EXPECT_FALSE ( NormalizeName ( SequenceValueFromString ( & der ) , & normalized_der , & errors ) ) ; } }
Matching should fail if a PrintableString contains invalid characters.
Matching should fail if a PrintableString contains invalid characters .
// Find a known location inside a PrintableString in the DER-encoded data. // Verification should fail due to the invalid character.