24934893 publication api should not use sha512t_256 by default in S11.3 s11u3-sru
authorsaurabh.vyas@oracle.com
Thu, 08 Dec 2016 03:41:20 +0530
branchs11u3-sru
changeset 3498 3c1a7afe9c60
parent 3497 2b9327d94ee0
child 3509 58a9ffc8a2aa
24934893 publication api should not use sha512t_256 by default in S11.3
src/modules/actions/file.py
src/modules/digest.py
src/modules/misc.py
src/tests/api/t_api_search.py
src/tests/cli/t_pkg_install.py
src/tests/cli/t_pkg_revert.py
src/tests/cli/t_pkg_search.py
src/tests/cli/t_pkgrepo.py
src/tests/cli/t_pkgsurf.py
src/tests/pkg5unittest.py
src/util/publish/pkgdiff.py
src/util/publish/pkgsurf.py
--- a/src/modules/actions/file.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/modules/actions/file.py	Thu Dec 08 03:41:20 2016 +0530
@@ -152,7 +152,6 @@
                 finally:
                         pkgplan.image.cleanup_downloads()
 
-
         def install(self, pkgplan, orig):
                 """Client-side method that installs a file."""
 
--- a/src/modules/digest.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/modules/digest.py	Thu Dec 08 03:41:20 2016 +0530
@@ -88,7 +88,7 @@
 if DebugValues["hash"]:
         _hashes = reversed(DebugValues["hash"].split("+"))
 else:
-        _hashes = ("sha512t_256", "sha256", "sha1")
+        _hashes = ("sha1",)
 
 for alg in _hashes:
         if alg == "sha512t_256":
--- a/src/modules/misc.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/modules/misc.py	Thu Dec 08 03:41:20 2016 +0530
@@ -2831,6 +2831,7 @@
 
         # Sort the candidates by their distance, and return the words only.
         return [c[0] for c in sorted(candidates, key=itemgetter(1))]
+
 def force_bytes(s, encoding="utf-8", errors="strict"):
         """Force the string into bytes."""
 
@@ -2850,7 +2851,6 @@
                 raise
         return s
 
-
 def force_text(s, encoding="utf-8", errors="strict"):
         """Force the string into text."""
 
--- a/src/tests/api/t_api_search.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/api/t_api_search.py	Thu Dec 08 03:41:20 2016 +0530
@@ -34,14 +34,17 @@
 import time
 import unittest
 import urllib2
+from imp import reload
 
 import pkg.client.api as api
 import pkg.client.api_errors as api_errors
 import pkg.client.query_parser as query_parser
+import pkg.digest
 import pkg.fmri as fmri
 import pkg.indexer as indexer
 import pkg.portable as portable
 import pkg.search_storage as ss
+from pkg.client.debugvalues import DebugValues
 
 
 class TestApiSearchBasics(pkg5unittest.SingleDepotTestCase):
@@ -1420,7 +1423,14 @@
 
         def setUp(self):
                 TestApiSearchBasics.setUp(self)
+                # We pkgsend with SHA-2 hash in the high level so debug hash
+                # is required here to enable SHA-2 hashes for search.
+                DebugValues["hash"] = "sha1+sha512t_256"
+                reload(pkg.digest)
                 durl = self.dc.get_depot_url()
+                self.dc.stop()
+                self.dc.set_debug_feature("hash=sha1+sha512t_256")
+                self.dc.start()
                 self.pkgsend_bulk(durl, (self.example_pkg10, self.fat_pkg10,
                     self.another_pkg10))
 
--- a/src/tests/cli/t_pkg_install.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/cli/t_pkg_install.py	Thu Dec 08 03:41:20 2016 +0530
@@ -4773,7 +4773,10 @@
                 # do not complain about unknown gelf content-hash.
                 self.pkgrecv("%s -a -d %s '*'" % (repo_dir,
                     os.path.join(self.test_root, "x.p5p")))
