def test_WriteRepoYaml(self): """Test WriteRepoYaml and _WriteConfig.""" options = update_release_keys.ParseArgs(self.argv) kd = update_release_keys.KeyringData(self.prod, self.base, options, self.config) self.assertEqual(kd.contents_yaml, os.path.join(self.base, 'contents.yaml')) kd.keysets = {'metadata-version': 0, 'mp-keysets': ['foo-mp']} kd.WriteRepoYaml() self.assertEqual(osutils.ReadFile(kd.contents_yaml), 'metadata-version: 0\nmp-keysets:\n- foo-mp\n')
def test_ReadsRepoYaml(self): """Test missing file case.""" osutils.WriteFile(os.path.join(self.base, 'contents.yaml'), 'metadata-version: 0\nmp-keysets: [foo-mp]\n') options = update_release_keys.ParseArgs(self.argv) kd = update_release_keys.KeyringData(self.prod, self.base, options, self.config) self.assertDictEqual({ 'metadata-version': 0, 'mp-keysets': ['foo-mp'] }, kd.keysets)
def test_ImportKeysChecksExists(self): """Test that existing configs are properly handled.""" kd = self.keydata osutils.WriteFile(os.path.join(kd.configs, 'foo-mp.yaml'), 'bad: 0', makedirs=True) self.assertRaises(update_release_keys.KeyimportError, kd.ImportKeyset, 'foo-mp', 'FooMPKeys') kd.options = update_release_keys.ParseArgs(self.argv + ['--new-only']) kd.ImportKeyset('foo-mp', 'FooMPKeys') self.assertEqual({'metadata-version': 0}, kd.keysets) self.logdebug.assert_called_once()
def setUp(self): self.prod = os.path.join(self.tempdir, 'prod') os.makedirs(os.path.join(self.prod, 'keys')) self.base = os.path.join(self.prod, 'v2-keys') os.makedirs(self.base) for dname in 'public', 'config': os.mkdir(os.path.join(self.base, dname)) conf_path = os.path.join(self.prod, 'signer', 'configs', 'cros_common.config') os.makedirs(os.path.dirname(conf_path)) with open(conf_path, 'w') as fp: fp.write('[keysets]\nfoo-mp-v3 = FooMPKeys-v3\n') self.config = update_release_keys.ParseSignerConfig(self.prod) self.argv = ['-d', self.base] options = update_release_keys.ParseArgs(self.argv) self.keydata = update_release_keys.KeyringData(self.prod, self.base, options, self.config) os.chdir(self.keydata.public) self.wc = self.PatchObject(self.keydata, '_WriteConfig') self.logdebug = self.PatchObject(logging, 'debug') self.loginfo = self.PatchObject(logging, 'info') self.lognotice = self.PatchObject(logging, 'notice') self.logwarning = self.PatchObject(logging, 'warning') self.logerror = self.PatchObject(logging, 'error')
def test_ReadMissingRepoYaml(self): """Test missing file case.""" options = update_release_keys.ParseArgs(self.argv) kd = update_release_keys.KeyringData(self.prod, self.base, options, self.config) self.assertDictEqual({'metadata-version': 0}, kd.keysets)