Beispiel #1
0
    def test_zone_select(self):
        key = 'c286696d887c9aa0611bbb3e2025a45a'
        self.flags(build_plan_encryption_key=key)
        self.stubs.Set(api, 'select', zone_select)

        # Select queries end up being JSON encoded twice.
        # Once to a string and again as an HTTP POST Body
        body = json.dumps({})

        req = fakes.HTTPRequest.blank('/v2/fake/zones/select')
        res_dict = self.controller.select(req, body)

        self.assertTrue('weights' in res_dict)

        for item in res_dict['weights']:
            blob = item['blob']
            decrypt = crypto.decryptor(FLAGS.build_plan_encryption_key)
            secret_item = json.loads(decrypt(blob))
            found = False
            for original_item in GLOBAL_BUILD_PLAN:
                if original_item['name'] != secret_item['name']:
                    continue
                found = True
                for key in ('weight', 'ip', 'zone'):
                    self.assertEqual(secret_item[key], original_item[key])

            self.assertTrue(found)
            self.assertEqual(len(item), 2)
            self.assertTrue('weight' in item)
    def test_zone_select(self):
        key = 'c286696d887c9aa0611bbb3e2025a45a'
        self.flags(build_plan_encryption_key=key)
        self.stubs.Set(api, 'select', zone_select)

        # Select queries end up being JSON encoded twice.
        # Once to a string and again as an HTTP POST Body
        body = json.dumps({})

        req = fakes.HTTPRequest.blank('/v2/fake/zones/select')
        res_dict = self.controller.select(req, body)

        self.assertTrue('weights' in res_dict)

        for item in res_dict['weights']:
            blob = item['blob']
            decrypt = crypto.decryptor(FLAGS.build_plan_encryption_key)
            secret_item = json.loads(decrypt(blob))
            found = False
            for original_item in GLOBAL_BUILD_PLAN:
                if original_item['name'] != secret_item['name']:
                    continue
                found = True
                for key in ('weight', 'ip', 'zone'):
                    self.assertEqual(secret_item[key], original_item[key])

            self.assertTrue(found)
            self.assertEqual(len(item), 2)
            self.assertTrue('weight' in item)
    def test_encrypt_decrypt(self):
        key = 'c286696d887c9aa0611bbb3e2025a45a'
        plain_text = "The quick brown fox jumped over the lazy dog."

        # No IV supplied (all 0's)
        encrypt = crypto.encryptor(key)
        cipher_text = encrypt(plain_text)
        self.assertNotEquals(plain_text, cipher_text)

        decrypt = crypto.decryptor(key)
        plain = decrypt(cipher_text)

        self.assertEquals(plain_text, plain)

        # IV supplied ...
        iv = '562e17996d093d28ddb3ba695a2e6f58'
        encrypt = crypto.encryptor(key, iv)
        cipher_text = encrypt(plain_text)
        self.assertNotEquals(plain_text, cipher_text)

        decrypt = crypto.decryptor(key, iv)
        plain = decrypt(cipher_text)

        self.assertEquals(plain_text, plain)
Beispiel #4
0
    def test_encrypt_decrypt(self):
        key = 'c286696d887c9aa0611bbb3e2025a45a'
        plain_text = "The quick brown fox jumped over the lazy dog."

        # No IV supplied (all 0's)
        encrypt = crypto.encryptor(key)
        cipher_text = encrypt(plain_text)
        self.assertNotEquals(plain_text, cipher_text)

        decrypt = crypto.decryptor(key)
        plain = decrypt(cipher_text)

        self.assertEquals(plain_text, plain)

        # IV supplied ...
        iv = '562e17996d093d28ddb3ba695a2e6f58'
        encrypt = crypto.encryptor(key, iv)
        cipher_text = encrypt(plain_text)
        self.assertNotEquals(plain_text, cipher_text)

        decrypt = crypto.decryptor(key, iv)
        plain = decrypt(cipher_text)

        self.assertEquals(plain_text, plain)
    def _make_weighted_host_from_blob(self, blob):
        """Returns the decrypted blob as a WeightedHost object
        or None if invalid. Broken out for testing.
        """
        decryptor = crypto.decryptor(FLAGS.build_plan_encryption_key)
        try:
            json_entry = decryptor(blob)
            # Extract our WeightedHost values
            wh_dict = json.loads(json_entry)
            host = wh_dict.get('host', None)
            blob = wh_dict.get('blob', None)
            zone = wh_dict.get('zone', None)
            return least_cost.WeightedHost(wh_dict['weight'],
                        host=host, blob=blob, zone=zone)

        except M2Crypto.EVP.EVPError:
            raise InvalidBlob()