-                self.pkgrepo("verify -s %s" % repo_dir)
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here to enable SHA-2 hashes.
+                self.pkgrepo("verify -s {0}".format(repo_dir),
+                    debug_hash="sha1+sha512t_256")
                 self.image_create(self.rurl, destroy=True)
                 self.pkg("install -v %s" % elf1)
                 # Note that we pass verification if any of the hashes match, but
@@ -4790,9 +4793,15 @@
                 # the unknown file hash.
                 self.pkgrecv("{0} -a -d {1} '*'".format(repo_dir,
                     os.path.join(self.test_root, "y.p5p")))
-                self.pkgrepo("verify -s {0}".format(repo_dir), exit=1)
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here to enable SHA-2 hashes.
+                self.pkgrepo("verify -s {0}".format(repo_dir),
+                    debug_hash="sha1+sha512t_256", exit=1)
                 self.image_create(self.rurl, destroy=True)
-                self.pkg("install -v {0}".format(elf1), exit=1)
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here to enable SHA-2 hashes.
+                self.pkg("-D hash=sha1+sha512t_256 install -v {0}".format(elf1),
+                    exit=1)
                 # We pass verification if any of the hashes match.
                 self.pkg("verify")
 
--- a/src/tests/cli/t_pkg_revert.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/cli/t_pkg_revert.py	Thu Dec 08 03:41:20 2016 +0530
@@ -167,7 +167,9 @@
                 self.pkg("-D hash=sha1+sha256 verify B", exit=1)
                 sha2 = "e3868252b2b2de64e85f5b221e46eb23c428fe5168848eb36d113c66628131ce"
                 self.assert_(sha2 in self.output)
-                self.pkg("verify B", exit=1)
+                # We pkgsend with SHA-2 hash in the high level, therefore debug hash
+                # is required here.
+                self.pkg("-D hash=sha1+sha256 verify B", exit=1)
                 self.assert_(sha2 in self.output)
 
                 if sha512_supported:
--- a/src/tests/cli/t_pkg_search.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/cli/t_pkg_search.py	Thu Dec 08 03:41:20 2016 +0530
@@ -395,7 +395,10 @@
                         token = "-f " + token
                 if not headers:
                         token = "-H " + token
-                self.pkg("search " + token + " > " + outfile, exit=exit)
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here to enable SHA-2 hashes for search.
+                self.pkg("-D hash=sha1+sha512t_256 search " + token + " > " +
+                    outfile, exit=exit)
                 res_list = (open(outfile, "rb")).readlines()
                 self._check(set(res_list), test_value)
 
@@ -626,6 +629,11 @@
                 # Need to retain to check that default search does remote, not
                 # local search, and that -r and -s work as expected
                 durl = self.dc.get_depot_url()
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here to enable SHA-2 hashes for search.
+                self.dc.stop()
+                self.dc.set_debug_feature("hash=sha1+sha512t_256")
+                self.dc.start()
                 self.pkgsend_bulk(durl, self.example_pkg10)
 
                 self.image_create(durl)
--- a/src/tests/cli/t_pkgrepo.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/cli/t_pkgrepo.py	Thu Dec 08 03:41:20 2016 +0530
@@ -1951,7 +1951,9 @@
                         bad_hash_path = self.__inject_badhash("tmp/truck1")
                         bad_basename = os.path.basename(bad_hash_path)
 
-                        self.pkgrepo("-s %s verify" % repo_path, exit=1)
+                        # debug hash is required here to enable SHA-2 hashes.
+                        self.pkgrepo("-s {0} verify".format(repo_path),
+                            debug_hash="sha1+{0}".format(hash_alg), exit=1)
                         self.assert_(
                             self.output.count("ERROR: Invalid file hash") == 1)
 
--- a/src/tests/cli/t_pkgsurf.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/cli/t_pkgsurf.py	Thu Dec 08 03:41:20 2016 +0530
@@ -30,6 +30,7 @@
 import pkg5unittest
 
 import os
+from imp import reload
 import pkg.digest as digest
 import pkg.fmri as fmri
 import pkg.manifest as manifest
