#
# 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 json
import os
import shutil
import six
import stat
import tempfile
import unittest
# Don't discard repository or setUp() every test.
# Tests in this suite use the read only data directory.
foo_pkg = """
add set name=pkg.summary value="Example package foo."
add dir mode=0755 owner=root group=bin path=lib
add dir mode=0755 owner=root group=bin path=usr
add file tmp/libfoo.so.1 mode=0755 owner=root group=bin path=lib/libfoo.so.1 variant.debug.foo=false
add file tmp/libfoo_debug.so.1 mode=0755 owner=root group=bin path=lib/libfoo.so.1 variant.debug.foo=true
close """
incorp_pkg = """
add set name=pkg.summary value="Incorporation"
add depend type=incorporate fmri=quux@0.1,5.11-0.1
close
add set name=pkg.summary value="Incorporation"
add depend type=incorporate fmri=quux@1.0,5.11-0.2
close """
signed_pkg = """
add depend type=require fmri=foo@1.0
add set name=authorized.species value=bobcat
close """
quux_pkg = """
add set name=pkg.summary value="Example package quux."
add depend type=require fmri=pkg:/incorp
close
add set name=pkg.summary value="Example package quux."
add depend type=require fmri=pkg:/incorp
add dir mode=0755 owner=root group=bin path=usr
close """
if not dest_dir:
for c in certs:
"""Private helper function to publish packages needed for
testing.
"""
# Publish packages needed for tests.
# Sign the 'signed' package.
sign_args = "-k {key} -c {cert} -i {i1} -i {i2} " \
"-i {i3} -i {i4} -i {i5} -i {i6} {pkg}".format(
"ch1_ta1_cert.pem"),
"ch2_ta1_cert.pem"),
"ch3_ta1_cert.pem"),
"ch4_ta1_cert.pem"),
"ch5_ta1_cert.pem"),
"ch1_ta3_cert.pem"),
)
# This is just a test assertion to verify that the
# package was signed as expected.
return [
]
"""Private helper function to archive packages needed for
testing.
"""
return arc_path
"test", "empty", "void"])
# First repository will contain all packages.
# Second repository will contain only foo.
# Third repository will contain only signed.
# Fourth will be empty.
# Fifth will have a publisher named 'void', but no packages.
# Setup base test paths.
"signing_certs", "produced")
"code_signing_certs")
"chain_certs")
"publisher_cas")
"inter_certs")
"trust_anchors")
# Publish packages.
# Copy foo to second repository and build index.
# Copy incorp and quux to third repository and build index.
# Now create a package archive containing all packages, and
# then one for each.
# Store FMRIs for later use.
"""Verify that the list operation works as expected when
compositing publishers.
"""
# Create an image and verify no packages are known.
"test")
# Verify list output for multiple, disparate sources using
# different combinations of archives and repositories.
expected = \
("foo (test) 1.0 ---\n"
"signed (test) 1.0 ---\n")
# Verify removing origins while others remain configured
# works as expected.
expected = "signed (test) 1.0 ---\n"
# Verify simply adding origins works as expected.
expected = \
("foo (test) 1.0 ---\n"
"incorp (test) 2.0 ---\n"
"incorp (test) 1.0 ---\n"
"quux (test2) 1.0-0.2 ---\n"
"quux (test2) 0.1-0.1 ---\n"
"signed (test) 1.0 ---\n")
# Verify removing and adding origins at the same time works as
# expected.
# Verify packages can be installed from disparate sources and
# show in default list output.
expected = \
("foo (test) 1.0 i--\n"
"incorp (test) 1.0 i--\n"
"quux (test2) 0.1-0.1 i--\n"
"signed (test) 1.0 i--\n")
"""Verify that the info operation works as expected when
compositing publishers.
"""
# because we compare date strings we must run this in
# a consistent locale, which we made 'C'
# Create an image and verify no packages are known.
# Verify info result for multiple disparate sources using
# different combinations of archives and repositories.
"signed@1.0 quux@0.1".format(
# Verify package installed from archive shows in default info
# output.
expected = """\
Name: foo
Summary: Example package foo.
State: Installed
Publisher: test
Version: 1.0
Branch: None
Packaging Date: {pkg_date}
Last Install Time: {pkg_install}
Size: 41.00 B
FMRI: {pkg_fmri}
# Change locale back to 'UTF-8' to not affect other test cases.
"""Verify that the contents operation works as expected when
compositing publishers.
"""
# Create an image and verify no packages are known.
# Verify contents result for multiple disparate sources using
# different combinations of archives and repositories.
# Verify package installed from archive can be used with
# contents.
"""Verify that install and update work as expected when
compositing publishers.
"""
#
# Create an image and verify no packages are known.
#
"test")
# Verify that packages with dependencies can be installed when
# using multiple, disparate sources.
# Verify publisher can be removed.
#
# Create an image using the signed archive.
#
# Verify that signed package can be installed and the archive
# configured for the publisher allows dependencies to be
# satisfied.
# Verify that removing all packages and the signed archive as
# a source leaves only foo known.
expected = "foo 1.0 ---\n"
#
# Create an image and verify no packages are known.
#
# Install an older version of a known package.
# Verify that packages can be updated when using multiple,
# disparate sources (that have some overlap).
#
# Create an image using the signed archive.
#
# Add the incorp archive as a source.
# Now verify that temporary package sources can be used during
# package operations when multiple, disparate sources are
# already configured for the same publisher.
"""Verify that search works as expected when compositing
publishers.
"""
#
# Create an image and verify no packages are known.
#
# Add multiple, different sources.
# Verify a remote search that should only match one of the
# sources works as expected.
expected = "pkg:/foo@1.0\n"
# Verify a remote search for multiple terms that should match
# each source works as expected.
expected = \
("pkg:/foo@1.0\n"
"pkg:/signed@1.0\n")
# Add a source that partially overlaps with the existing ones
# (provides some of the same packages) and verify that some
# of the results are duplicated (since search across sources
# is a simple aggregation of all sources).
expected = \
("pkg:/foo@1.0\n"
"pkg:/incorp@1.0\n"
"pkg:/incorp@2.0\n"
"pkg:/signed@1.0\n"
"pkg:/foo@1.0\n"
"pkg:/signed@1.0\n")
# Add a publisher with no origins and verify output still
# matches expected.
# Elide error output from client to verify that search
# results were returned despite error.
"""Verify empty repositories and repositories with a publisher,
but no packages, can be used with -g."""
# Verify usage alone.
# Verify usage in combination with non-empty.
expected = \
("foo (test) 1.0 ---\n")
if __name__ == "__main__":