#
# 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 shutil
import tempfile
import time
import unittest
# Don't need to restart depot for every test.
# Tests in this suite use the read only data directory.
amber10 = """
open amber@1.0,5.11-0
add dir mode=0755 owner=root group=bin path=etc
add hardlink path=etc/amber.hardlink target=/etc/amber1
close """
licensed13 = """
open licensed@1.3,5.11-0
add license copyright.licensed license=copyright.licensed must-display=True
add license license.licensed license=license.licensed must-accept=True
close """
dir10 = """
open dir@1.0,5.11-0
add dir path=etc mode=0755 owner=root group=bin
close """
pkg_dupfile = """
open dupfile@0,5.11-0
add file tmp/file1 path=dir/pathname mode=0755 owner=root group=bin preserve=renameold overlay=allow
close
"""
pkg_duplink = """
open duplink@0,5.11-0
close
"""
# All of these purposefully omit dir dependency.
file10 = """
open file@1.0,5.11-0
add file amber1 path=amber1 mode=0600 owner=root group=bin
close """
preserve10 = """
open preserve@1.0,5.11-0
add file amber1 path=amber1 mode=755 owner=root group=bin preserve=true timestamp="20080731T001051Z"
add file amber2 path=amber2 mode=755 owner=root group=bin preserve=true timestamp="20080731T001051Z"
close """
preserve11 = """
open preserve@1.1,5.11-0
add file amber1 path=amber1 mode=755 owner=root group=bin preserve=renamenew timestamp="20090731T004051Z"
close """
preserve12 = """
open preserve@1.2,5.11-0
add file amber1 path=amber1 mode=755 owner=root group=bin preserve=renameold timestamp="20100731T014051Z"
close """
driver10 = """
open drv@1.0,5.11-0
add driver name=whee alias=pci8186,4321
close """
driver_prep10 = """
open drv-prep@1.0,5.11-0
add dir path=/tmp mode=755 owner=root group=root
add dir mode=0755 owner=root group=root path=/var
add dir mode=0755 owner=root group=root path=/system
add file tmp/empty path=/etc/driver_aliases mode=644 owner=root group=sys preserve=true
add file tmp/empty path=/etc/name_to_major mode=644 owner=root group=sys preserve=true
add file tmp/empty path=/etc/driver_classes mode=644 owner=root group=sys
add file tmp/empty path=/etc/minor_perm mode=644 owner=root group=sys
add file tmp/empty path=/etc/security/device_policy mode=644 owner=root group=sys
add file tmp/empty path=/etc/security/extra_privs mode=644 owner=root group=sys
close """
sysattr = """
open sysattr@1.0-0
add file amber1 mode=0555 owner=root group=bin sysattr=sensitive preserve=true path=amber1 timestamp=20100731T014051Z overlay=allow
add file amber2 mode=0555 owner=root group=bin sysattr=sensitive path=amber2 timestamp=20100731T014051Z
close"""
sysattr_o = """
open sysattr_overlay@1.0-0
add file mode=0555 owner=root group=bin sysattr=sensitive preserve=true path=amber1 overlay=true
close"""
gss = """
open gss@1.0-0
close """
krb = """
open krb5@1.0-0
close """
"license.licensed", "license.licensed.addendum", "amber1", "amber2",
misc_files2 = {
"mech_1": """kerberos_v5 1.2.840.113554.1.2.2 mech_krb5.so kmech_krb5\n""",
"mech_2": """\n""",
"mech_3": """kerberos_v5 1.2.840.113554.1.2.2 mech_krb5.so kmech_krb5\n""",
"mech_4": """\n"""
}
"""Basic fix test: install the amber package, modify one of the
files, and make sure it gets fixed. """
# Test invalid option combo.
# Test invalid option value.
# Test parsable output.
== "info")
# Test unpackaged option.
== "info")
# Initial size
# Corrupt the file
# Make sure the size actually changed
# Verify that unprivileged users are handled by fix.
# Fix the package
# Make sure it's the same size as the original
# check that we didn't reindex
# Verify that removing the publisher of a package that needs
# fixing results in graceful failure (not a traceback).
"""Hardlink test: make sure that a file getting fixed gets any
hardlinks that point to it updated"""
# Get the inode of the orig file
# Get the inode of the new hardlink
# Make sure the inode of the link is now different
"""Verify that fix works with licenses that require acceptance
# Initial size
# Corrupt the file
# Make sure the size actually changed
# Verify that the fix will fail if the license file needs fixing
# since the license action requires acceptance.
# Verify that when the fix failed, it displayed the license
# that required display.
# Verify that fix will display all licenses when it fails,
# if provided the --licenses option.
# Finally, verify that fix will succeed when a package requires
# license acceptance if provided the --accept option.
# Make sure it's the same size as the original
# Alter the owner, group, mode, and timestamp of all files (and
# directories) to something different than the package declares.
for a in m.gen_actions():
# Only want file or dir actions.
continue
# Call pkg fix to fix them.
fix_cmd = "fix"
if verbose:
fix_cmd += " -v"
if quiet:
fix_cmd += " -q"
if parsable:
fix_cmd += " --parsable=0"
if exit != 0:
return exit
editables = []
# Now verify that fix actually fixed them.
for a in m.gen_actions():
# Only want file or dir actions.
continue
# Validate standard attributes.
# Now validate attributes that require special handling.
# Verify that preserved files don't get renamed, and
# the new ones are not installed if the file wasn't
# missing already.
if preserve == "renamenew":
elif preserve == "renameold":
if preserve:
# Verify timestamp (if applicable).
if ts:
if preserve:
"timestamp expected {expected} == "
"actual {actual} for "
"{fname}".format(
else:
"timestamp expected {expected} != "
"actual {actual} for "
"{fname}".format(
# Verify the parsable output (if applicable).
if parsable:
if editables:
else:
"""Ensure that files and directories will have their owner,
group, and modes fixed."""
# Because fix and install operations for directories and
# files can indirectly interact, each package must be
# tested separately and then together (by using a package
# with a mix of files and directories).
for p in ("dir@1.0-0", "file@1.0-0", "preserve@1.0-0",
"preserve@1.1-0", "preserve@1.2-0", "amber@1.0-0"):
"""Verify that fixing a name collision for drivers doesn't
cause a stack trace. Bug 14948"""
"driver_aliases"), "w")
# Change the entry from whee to wqee.
"""Private helper function for ensuring that offline operation
is supported for 'pkg fix' when no package data retrieval is
required."""
# If only attributes are wrong and no local modification
# is on the file content, fix doesn't need to download the
# file data.
# Test the system attribute.
# in tmpfs.
# Need to get creative here to remove the system attributes
# since you need the sys_linkdir privilege which we don't have:
# see run.py:393
# So we re-create the file with correct owner and mode and the
# only thing missing are the sysattrs.
# Make the repository offline.
# If only attributes on a file are wrong, pkg fix still
# succeeds even if the repository is offline.
# Test other attributes: mode, owner, group and timestamp.
for p in ("file@1.0-0","preserve@1.0-0", "preserve@1.1-0",
"preserve@1.2-0", "amber@1.0-0", "sysattr@1.0-0"):
# If modify the file content locally and its attributes, for the
# editable file delivered with preserve=true, fix doesn't need to
# download the file data.
# For editable files delivered with preserve=renamenew or
# preserve=renameold, and non-editable files, fix needs to
# download the file data.
for p in ("file@1.0-0", "preserve@1.1-0", "preserve@1.2-0"):
# Prepare for next test iteration.
"""Test that pkg fix won't try to download all data for
files that fail verification when the data is not going
to be used."""
# For one of the tests we need a repository with at least one
# package with the same publisher as the package we're testing
# with. This is to trigger the package composition code in
# pkg(7) which will cause it to record the source each package
# is available from.
"repo_contents_test_06_download")
"prefix": "test" } })
# First, test for the simple offline / online case where the
# publisher repositories are simply unreachable.
def nop():
pass
# Next, test for the case where the publisher configuration has
# been removed entirely (historically, this generated "Unknown
# Publisher 'foo'" errors).
def rem_test_pub():
def add_test_pub():
# Next, test case for where some packages are from a repository
# that is no longer configured.
def configure_cb():
def add_multi_test_pub():
"""Test that running package fix won't change the manifest of an
installed package even if it has changed in the repository."""
# Specify location as filesystem path.
# Run it one more time to ensure that the manifest on disk
# wasn't changed.
"""Test that the output and exit code works fine for pkg fix."""
info = "editable file has been changed"
# Test that the output is expected when the file has only info
# level mistakes.
# Test that the output is expected when the file has both info
# and error level mistakes.
"""Test that pkg verify / fix should tell the users to look at
the overlaying package in the error message if fix won't repair
the overlaid package."""
file_path_1 = "etc/gss/mech_1"
# First, only install the package that has a file with
# attribute overlay=allow.
# Path verification should report ok.
# Verify should report an error if the file is missing.
# Path verification should report error.
# Fix should be able to repair the file.
# Install the overlaying package.
# Path verification should report ok for both the overlaid package
# and the overlaying package.
# Path verification should report error for both the overlaid package
# and the overlaying package.
# Now pkg verify should still report an error on the overlaid
# package and tell the users to verify the overlaying package.
# Verify should report an error on the overlaying package.
# Fix won't repair the overlaid package but will tell the users
# to fix the overlaying package in the verbose mode.
# Fix should be able to repair the file by fixing the overlaying
# package.
# Test that multiple overlaid files are missing.
# Test that the overlay warning only emits once for each
# package.
# Test the owner, group and mode change.
# Test that verify / fix on system wide could report / fix the
# error on the overlaid and overlaying packges.
# Test that verify / fix on all packages should not emit the
# overlaying warning.
# Test different file types install. Since fix will repair the
# overlaid package in this case, we don't need to tell the users
# to look at the overlaying package.
"dupfile duplink")
# Test overlaid package that contains system attribute error.
# Install the overlaying package.
if __name__ == "__main__":