@@ -38,6 +39,7 @@
 import subprocess
 import tempfile
 import unittest
+from pkg.client.debugvalues import DebugValues
 from pkg.misc import CMP_UNSIGNED
 
 class TestPkgsurf(pkg5unittest.ManyDepotTestCase):
@@ -714,6 +716,11 @@
                 # Copy target repo to tmp repo
                 self.copy_repository(self.dpath2, self.dpath_tmp,
                     {"selachii": "selachii"})
+                self.dcs[4].stop()
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here.
+                self.dcs[4].set_debug_feature("hash=sha1+sha512t_256")
+                self.dcs[4].start()
                 # The new repository won't have a catalog, so rebuild it.
                 self.dcs[4].get_repo(auto_create=True).rebuild()
 
@@ -733,8 +740,10 @@
 
                 # Check that '-u' option works and should not affect other
                 # packages.
-                self.pkgsurf("-s {0} -r {1} -u".format(self.dpath_tmp,
-                    self.dpath1))
+                # We pkgsend with SHA-2 hash in the high level, so debug hash
+                # is required here to enable SHA-2 hashes for pkgsurf.
+                self.pkgsurf("-D hash=sha1+sha512t_256 -s {0} -r {1} -u".format(
+                    self.dpath_tmp, self.dpath1))
 
                 ref_repo = self.get_repo(self.dpath1)
                 targ_repo = self.get_repo(self.dpath_tmp)
--- a/src/tests/pkg5unittest.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/tests/pkg5unittest.py	Thu Dec 08 03:41:20 2016 +0530
@@ -2563,8 +2563,15 @@
                     su_wrap=su_wrap, env_arg=env_arg)
 
         def pkgdiff(self, command, comment="", exit=0, su_wrap=False,
-            env_arg=None, stderr=False, out=False):
-                cmdline = "%s/usr/bin/pkgdiff %s" % (g_proto_area, command)
+            env_arg=None, stderr=False, out=False, debug_hash="sha1+sha512t_256"):
+                """debug_hash is default to be "sha1+sha512t_256", so SHA-2
+                hashes are enabled in comparison."""
+                if debug_hash:
+                        debug_arg = "-D hash={0} ".format(debug_hash)
+                else:
+                        debug_arg = ""
+                cmdline = sys.executable + " " + os.path.join(g_proto_area,
+                    "usr/bin/pkgdiff {0}{1}".format(debug_arg, command))
                 return self.cmdline_run(cmdline, comment=comment, exit=exit,
                     su_wrap=su_wrap, env_arg=env_arg, out=out, stderr=stderr)
 
@@ -2655,7 +2662,9 @@
 
         def pkgsend(self, depot_url="", command="", exit=0, comment="",
             allow_timestamp=False, env_arg=None, su_wrap=False,
-            debug_hash=None):
+            debug_hash="sha1+sha512t_256"):
+                """debug_hash is default to be "sha1+sha512t_256", so SHA-2
+                hashes are added to actions when publishing."""
                 args = []
                 if allow_timestamp:
                         args.append("-D allow-timestamp")
@@ -2713,7 +2722,7 @@
 
         def pkgsend_bulk(self, depot_url, commands, exit=0, comment="",
             no_catalog=False, refresh_index=False, su_wrap=False,
-            debug_hash=None):
+            debug_hash="sha1+sha512t_256"):
                 """ Send a series of packaging commands; useful  for quickly
                     doing a bulk-load of stuff into the repo.  All commands are
                     expected to work; if not, the transaction is abandoned.  If
@@ -2722,7 +2731,11 @@
 
                     A list containing the fmris of any packages that were
                     published as a result of the commands executed will be
-                    returned; it will be empty if none were. """
+                    returned; it will be empty if none were.
+
+                    debug_hash is default to be "sha1+sha512t_256", so SHA-2
+                    hashes are added to actions when publishing.
+                    """
 
                 if isinstance(commands, (list, tuple)):
                         commands = "".join(commands)
--- a/src/util/publish/pkgdiff.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/util/publish/pkgdiff.py	Thu Dec 08 03:41:20 2016 +0530
@@ -29,6 +29,7 @@
 import locale
 import sys
 import traceback
+from imp import reload
 
 import pkg.actions
 import pkg.variant as variant
@@ -37,6 +38,7 @@
 import pkg.misc as misc
 from pkg.misc import PipeError, CMP_UNSIGNED, CMP_ALL
 from collections import defaultdict
+from pkg.client.debugvalues import DebugValues
 
 def usage(errmsg="", exitcode=2):
         """Emit a usage message and optionally prefix it with a more specific
