#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
from . import testutils
if __name__ == "__main__":
import pkg5unittest
import os
import unittest
# Cleanup after every test.
stub1 = """
dir owner=root group=root mode=0755 path=etc
stub2 = """
dir owner=root group=root mode=0755 path=etc
tree10 = """
set name=pkg.fmri value=tree@1.0,5.11-0:20110804T203458Z
set name=pkg.summary value="Leafy SPARC package" variant.arch=sparc
set name=pkg.summary value="Leafy i386 package" variant.arch=i386
set name=variant.arch value=i386 value=sparc
tree20 = """
set name=pkg.fmri value=tree@2.0,5.11-0:20120804T203458Z
set name=pkg.summary value="Leafy SPARC package" variant.arch=sparc
set name=pkg.summary value="Leafy i386 package" variant.arch=i386
set name=variant.arch value=i386 value=sparc
dir owner=root group=root mode=0755 path=etc
tree30 = """
set name=pkg.fmri value=tree@3.0,5.11-0:20130804T203458Z
set name=pkg.summary value="Leafy SPARC package" variant.arch=sparc
set name=pkg.summary value="Leafy i386 package" variant.arch=i386
set name=variant.arch value=i386 value=sparc
dir owner=root group=root mode=0755 path=etc
#
# they are considered as different
#
# they are considered as different
#
# they are considered as different
#
# this case is special, since file content-hash is preferred over
# action.hash, they are considered as the same
#
# file content-hash changes.
# they are consider as different in the case of CMP_ALL, the same in the
# case of CMP_UNSIGNED.
#
# file content-hash doesn't change
# they are consider as different
#
# content-hash change, gelf unsigned content-hash doesn't change
# they are consider as different in the case of CMP_ALL, the same in
# the case of CMP_UNSIGNED.
#
# newer version
# they are considered as different in the case of CMP_ALL, the same in
# the case of CMP_UNSIGNED because the preferred unsinged hash match.
#
hashed10 = """
set name=pkg.fmri value=hashed@1.0:20130804T203459Z
license 6aba708bd383553aa84bba4fefe8495239927767 chash=60c3aa47dce2ba0132efdace8d3b88b6589767f4 license=lic_OTN
file 4ab5de3107a63f5cf454485f720cac025f1b7002 chash=dc03afd488e3b3e4c4993d2403d7e15603b0a391 path=etc/motd
file abcd elfarch=i386 elfbits=32 elfhash=efgh path=bin/true pkg.content-hash=gelf:sha512t_256:wxyz pkg.content-hash=gelf.unsigned:sha512t_256:wxyz pkg.content-hash=file:sha512t_256:ijkl
file foo elfarch=i386 elfbits=32 elfhash=abcd path=bin/ls pkg.content-hash=gelf:sha512t_256:abcd pkg.content-hash=gelf.unsigned:sha512t_256:abcd pkg.content-hash=file:sha512t_256:wxyz
file foo elfarch=i386 elfbits=32 chash=foo elfhash=abcd path=bin/cat pkg.content-hash=gelf:sha512t_256:abcd pkg.content-hash=gelf.unsigned:sha512t_256:efgh pkg.content-hash=file:sha512t_256:ijkl
file nohash elfarch=i386 elfbits=64 elfhash=abcd path=bin/false pkg.content-hash=gelf:sha512t_256:abcd pkg.content-hash=gelf.unsigned:sha512t_256:abcd
"""
hashed20 = """
set name=pkg.fmri value=hashed@2.0:20130904T203001Z
license 7ab6de3107a63f5cf454485f720cac025f1b7001 chash=cc05afd488e3b3e4c4993d2403d7e15603b0a398 license=lic_OTN
file 3aba408bd383553aa84bba4fefe8495239927763 chash=f0c2aa47dce2ba0132efdace8d3b88b6589767f3 path=etc/motd
file abcd elfarch=i386 elfbits=32 elfhash=efgh path=bin/true pkg.content-hash=gelf:sha512t_256:wxyz pkg.content-hash=gelf.unsigned:sha512t_256:wxyz pkg.content-hash=file:sha512t_256:mnop
file bar elfarch=i386 elfbits=32 elfhash=abcd path=bin/ls pkg.content-hash=gelf:sha512t_256:efgh pkg.content-hash=gelf.unsigned:sha512t_256:efgh pkg.content-hash=file:sha512t_256:wxyz
file bar elfarch=i386 elfbits=32 chash=bar elfhash=abcd path=bin/cat pkg.content-hash=gelf:sha512t_256:mnop pkg.content-hash=gelf.unsigned:sha512t_256:efgh pkg.content-hash=file:sha512t_256:qrst
file nohash elfarch=i386 elfbits=64 elfhash=abcd path=bin/false pkg.content-hash=gelf:sha512t_256:abcd pkg.content-hash=gelf.unsigned:sha512t_256:abcd pkg.content-hash=gelf:sha3_384:wxyz pkg.content-hash=gelf.unsigned:sha3_384:wxyz
"""
["tmp/noaccess.p5m"])[0]
"""Verify pkgdiff handles basic option and subcommand parsing as
expected.
"""
# --help, -? should exit with 0.
# unknown options should exit with 2.
# no arguments should exit with 2.
# one argument should exit with 2.
"""Verify that pkgdiff can accept input from both files and
stdin and works as expected."""
#
# Verify file input.
#
# Verify that pkgdiff finds no difference for the same file.
# Verify that pkgdiff finds a difference for different files.
exit=1)
# Verify that pkgdiff gracefully handles no such file errors.
# Verify that pkgdiff gracefully handles permission errors.
#
# Verify stdin input.
#
# Verify that both arguments cannot be stdin.
# Verify that one argument can be stdin with no differences for
# identical case.
# Verify that one argument can be stdin with differences.
exit=1)
"""Verify that pkgdiff action type filtering works as expected."""
# Verify unknown types cause graceful failure.
# Verify no differences for same manifest.
self.tree10_p5m)))
# Verify differences found for file actions between 1.0 and 2.0.
# Verify differences found for dir actions between 1.0 and 2.0.
# Verify no differences found for file actions between 2.0 and
# 3.0.
self.tree30_p5m)))
# Verify no differences found for dir and file actions between
# 2.0 and 3.0 using both option forms.
self.tree30_p5m)))
# Verify differences found when only one action of a given type
# of two differs between stub1 and stub2 and other actions are
# the same.
"""Verify that hash attributes are compared as expected."""
# Verify no differences for same manifest.
self.hashed10_p5m)))
# Verify differences found for file actions between 1.0 and 2.0;
# in particular, that the 'old' hash values match 1.0 and the
# 'new' hash values match 2.0.
expected = """\
- foo
+ bar
- chash=foo
+ chash=bar
- pkg.content-hash=file:sha512t_256:ijkl pkg.content-hash=gelf:sha512t_256:abcd
+ pkg.content-hash=file:sha512t_256:qrst pkg.content-hash=gelf:sha512t_256:mnop
+ pkg.content-hash=gelf.unsigned:sha3_384:wxyz pkg.content-hash=gelf:sha3_384:wxyz
- foo
+ bar
- pkg.content-hash=gelf.unsigned:sha512t_256:abcd pkg.content-hash=gelf:sha512t_256:abcd
+ pkg.content-hash=gelf.unsigned:sha512t_256:efgh pkg.content-hash=gelf:sha512t_256:efgh
- pkg.content-hash=file:sha512t_256:ijkl
+ pkg.content-hash=file:sha512t_256:mnop
- abcd
+ efgh
- 4ab5de3107a63f5cf454485f720cac025f1b7002
+ 3aba408bd383553aa84bba4fefe8495239927763
- chash=dc03afd488e3b3e4c4993d2403d7e15603b0a391
+ chash=f0c2aa47dce2ba0132efdace8d3b88b6589767f3
- pkg.content-hash=file:sha512t_256:abcd
+ pkg.content-hash=file:sha512t_256:efgh
"""
# Verify that only the unsigned value will be compared if it
# exists in the action when '-u' option is enabled.
expected = """\
- foo
+ bar
- pkg.content-hash=gelf.unsigned:sha512t_256:abcd pkg.content-hash=gelf:sha512t_256:abcd
+ pkg.content-hash=gelf.unsigned:sha512t_256:efgh pkg.content-hash=gelf:sha512t_256:efgh
- abcd
+ efgh
- 4ab5de3107a63f5cf454485f720cac025f1b7002
+ 3aba408bd383553aa84bba4fefe8495239927763
- chash=dc03afd488e3b3e4c4993d2403d7e15603b0a391
+ chash=f0c2aa47dce2ba0132efdace8d3b88b6589767f3
- pkg.content-hash=file:sha512t_256:abcd
+ pkg.content-hash=file:sha512t_256:efgh
"""
# Again, but only comparing hash attribute.
expected = """\
- foo
+ bar
- foo
+ bar
- abcd
+ efgh
- 4ab5de3107a63f5cf454485f720cac025f1b7002
+ 3aba408bd383553aa84bba4fefe8495239927763
"""
# Again, ignoring hash attributes (should find no differences).
"-i pkg.content-hash",
# Verify differences found for license actions between 2.0 and 1.0;
# in particular, that the 'old' hash values match 2.0 and the
# 'new' hash values match 1.0.
expected = """\
license license=lic_OTN
- 7ab6de3107a63f5cf454485f720cac025f1b7001
+ 6aba708bd383553aa84bba4fefe8495239927767
- chash=cc05afd488e3b3e4c4993d2403d7e15603b0a398
+ chash=60c3aa47dce2ba0132efdace8d3b88b6589767f4
"""
# Again, but only comparing hash attribute.
expected = """\
license license=lic_OTN
- 7ab6de3107a63f5cf454485f720cac025f1b7001
+ 6aba708bd383553aa84bba4fefe8495239927767
"""
# Again, ignoring hash attributes (should find no differences).
if __name__ == "__main__":