305N/A# The contents of this file are subject to the terms of the 305N/A# Common Development and Distribution License (the "License"). 305N/A# You may not use this file except in compliance with the License. 305N/A# See the License for the specific language governing permissions 305N/A# and limitations under the License. 305N/A# When distributing Covered Code, include this CDDL HEADER in each 305N/A# If applicable, add the following below this CDDL HEADER, with the 305N/A# fields enclosed by brackets "[]" replaced with your own identifying 305N/A# information: Portions Copyright [yyyy] [name of copyright owner] 3296N/A# Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. 2026N/A "set name=foo value=f'o'o",
2026N/A "set name=foo value='f\"o \"o'",
2026N/A "set name=foo value='b\"a \"r' value='f\"o \"o'",
2026N/A "set name=foo value=\"f'o 'o\"",
2026N/A "set name=foo value=\"b'a 'r\" value=\"f'o 'o\"",
2026N/A "set name=foo value='f\"o \\' \"o'",
2026N/A "set name=foo value='b\"a \\' \"r' value='f\"o \\' \"o'",
2026N/A "set name=foo value='\"foo\"'",
2026N/A "set name=foo value='\"bar\"'value='\"foo\"'",
2026N/A "set name=foo value=\"'foo'\"",
2026N/A "set name=foo value=\"'bar'\" value=\"'foo'\"",
2026N/A "set name=foo value='\"fo\\\'o\"'",
2026N/A "set name=foo value='\"ba\\\'r\"' value='\"fo\\\'o\"'",
2026N/A "set name=foo value=\"'fo\\\"o'\"",
2026N/A "set name=foo value=\"'ba\\\"r'\" value=\"'fo\\\"o'\"",
2026N/A 'set name=foo value=ab value="" value=c',
2026N/A "file 12345 name=\"foo bar\" attr=\"bar baz\" path=/tmp/foo",
2026N/A "file 12345 name=\"foo bar\" attr=\"bar baz\" path=/tmp/foo",
2026N/A "file 12345 name=foo value=\"bar baz quux\" path=/tmp/foo",
2026N/A "file 12345 name=\"foo bar baz\" value=quux path=/tmp/foo",
2026N/A "driver alias=pci1234,56 alias=pci4567,89 class=scsi name=lsimega",
2026N/A "signature 12345 algorithm=foo",
591N/AIncorrect attribute value. 591N/AIncorrect attribute list. 2639N/A # For convenience, we allow set actions to be expressed as 2639N/A # "<name>=<value>", rather than "name=<name> value=<value>", but 2639N/A # we always convert to the latter. Verify that both forms are 591N/A # Make sure that unescaped double quotes are parsed properly 591N/A # inside a single-quoted value. 591N/A # Make sure that escaped single quotes are parsed properly 591N/A # inside a single-quoted value. 591N/A # Unescaped, unpaired quotes are allowed in the middle of values 591N/A # without further quoting 591N/A # They can even be paired. Note this is not like shell quoting. 591N/A # An unquoted value can end in an escaped backslash 591N/A # An action with multiple identical attribute names should 591N/A # result in an attribute with a list value. 1384N/A # An action with an empty value. 1384N/A # An action with an empty value as part of a list. 1618N/A # An action with its key attribute and extra attributes that 1618N/A # are not used by the package system. 1618N/A 'Distribution License 1.0 (CDDL)" custom="foo" ' 1618N/A 'and Distribution License 1.0 (CDDL)')
2233N/A # Really long actions with lots of backslash-escaped quotes 2233N/A a =
action.
fromstr(r
'set name=pkg.description value="Sphinx is a tool that makes it easy to create intelligent \"and beautiful documentation f\"or Python projects (or \"other documents consisting of\" multiple reStructuredText so\"urces), written by Georg Bran\"dl. It was originally created\" to translate the new Python \"documentation, but has now be\"en cleaned up in the hope tha\"t it will be useful to many o\"ther projects. Sphinx uses re\"StructuredText as its markup \"language, and many of its str\"engths come from the power an\"d straightforwardness of reSt\"ructuredText and its parsing \"and translating suite, the Do\"cutils. Although it is still \"under constant development, t\"he following features are alr\"eady present, work fine and c\"an be seen \"in action\" \"in the Python docs: * Output \"formats: HTML (including Wind\"ows HTML Help) and LaTeX, for\" printable PDF versions * Ext\"ensive cross-references: sema\"ntic markup and automatic lin\"ks for functions, classes, gl\"ossary terms and similar piec\"es of information * Hierarchi\"cal structure: easy definitio\"n of a document tree, with au\"tomatic links to siblings, pa\"rents and children * Automati\"c indices: general index as w\"ell as a module index * Code \"handling: automatic highlight\"ing using the Pygments highli\"ghter * Various extensions ar\"e available, e.g. for automat\"ic testing of snippets and in\"clusion of appropriately formatted docstrings."')
2457N/A # Make sure that the hash member of the action object properly 2457N/A # contains the value of the "hash" named attribute. 1618N/A """Test license action attributes.""" 1618N/A # Verify license attributes for must-accept / must-display 1618N/A 'Distribution License 1.0 (CDDL)" custom="foo" ' 1618N/A 'Distribution License 1.0 (CDDL)" must-accept=true ' 1618N/A 'Distribution License 1.0 (CDDL)" must-accept=True ' 1618N/A 'Distribution License 1.0 (CDDL)" must-accept=True ')
3312N/A """Private helper function for action stringification 1938N/A """Test that actions convert to strings properly. This means 1938N/A that we can feed the resulting string back into fromstr() and 3312N/A get an identical action back (excluding a few cases detailed in 3312N/A # The first case that invariant doesn't hold is when you specify 2457N/A # the payload hash as the named attribute "hash", in which case 2457N/A # the resulting re-stringification emits the payload hash as a 2457N/A # positional attribute again ... 2457N/A # ... unless of course the hash can't be represented that way. 2685N/A "hash=\"one with spaces\"":
"one with spaces",
2685N/A "hash='one with \" character'":
'one with " character',
2685N/A "hash=\"'= !@$%^\)(*\"":
"'= !@$%^\)(*",
2685N/A """hash="\\"'= \\ " """:""""'= \\ """,
3312N/A # The attributes are verified separately from the stringified 3312N/A # action in the tests below to ensure that the attributes were 3312N/A # parsed independently and not as a single value (e.g. 3312N/A # 'file path=etc/foo\nfacet.debug=true' is parsed as having a 3312N/A # path attribute and a facet.debug attribute). 3312N/A # The next case that invariant doesn't hold is when you have 3312N/A # multiple, quoted values for a single attribute (this case 3312N/A # primarily exists for use with line-continuation support 3312N/A # offered by the Manifest class). 3312N/A "set name=pkg.description value='foo ''bar ''baz'",
3312N/A "set name=pkg.description value='foo ' 'bar ' 'baz'",
3312N/A 'set name=pkg.description value="foo " "bar " "baz"'):
3312N/A "set name=pkg.description value='foo \"bar\" ''baz'",
3312N/A "set name=pkg.description value='foo \"bar\" '\"baz\""):
3312N/A # The next case that invariant doesn't hold is when there are 3312N/A # multiple whitespace characters between attributes or after the 3312N/A "set name=pkg.description value=foo",
3312N/A "set name=pkg.description value=foo",
3312N/A "set name=pkg.description value=foo",
3312N/A "set\n name=pkg.description \nvalue=foo",
3312N/A "set\t\nname=pkg.description\t\nvalue=foo"):
3312N/A # To force stressing the parsing logic a bit more, we 3312N/A # parse an action with a multi-value attribute that 3312N/A # needs concatention each time before we parse a 3312N/A # single-value attribute that needs concatenation. 3312N/A # This simulates a refcount bug that was found during 3312N/A # development and serves as an extra stress-test. 3312N/A 'set name=multi-value value=bar value="foo ""baz"',
3312N/A 'set name=multi-value value=bar value="foo baz"',
3312N/A 'value': [
'bar',
'foo baz'] })
2026N/A "signature 54321 algorithm=baz")
2026N/A # action.sig_str should return an identical string each 2026N/A # time it's called. Also, parsing the result of 2026N/A # sig_str so produce the same action. 2026N/A # If s2 is None, then s was a different signature 2026N/A # action, so there is no output to parse. 2026N/A # Test that using an unknown sig_version triggers the 2026N/A # Test that the sig_str of a signature action other than the 2026N/A "signature 98765 algorithm=foobar")
1234N/A # If the action isn't malformed, something is wrong. 1234N/A # If the action isn't invalid, something is wrong. 2639N/A # Nothing but the action type or type is malformed. 591N/A # Bad quoting: missing close quote 591N/A # Bad quoting: quote in key 1234N/A # Missing key attribute 'fmri'. 3366N/A # XXX Fails in Python 3.4 due to module import issue; see 3366N/A # set_invalid_action_error in actions/_common.c. 3366N/A # Multiple values not allowed for 'fmri' if 'type' is 3366N/A "type=require-any fmri=foo fmri=bar")
2254N/A # 'path' attribute specified multiple times 1659N/A # 'data' used as an attribute key 1234N/A # Missing required attribute 'path'. 1234N/A # Missing required attribute 'name'. 873N/A "driver alias=pci1234,56 alias=pci4567,89 class=scsi")
1973N/A # Verify malformed actions > 255 characters don't cause corrupt 1973N/A # exception action strings. 1973N/A self.
assertMalformed(
"""legacy arch=i386 category=GNOME2,application,JDSosol desc="XScreenSaver is two things: it is both a large collection of screen savers (distributed in the "hacks" packages) and it is also the framework for blanking and locking the screen (this package)." hotline="Please contact your local service provider" name="XScreenSaver is two things: it is both a large collection of screen savers (distributed in the "hacks" packages) and it is also the framework for blanking and locking the screen (this package)." pkg=SUNWxscreensaver vendor="XScreenSaver Community" version=5.11,REV=110.0.4.2010.07.08.22.18""")
1973N/A self.
assertMalformed(
"""legacy arch=i386 category=GNOME2,application,JDSosol desc="XScreenSaver is two things: it is both a large collection of screen savers (distributed in the "hacks" packages) and it is also the framework for blanking and locking the screen (this package)." hotline="Please contact your local service provider" name="XScreenSaver is two things: it is both a large collection of screen savers (distributed in the "hacks" packages) and it is also the framework for blanking and locking the screen (this package)." pkg=SUNWxscreensaver-l10n vendor="XScreenSaver Community" version=5.11,REV=110.0.4.2010.07.08.22.18""")
2026N/A # Missing required attribute 'algorithm'. 2026N/A "signature 12345 pkg.cert=bar")
2457N/A # The payload hash can't be specified as both a named and a 2457N/A # positional attribute if they're not identical. 1755N/A """Verify that action validate() works as expected; currently 1755N/A only used during publication or action execution failure.""" 3417N/A # Verify mode attributes for file specified more than once are 2476N/A # Verify predicate and target attributes of FMRIs must be valid. 2476N/A "depend type=require-any fmri=foo fmri=bar fmri=invalid@abc",
3366N/A # Missing required attribute 'type'. 3366N/A "depend type=unknown fmri=foo@1.0",
3366N/A # Multiple values never allowed for depend action 'type' attribute. 3366N/A "depend type=require type=require-any fmri=foo",
3366N/A # Mutiple fmri values only allowed for require-any deps. 3366N/A "depend type=require fmri=foo fmri=bar",
2476N/A # Predicate is missing for conditional dependency. 2476N/A "depend type=conditional fmri=foo",
2476N/A # Predicate value is invalid. 2476N/A "depend type=conditional predicate=-invalid fmri=foo",
2476N/A # Predicate isn't valid for dependency type. 2476N/A "depend type=require predicate=1invalid fmri=foo",
2476N/A # root-image attribute is only valid for origin dependencies. 2476N/A "depend type=require fmri=foo root-image=true",
2476N/A # Multiple values for predicate are not allowed. 3138N/A "depend type=conditional predicate=foo predicate=bar fmri=baz",
3138N/A # Multiple values for ignore-check are not allowed. 3138N/A "depend type=require fmri=foo ignore-check=true ignore-check=false"):
2476N/A # Verify multiple values for file attributes are rejected. 2476N/A for attr in (
"pkg.size",
"pkg.csize",
"chash",
"preserve",
2476N/A "overlay",
"elfhash",
"original_name",
"facet.doc",
2476N/A # Verify invalid values are not allowed for mode attribute on 1755N/A "mode=44755",
"mode=44",
"mode=999",
"mode=0898"):
2476N/A # Verify multiple values aren't allowed for legacy action 2476N/A for attr in (
"category",
"desc",
"hotline",
"name",
"vendor",
2476N/A # Verify multiple values aren't allowed for gid of group. 2476N/A # Verify only numeric value is allowed for gid of group. 2476N/A # Verify multiple values are not allowed for must-accept and 2476N/A # must-display attributes of license actions. 3158N/A nact =
"license license=copyright {attr}=true " \
2476N/A # Ensure link and hardlink attributes are validated properly. 2453N/A # Action with mediator without mediator properties is 2453N/A # Action with multiple mediator values is invalid. 2453N/A "mediator=vi mediator=vim " \
2453N/A # Action with mediator properties without mediator 2453N/A "mediator-implementation":
"svr4",
2453N/A "mediator-priority":
"site",
2453N/A # Action with multiple values for any property is 2453N/A # mediator-priority alone isn't 2453N/A # valid, so test multiple value 2453N/A # Verify invalid mediator names are rejected. 3158N/A "mediator=\"{1}\" mediator-implementation=vim" \
2453N/A # Verify invalid mediator-versions are rejected. 3158N/A "mediator=vim mediator-version={1}" \
2476N/A # Verify invalid mediator-implementations are rejected. 3158N/A "mediator=vim mediator-implementation={1}" \
2476N/A # Verify multiple targets are not allowed. 2476N/A # Verify multiple values are not allowed for set actions such as 2476N/A # pkg.description, pkg.obsolete, pkg.renamed, and pkg.summary. 2476N/A for attr in (
"pkg.description",
"pkg.obsolete",
"pkg.renamed",
3197N/A "pkg.summary",
"pkg.depend.explicit-install"):
2476N/A # Verify signature action attribute 'value' is required during 2476N/A # Verify multiple values aren't allowed for user attributes. 2476N/A for attr in (
"password",
"group",
"gcos-field",
"home-dir",
2476N/A for attr in (
"uid",
"lastchg",
"min",
"max",
"warn",
"inactive",
2476N/A # Verify only numeric values are allowed for user attributes 2476N/A for attr in (
"uid",
"lastchg",
"min",
"max",
"warn",
"inactive",
3160N/A "set name=pkg.additional-update-on-uninstall " 3160N/A "set name=pkg.additional-update-on-uninstall " 3160N/A # Unknown actuator (should pass) 3160N/A "set name=pkg.additional-update-on-update value=A@1")