@@ -71,7 +73,8 @@
         cmp_policy = CMP_ALL
 
         try:
-                opts, pargs = getopt.getopt(sys.argv[1:], "i:o:t:uv:?", ["help"])
+                opts, pargs = getopt.getopt(sys.argv[1:], "i:o:t:uv:D:?",
+                    ["help", "debug="])
                 for opt, arg in opts:
                         if opt == "-i":
                                 ignoreattrs.append(arg)
@@ -91,10 +94,21 @@
                                 varattrs[args[0]].add(args[1])
                         elif opt in ("--help", "-?"):
                                 usage(exitcode=0)
+                        elif opt == "-D" or opt == "--debug":
+                                try:
+                                        key, value = arg.split("=", 1)
+                                except (AttributeError, ValueError):
+                                        usage(_("{opt} takes argument of form "
+                                            "name=value, not {arg}").format(
+                                            opt=opt, arg=arg))
+                                DebugValues.set_value(key, value)
 
         except getopt.GetoptError, e:
                 usage(_("illegal global option -- %s") % e.opt)
 
+        if DebugValues:
+                reload(pkg.digest)
+
         if len(pargs) != 2:
                 usage(_("two manifest arguments are required"))
 
--- a/src/util/publish/pkgsurf.py	Thu Dec 08 03:41:19 2016 +0530
+++ b/src/util/publish/pkgsurf.py	Thu Dec 08 03:41:20 2016 +0530
@@ -76,6 +76,7 @@
 import traceback
 
 from itertools import repeat
+from imp import reload
 
 import pkg.actions as actions
 import pkg.client.api_errors as api_errors
@@ -83,6 +84,7 @@
 import pkg.client.progress as progress
 import pkg.client.publisher as publisher
 import pkg.client.transport.transport as transport
+import pkg.digest
 import pkg.fmri as fmri
 import pkg.manifest as manifest
 import pkg.misc as misc
@@ -90,6 +92,7 @@
 import pkg.server.repository as sr
 
 from pkg.client import global_settings
+from pkg.client.debugvalues import DebugValues
 from pkg.misc import emsg, msg, PipeError, CMP_ALL, CMP_UNSIGNED
 
 PKG_CLIENT_NAME = "pkgsurf"
@@ -683,8 +686,8 @@
         global_settings.client_name = PKG_CLIENT_NAME
 
         try:
-                opts, pargs = getopt.getopt(sys.argv[1:], "?c:i:np:r:s:u",
-                    ["help"])
+                opts, pargs = getopt.getopt(sys.argv[1:], "?c:i:np:r:s:uD:",
+                    ["help", "debug="])
         except getopt.GetoptError, e:
                 usage(_("illegal option -- %s") % e.opt)
 
@@ -715,6 +718,17 @@
                         cmp_policy = CMP_UNSIGNED
                 elif opt == "-?" or opt == "--help":
                         usage(retcode=pkgdefs.EXIT_OK)
+                elif opt == "-D" or opt == "--debug":
+                        try:
+                                key, value = arg.split("=", 1)
+                        except (AttributeError, ValueError):
+                                usage(_("{opt} takes argument of form "
+                                        "name=value, not {arg}").format(
+                                        opt=opt, arg=arg))
+                        DebugValues.set_value(key, value)
+
+        if DebugValues:
+                reload(pkg.digest)
 
         if pargs:
                 usage(_("Unexpected argument(s): %s") % " ".join(pargs))