security: fix bugs in keylocator checker of validator config

refs: #4339
Change-Id: Icfd7314e5c6d244f558c6a7362c547d4fe1ce80c
diff --git a/src/security/v2/validator-config/checker.cpp b/src/security/v2/validator-config/checker.cpp
index 47415af..fdff8d2 100644
--- a/src/security/v2/validator-config/checker.cpp
+++ b/src/security/v2/validator-config/checker.cpp
@@ -80,13 +80,11 @@
 bool
 RegexChecker::checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state)
 {
-  // pktName not used in this check
-  Name identity = extractIdentityFromKeyName(klName);
-  bool result = m_regex.match(identity);
+  bool result = m_regex.match(klName);
   if (!result) {
     std::ostringstream os;
     os << "KeyLocator check failed: regex " << m_regex << " for packet " << pktName << " is invalid"
-       << " (KeyLocator=" << klName << ", identity=" << identity << ")";
+       << " (KeyLocator=" << klName << ")";
     state->fail({ValidationError::POLICY_ERROR, os.str()});
   }
 
diff --git a/tests/unit-tests/security/v2/validator-config/checker.t.cpp b/tests/unit-tests/security/v2/validator-config/checker.t.cpp
index 12af61b..4b8d5ee 100644
--- a/tests/unit-tests/security/v2/validator-config/checker.t.cpp
+++ b/tests/unit-tests/security/v2/validator-config/checker.t.cpp
@@ -123,7 +123,7 @@
 {
 public:
   RegexEqual()
-    : checker(Regex("^<foo><bar>$"))
+    : checker(Regex("^<foo><bar><KEY><>$"))
   {
   }
 
@@ -139,7 +139,7 @@
 {
 public:
   RegexIsPrefixOf()
-    : checker(Regex("^<foo><bar><>*$"))
+    : checker(Regex("^<foo><bar><>*<KEY><>$"))
   {
   }
 
@@ -155,7 +155,7 @@
 {
 public:
   RegexIsStrictPrefixOf()
-    : checker(Regex("^<foo><bar><>+$"))
+    : checker(Regex("^<foo><bar><>+<KEY><>$"))
   {
   }
 
@@ -275,7 +275,7 @@
           key-locator
           {
             type name
-            regex ^<foo><bar>$
+            regex ^<foo><bar><KEY><>$
           }
         )CONF"), "test-config"))
     , checker(*checkerPtr)