Example #1
0
    def test_mismatched_paths(self):
        a = self.cp('path', 'package_name/${platform}-${os_ver}', 'latest')
        b = self.cp('else', 'package_name/windows-amd64-something_10',
                    'deadbeef' * 5)

        with cipd.pin_check_fn(None, None) as check:
            with self.assertRaisesRegexp(ValueError, 'Mismatched path'):
                check(a, b)
Example #2
0
    def test_mismatched_pins(self):
        # if a is already a pin, b must match its version exactly
        a = self.cp('path', 'package_name/${platform}-${os_ver}',
                    'deadbeef' * 5)
        b = self.cp('path', 'package_name/windows-amd64-something_10',
                    'badc0ffe' * 5)

        with cipd.pin_check_fn(None, None) as check:
            with self.assertRaisesRegexp(ValueError, 'Mismatched pins'):
                check(a, b)
Example #3
0
    def test_correct_pins(self):
        a = self.cp('path', 'package_name/${platform}-${os_ver}', 'latest')
        b = self.cp('path', 'package_name/windows-amd64-something_10',
                    'deadbeef' * 5)

        with cipd.pin_check_fn(None, None) as check:
            # will not raise
            check(a, b)

            a = self.cp('path', 'other/${platform}-${os_ver}', 'latest')
            b = self.cp('path', 'other/windows-amd64-something_10',
                        'deadbeef' * 5)

            # will not raise
            check(a, b)
Example #4
0
    def validate(self, request):
        """Validation that requires the task_request.

    Full validation includes calling this method, and the checks in
    _pre_put_hook.

    Raises ValueError if this is invalid, otherwise returns None.
    """
        props = request.properties

        if props.cipd_input and self.cipd_pins:
            with cipd.pin_check_fn(None, None) as check:
                check(props.cipd_input.client_package,
                      self.cipd_pins.client_package)
                if len(props.cipd_input.packages) != len(
                        self.cipd_pins.packages):
                    raise ValueError('Mismatched package lengths')
                for a, b in zip(props.cipd_input.packages,
                                self.cipd_pins.packages):
                    check(a, b)
Example #5
0
    def test_mismatched_names(self):
        a = self.cp('', 'package_name/${platform}-${os_ver}', 'latest')
        b = self.cp('', 'else/windows-amd64-something_10', 'deadbeef' * 5)

        with cipd.pin_check_fn(None, None) as check:
            with self.assertRaisesRegexp(ValueError,
                                         'Mismatched package_name'):
                check(a, b)

        a = self.cp('', 'package_name/${platform}-${os_ver}', 'latest')
        b = self.cp('', 'package_name/windows-amd64-something_10',
                    'deadbeef' * 5)
        # will not raise
        check(a, b)

        # This doesn't match the previous knowledge of platform or os_ver, so it
        # will not match.
        a = self.cp('', 'package_name/${platform}-${os_ver}', 'latest')
        b = self.cp('', 'package_name/linux-32-nerds', 'deadbeef' * 5)

        with self.assertRaisesRegexp(ValueError, 'Mismatched package_name'):
            check(a, b)