Exemplo n.º 1
0
 def testOverrideDefaults(self):
     """Verify we can set custom values at instantiation time."""
     O = cros_collections.Collection('O', a=0, b='string', c={})
     o = O(a=1000)
     self.assertEqual(o.a, 1000)
     self.assertEqual(o.b, 'string')
     self.assertEqual(o.c, {})
Exemplo n.º 2
0
 def testDefaults(self):
     """Verify default values kick in."""
     O = cros_collections.Collection('O', a=0, b='string', c={})
     o = O()
     self.assertEqual(o.a, 0)
     self.assertEqual(o.b, 'string')
     self.assertEqual(o.c, {})
Exemplo n.º 3
0
 def testNewValue(self):
     """Verify we change members correctly."""
     O = cros_collections.Collection('O', a=0, b='string', c={})
     o = O()
     o.a = 'a string'
     o.c = 123
     self.assertEqual(o.a, 'a string')
     self.assertEqual(o.b, 'string')
     self.assertEqual(o.c, 123)
Exemplo n.º 4
0
    def testGetNoNewMembers(self):
        """Verify we cannot get new members after the fact."""
        O = cros_collections.Collection('O', a=0, b='string', c={})
        o = O()

        # Need the func since self.assertRaises evaluates the args in this scope.
        def _getit(collection):
            return collection.does_not_exit

        self.assertRaises(AttributeError, _getit, o)
        self.assertRaises(AttributeError, getattr, o, 'foooo')
Exemplo n.º 5
0
    def testSetNoNewMembers(self):
        """Verify we cannot add new members after the fact."""
        O = cros_collections.Collection('O', a=0, b='string', c={})
        o = O()

        # Need the func since self.assertRaises evaluates the args in this scope.
        def _setit(collection):
            collection.does_not_exit = 10

        self.assertRaises(AttributeError, _setit, o)
        self.assertRaises(AttributeError, setattr, o, 'new_guy', 10)
Exemplo n.º 6
0
# -*- coding: utf-8 -*-
# Copyright 2017 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Baselines for user/group tests."""

from __future__ import print_function

from chromite.lib import cros_collections

# firewall:!:236:236:firewall daemon:/dev/null:/bin/false
UserEntry = cros_collections.Collection('UserEntry',
                                        user=None,
                                        encpasswd='!',
                                        uid=None,
                                        gid=None,
                                        home='/dev/null',
                                        shell='/bin/false')

# tty:!:5:xorg,power,brltty
GroupEntry = cros_collections.Collection('GroupEntry',
                                         group=None,
                                         encpasswd='!',
                                         gid=None,
                                         users=set())

# For users that we allow to login to the system, whitelist a number of
# alternative shells.  These are equivalent from a security POV.
_VALID_LOGIN_SHELLS = set((
    '/bin/sh',
    '/bin/bash',
Exemplo n.º 7
0
 def testString(self):
     """Make sure the string representation is readable by da hue mans."""
     O = cros_collections.Collection('O', a=0, b='string', c={})
     o = O()
     self.assertEqual("Collection_O(a=0, b='string', c={})", str(o))
Exemplo n.º 8
0
# A Device object holds information parsed from the command line input:
#   scheme: DEVICE_SCHEME_SSH, DEVICE_SCHEME_USB, DEVICE_SCHEME_SERVO,
#     or DEVICE_SCHEME_FILE.
#   username: String SSH username or None.
#   hostname: String SSH hostname or None.
#   port: Int SSH or Servo port or None.
#   path: String USB/file path or None.
#   raw: String raw input from the command line.
#   serial_number: String Servo serial number or None.
# For now this is a superset of all information for USB, SSH, or file devices.
# If functionality diverges based on type, it may be useful to split this into
# separate device classes instead.
Device = cros_collections.Collection('Device',
                                     scheme=None,
                                     username=None,
                                     hostname=None,
                                     port=None,
                                     path=None,
                                     raw=None,
                                     serial_number=None)


class DeviceParser(object):
    """Parses devices as an argparse argument type.

  In addition to parsing user input, this class will also ensure that only
  supported device schemes are accepted by the parser. For example,
  `cros deploy` only makes sense with an SSH device, but `cros flash` can use
  SSH, USB, or file device schemes.

  If the device input is malformed or the scheme is wrong, an error message will
  be printed and the program will exit.