Fix tpk author handler 63/60463/5
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 25 Feb 2016 13:47:39 +0000 (14:47 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Mon, 29 Feb 2016 09:44:53 +0000 (01:44 -0800)
Requires to be submitted with:
 - https://review.tizen.org/gerrit/#/c/60464/

Change-Id: Ibe3f8384a9c64e4bcdabd12bbd3bd597c10498ad

src/manifest_parser/manifest_util.cc
src/manifest_parser/manifest_util.h
src/tpk_manifest_handlers/application_manifest_constants.cc
src/tpk_manifest_handlers/application_manifest_constants.h
src/tpk_manifest_handlers/author_handler.cc
src/tpk_manifest_handlers/author_handler.h

index d52bcb51e0e25dd53f2c3709fd3f42c686e53e50..bbe0170e40e65148a54d5769d63ec0c48790966b 100644 (file)
@@ -50,6 +50,8 @@ const char kNamespaceKey[] = "@namespace";
 const char kIdPattern[] = "^[0-9a-zA-Z]{10}[.][0-9a-zA-Z]{1,52}$";
 const char kPackagePattern[] = "^[0-9a-zA-Z]{10}$";
 
+const char kEmailPattern[] = "^[^@]+@[^.]+\\.([^.]+)(\\.[^.]+)*$";
+
 }  // namespace
 
 namespace parser {
@@ -341,5 +343,9 @@ bool ValidateTizenNativeId(const std::string& id) {
   return id.find_first_of('/') == std::string::npos;
 }
 
+bool ValidateEmailAddress(const std::string& email) {
+  std::regex regex(kEmailPattern);
+  return std::regex_match(email, regex);
+}
 
 }  // namespace parser
index 0fef26851bcef86f10c5a14775819e7df56454f9..93cee4de999ca4f90f1d838b667fdfeb07cc59fe 100644 (file)
@@ -35,6 +35,8 @@ bool ValidateTizenApplicationId(const std::string& id);
 bool ValidateTizenPackageId(const std::string& id);
 bool ValidateTizenNativeId(const std::string& id);
 
+bool ValidateEmailAddress(const std::string& email);
+
 }  // namespace parser
 
 #endif  // MANIFEST_PARSER_MANIFEST_UTIL_H_
index 16ad656898dd2c54b62d2dc6c9a25029f3522ae8..24bf2bb6fc91b5c3db6b6c714db46e8fd8e7b87e 100644 (file)
@@ -10,9 +10,6 @@ namespace application_keys {
 // manifest
 const char kManifestKey[] = "manifest";
 
-// author
-const char kAuthorKey[] = "author";
-
 // description
 const char kDescriptionKey[] = "description";
 
index 9e65669209bb9f7989a7681dcb6848a466273aa7..d22cb205b38f98a548f80b5eab9ef7b710f8ce24 100644 (file)
@@ -12,9 +12,6 @@ namespace application_keys {
 // manifest
 extern const char kManifestKey[];
 
-// author
-extern const char kAuthorKey[];
-
 // description
 extern const char kDescriptionKey[];
 
index f6bd5acd1f465295bd431e924fc285205aac1f86..3dd1644ea14c9505a3bb613b7bc2187f0a33e941 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <cassert>
 #include <map>
+#include <regex>
 #include <utility>
 
 #include "manifest_parser/manifest_util.h"
@@ -21,43 +22,24 @@ namespace keys = tpk::application_keys;
 
 namespace {
 
-const char kAuthorKey[] = "author";
+const char kAuthorKey[] = "manifest.author";
 const char kAuthorKeyText[] = "#text";
-const char kAuthorEmailKey[] = "email";
-const char kAuthorEmailChildKey[] = "@email";
-const char kAuthorHrefKey[] = "href";
-const char kAuthorHrefChildKey[] = "@href";
+const char kAuthorEmailKey[] = "@email";
+const char kAuthorHrefKey[] = "@href";
 
 void ParseAuthorAndStore(
-    const parser::DictionaryValue& control_dict,
+    const parser::DictionaryValue& author_dict,
     AuthorInfo* author) {
-
   std::string email;
-  const parser::DictionaryValue* email_dict;
-  if (control_dict.GetDictionary(kAuthorEmailKey,
-                                 &email_dict)) {
-    email_dict->GetString(
-        kAuthorEmailChildKey, &email);
-  }
+  author_dict.GetString(kAuthorEmailKey, &email);
+  author->set_email(email);
 
   std::string href;
-  const parser::DictionaryValue* href_dict;
-  if (control_dict.GetDictionary(kAuthorHrefKey,
-                                 &href_dict)) {
-    href_dict->GetString(
-        kAuthorHrefChildKey, &href);
-  }
+  author_dict.GetString(kAuthorHrefKey, &href);
+  author->set_href(href);
 
   std::string name;
-  const parser::DictionaryValue* name_dict;
-  if (control_dict.GetDictionary(kAuthorKey,
-                                 &name_dict)) {
-    name_dict->GetString(
-        kAuthorKeyText, &name);
-  }
-
-  author->set_email(email);
-  author->set_href(href);
+  author_dict.GetString(kAuthorKeyText, &name);
   author->set_name(name);
 }
 
@@ -98,6 +80,11 @@ bool AuthorHandler::Validate(
     *error = "The email child element of author element is obligatory";
     return false;
   }
+  if (!parser::ValidateEmailAddress(author.email())) {
+    *error = "The author email address is not valid";
+    return false;
+  }
+
 
   const std::string& href = author.href();
   if (href.empty()) {
@@ -121,7 +108,7 @@ bool AuthorHandler::Validate(
   return true;
 }
 
-std::string AuthorInfo::key() {
+std::string AuthorInfo::Key() {
   return kAuthorKey;
 }
 
index 0d0c88deeb58b6c493549bbf27b4ae8bfd10e899..6980cf3f16fb524289fa96bf8b348570eba01e17 100644 (file)
@@ -21,7 +21,7 @@ class AuthorInfo : public parser::ManifestData {
    * @brief key
    * @param key string
    */
-  static std::string key();
+  static std::string Key();
   /**
    * @brief set_email sets email
    * @param email