Esempio n. 1
0
 def test_creates_name_from_url(self):
     parts = [self.getUniqueString() for _ in range(1, 5)]
     source_url = "http://example.com/%s/" % "/".join(parts)
     expected_keyring_name = hashlib.md5(
         source_url.encode("utf8")).hexdigest()
     self.assertEqual(expected_keyring_name,
                      keyrings.calculate_keyring_name(source_url))
Esempio n. 2
0
    def test_returns_sources(self):
        self.patch(keyrings, "write_keyring")
        sources = [{
            "url": "http://%s" % self.getUniqueString(),
            "keyring_data": factory.make_bytes(),
        } for _ in range(5)]

        keyring_path = self.make_dir()

        expected_values = [
            os.path.join(keyring_path,
                         keyrings.calculate_keyring_name(source["url"]))
            for source in sources
        ]

        returned_sources = keyrings.write_all_keyrings(keyring_path, sources)
        actual_values = [source.get("keyring") for source in returned_sources]
        self.assertEqual(expected_values, actual_values)
Esempio n. 3
0
    def test_writes_keyring_data(self):
        fake_write_keyring = self.patch(keyrings, "write_keyring")

        sources = [{
            "url": "http://%s" % self.getUniqueString(),
            "keyring_data": factory.make_bytes(),
        } for _ in range(5)]

        keyring_path = self.make_dir()

        keyrings.write_all_keyrings(keyring_path, sources)

        expected_calls = (mock.call(
            os.path.join(
                keyring_path,
                keyrings.calculate_keyring_name(source["url"]),
            ),
            source["keyring_data"],
        ) for source in sources)
        self.assertThat(fake_write_keyring, MockCallsMatch(*expected_calls))
Esempio n. 4
0
    def test_ignores_existing_keyrings(self):
        self.patch(keyrings, 'write_keyring')
        fake_maaslog = self.patch(keyrings, 'maaslog')
        source = {
            'url': self.getUniqueString(),
            'keyring': self.getUniqueString(),
            'keyring_data': self.getUniqueString(),
            }

        keyring_path = self.make_dir()

        [returned_source] = keyrings.write_all_keyrings(keyring_path, [source])
        expected_keyring = os.path.join(
            keyring_path, keyrings.calculate_keyring_name(source['url']))
        self.assertEqual(expected_keyring, returned_source.get('keyring'))
        self.assertThat(
            fake_maaslog.warning,
            MockCalledWith(
                "Both a keyring file and keyring data were specified; "
                "ignoring the keyring file."))