Beispiel #6
0
    def test_select(self):
        serializer = zones.WeightsTemplate()

        key = 'c286696d887c9aa0611bbb3e2025a45a'

        encrypt = crypto.encryptor(key)
        decrypt = crypto.decryptor(key)

        item = GLOBAL_BUILD_PLAN[0]
        fixture = {
            'weights': {
                'blob': encrypt(json.dumps(item)),
                'weight': item['weight']
            }
        }

        output = serializer.serialize(fixture)
        res_tree = etree.XML(output)

        self.assertEqual(res_tree.tag, '{%s}weights' % xmlutil.XMLNS_V10)

        for item in res_tree:
            self.assertEqual(item.tag, '{%s}weight' % xmlutil.XMLNS_V10)
            blob = None
            weight = None
            for chld in item:
                if chld.tag.endswith('blob'):
                    blob = chld.text
                elif chld.tag.endswith('weight'):
                    weight = chld.text

            secret_item = json.loads(decrypt(blob))
            found = False
            for original_item in GLOBAL_BUILD_PLAN:
                if original_item['name'] != secret_item['name']:
                    continue
                found = True
                for key in ('weight', 'ip', 'zone'):
                    self.assertEqual(secret_item[key], original_item[key])

            self.assertTrue(found)
            self.assertEqual(len(item), 2)
            self.assertTrue(weight)
    def _make_weighted_host_from_blob(self, blob):
        """Returns the decrypted blob as a WeightedHost object
        or None if invalid. Broken out for testing.
        """
        decryptor = crypto.decryptor(FLAGS.build_plan_encryption_key)
        try:
            json_entry = decryptor(blob)
            # Extract our WeightedHost values
            wh_dict = json.loads(json_entry)
            host = wh_dict.get('host', None)
            blob = wh_dict.get('blob', None)
            zone = wh_dict.get('zone', None)
            return least_cost.WeightedHost(wh_dict['weight'],
                                           host=host,
                                           blob=blob,
                                           zone=zone)

        except M2Crypto.EVP.EVPError:
            raise InvalidBlob()
    def test_select(self):
        serializer = zones.WeightsTemplate()

        key = 'c286696d887c9aa0611bbb3e2025a45a'

        encrypt = crypto.encryptor(key)
        decrypt = crypto.decryptor(key)

        item = GLOBAL_BUILD_PLAN[0]
        fixture = {'weights': {'blob': encrypt(json.dumps(item)),
                               'weight': item['weight']}}

        output = serializer.serialize(fixture)
        res_tree = etree.XML(output)

        self.assertEqual(res_tree.tag, '{%s}weights' % xmlutil.XMLNS_V10)

        for item in res_tree:
            self.assertEqual(item.tag, '{%s}weight' % xmlutil.XMLNS_V10)
            blob = None
            weight = None
            for chld in item:
                if chld.tag.endswith('blob'):
                    blob = chld.text
                elif chld.tag.endswith('weight'):
                    weight = chld.text

            secret_item = json.loads(decrypt(blob))
            found = False
            for original_item in GLOBAL_BUILD_PLAN:
                if original_item['name'] != secret_item['name']:
                    continue
                found = True
                for key in ('weight', 'ip', 'zone'):
                    self.assertEqual(secret_item[key], original_item[key])

            self.assertTrue(found)
            self.assertEqual(len(item), 2)
            self.assertTrue(weight)