示例#1
0
    def testMultiAdd(self, winreg, build_info):
        # Mock add registry keys
        kpath = (r'SOFTWARE\Microsoft\Windows NT\CurrentVersion'
                 r'\SoftwareProtectionPlatform')
        args = [
            'HKLM', kpath, 'KeyManagementServiceName',
            'kms-server.example.com', 'REG_SZ', False
        ]
        skv = winreg.return_value.SetKeyValue
        ra = registry.RegAdd(args, build_info)
        ra.Run()
        skv.assert_called_with(key_path=kpath,
                               key_name='KeyManagementServiceName',
                               key_value='kms-server.example.com',
                               key_type='REG_SZ',
                               use_64bit=False)

        # Missing arguments
        args = [
            'HKLM', kpath, 'KeyManagementServiceName', 'kms-server.example.com'
        ]
        ra = registry.RegAdd(args, build_info)
        self.assertRaises(registry.ActionError, ra.Run)

        # Multiple missing arguments
        args = [[
            'HKLM', kpath, 'KeyManagementServiceName',
            'kms-server.example.com', 'REG_SZ'
        ], [
            'HKLM', kpath, 'KeyManagementServiceName', 'kms-server.example.com'
        ]]
        ra = registry.MultiRegAdd(args, build_info)
        self.assertRaises(registry.ActionError, ra.Run)
示例#2
0
  def testMultiAdd(self, sv, build_info):
    ra = registry.RegAdd(ARGS, build_info)
    ra.Run()
    sv.assert_called_with(NAME, VALUE, ROOT, PATH, TYPE, USE_64)

    # Missing arguments
    args = [ROOT, PATH, NAME, VALUE]
    ra = registry.RegAdd(args, build_info)
    self.assertRaises(registry.ActionError, ra.Run)

    # Multiple missing arguments
    args = [ARGS, [ROOT, PATH, NAME, VALUE]]
    ra = registry.MultiRegAdd(args, build_info)
    self.assertRaises(registry.ActionError, ra.Run)
示例#3
0
  def testAdd(self, sv, build_info):
    # Mock add registry keys
    ra = registry.RegAdd(ARGS, build_info)
    ra.Run()
    sv.assert_called_with(NAME, VALUE, ROOT, PATH, TYPE, USE_64)

    # Registry error
    sv.side_effect = registry.registry.Error
    self.assertRaises(registry.ActionError, ra.Run)
示例#4
0
    def testAddValidation(self):
        # List not passed
        r = registry.RegAdd('String', None)
        self.assertRaises(registry.ValidationError, r.Validate)

        # Too many args
        r = registry.RegAdd(
            ['HKLM', 'SOFTWARE/fake', 'foo', 'bar', 'REG_SZ', True, 'baz'],
            None)
        self.assertRaises(registry.ValidationError, r.Validate)

        # Not enough args
        r = registry.RegAdd(['SOFTWARE/fake', 'foo', 'bar', 'REG_SZ'], None)
        self.assertRaises(registry.ValidationError, r.Validate)

        # Type error
        r = registry.RegAdd(['HKLM', 'SOFTWARE/fake', 'foo', '1', 'REG_DWORD'],
                            None)
        self.assertRaises(registry.ValidationError, r.Validate)

        # Too many keys
        r = registry.RegAdd(
            [['HKLM', 'SOFTWARE/fake', 'foo', 1, 'REG_DWORD'],
             ['HKLM', 'SOFTWARE/boo', 'fake', 100, 'REG_DWORD']], None)
        self.assertRaises(registry.ValidationError, r.Validate)

        # Valid calls
        r = registry.RegAdd(['HKLM', 'SOFTWARE\fake', 'foo', 'bar', 'REG_SZ'],
                            None)
        r.Validate()
示例#5
0
  def testAddValidation(self):
    # List not passed
    r = registry.RegAdd(NAME, None)
    self.assertRaises(registry.ValidationError, r.Validate)

    # Too many args
    r = registry.RegAdd([ROOT, PATH, NAME, NAME, TYPE, True, NAME], None)
    self.assertRaises(registry.ValidationError, r.Validate)

    # Not enough args
    r = registry.RegAdd([PATH, NAME, NAME, TYPE], None)
    self.assertRaises(registry.ValidationError, r.Validate)

    # Type error
    r = registry.RegAdd([ROOT, PATH, NAME, '1', 'REG_DWORD'], None)
    self.assertRaises(registry.ValidationError, r.Validate)

    # Too many keys
    r = registry.RegAdd([
        [ROOT, PATH, NAME, 1, TYPE],
        [ROOT, PATH, NAME, 100, TYPE]], None)
    self.assertRaises(registry.ValidationError, r.Validate)

    # Valid calls
    r = registry.RegAdd([ROOT, PATH, NAME, VALUE, TYPE], None)
    r.Validate()
示例#6
0
 def testRun(self, winreg, build_info):
   kpath = (r'SOFTWARE\Microsoft\Windows NT\CurrentVersion'
            r'\SoftwareProtectionPlatform')
   args = [
       'HKLM', kpath, 'KeyManagementServiceName', 'kms-server.example.com',
       'REG_SZ', False
   ]
   skv = winreg.return_value.SetKeyValue
   ra = registry.RegAdd(args, build_info)
   ra.Run()
   skv.assert_called_with(
       key_path=kpath,
       key_name='KeyManagementServiceName',
       key_value='kms-server.example.com',
       key_type='REG_SZ',
       use_64bit=False)
   # registry error
   skv.side_effect = registry.registry.RegistryError
   self.assertRaises(registry.ActionError, ra.Run)
   skv.side_effect = None
   # missing arguments
   ra = registry.RegAdd(args[2:], build_info)
   self.assertRaises(registry.ActionError, ra.Run)