示例#1
0
    def test_invalid_certificate_config(self):
        self.maxDiff = None

        # Given
        url = "http://acme.com"
        config = Configuration()
        config.update(store_url=url)
        config.update(auth=("nono", "le petit robot"))
        config.write(self.config)

        responses.add_callback(responses.GET, re.compile(url + "/*"),
                               self._dummy_ssl_error_callback)

        error_message = "To connect to 'acme.com' insecurely, add the `-k` " \
                        "flag to enpkg command"

        # When
        with use_given_config_context(self.config):
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    main(["--config"])

        # Then
        last_line = m.value.splitlines()[-1]
        self.assertMultiLineEqual(last_line, error_message)
示例#2
0
    def test_invalid_certificate_dont_webservice(self):
        self.maxDiff = None

        # Given
        url = "http://acme.com"
        config = Configuration()
        config.update(use_webservice=False,
                      indexed_repositories=["http://acme.com/repo/"])
        config.update(auth=("nono", "le petit robot"))
        config.write(self.config)

        def callback(request):
            msg = "Dummy SSL error"
            raise requests.exceptions.SSLError(msg, request=request)
        responses.add_callback(responses.HEAD, re.compile(url + "/*"),
                               callback)

        error_message = textwrap.dedent("""\
            SSL error: Dummy SSL error
            To connect to 'acme.com' insecurely, add the `-k` flag to enpkg command
        """)

        # When
        with use_given_config_context(self.config):
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    main(["dummy_requirement"])

        # Then
        self.assertMultiLineEqual(m.value, error_message)
示例#3
0
    def test_401_index_handling(self):
        self.maxDiff = None

        # Given
        repo = "http://acme.com/repo/ets/"
        config = Configuration()
        config.update(use_webservice=False, indexed_repositories=[repo])
        config.update(auth=("nono", "le petit robot"))
        config.write(self.config)

        url = repo + "index.json"
        responses.add(responses.HEAD, url, status=401)

        error_message = textwrap.dedent("""\
            Could not authenticate as 'nono' (server answered: 'Invalid credentials')
            Ensure your username and password are correct.

            You can change your authentication details with 'enpkg --userpass'.
        """)

        # When
        with use_given_config_context(self.config):
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    main(["dummy_requirement"])

        # Then
        self.assertMultiLineEqual(m.value, error_message)
示例#4
0
    def test_deprecated_get_auth(self):
        with mkdtemp() as d:
            f = os.path.join(d, "enstaller4rc")
            config = Configuration()
            config.set_auth(FAKE_USER, FAKE_PASSWORD)
            config.write(f)

            with mock.patch("enstaller.config.get_path", lambda: f):
                self.assertEqual(get_auth(), (FAKE_USER, FAKE_PASSWORD))
示例#5
0
    def test_simple_with_proxy(self):
        proxystr = "http://acme.com:3128"

        config = Configuration()
        config.proxy = proxystr
        config.write(self.f)

        config = Configuration.from_file(self.f)
        self.assertEqual(config.proxy, proxystr)
示例#6
0
    def test_simple_with_proxy(self):
        proxystr = "http://acme.com:3128"

        config = Configuration()
        config.update(proxy=proxystr)
        config.write(self.f)

        config = Configuration.from_file(self.f)
        self.assertEqual(str(config.proxy), proxystr)
        self.assertEqual(config.proxy_dict, {"http": proxystr})
示例#7
0
    def test_simple_with_proxy(self):
        proxystr = "http://acme.com:3128"

        config = Configuration()
        config.update(proxy=proxystr)
        config.write(self.f)

        config = Configuration.from_file(self.f)
        self.assertEqual(str(config.proxy), proxystr)
        self.assertEqual(config.proxy_dict, {"http": proxystr})
示例#8
0
    def test_no_config_file(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration()
        self.assertIsNone(config.auth)

        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config.write(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertEqual(new_config.auth, FAKE_AUTH)
示例#9
0
    def test_no_config_file(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration()
        self.assertIsNone(config.auth)

        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config.write(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertEqual(new_config.auth, FAKE_AUTH)
示例#10
0
    def test_no_config_file(self):
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            fp.write("")

        config = Configuration()
        self.assertEqual(config.get_auth(), (None, None))

        config.set_auth(FAKE_USER, FAKE_PASSWORD)
        config.write(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertEqual(new_config.get_auth(), (FAKE_USER, FAKE_PASSWORD))
示例#11
0
    def test_keyring_call(self):
        with mock.patch("__builtin__.open"):
            mocked_keyring = mock.MagicMock(["get_password", "set_password"])
            with mock.patch("enstaller.config.keyring", mocked_keyring):
                config = Configuration()
                config.set_auth(FAKE_USER, FAKE_PASSWORD)
                config.write("dummy_config.rc")

                r_args = ("Enthought.com", FAKE_USER, FAKE_PASSWORD)
                self.assertTrue(mocked_keyring.set_password.call_with(r_args))
                r_args = ("Enthought.com", FAKE_USER)
                self.assertTrue(mocked_keyring.get_password.call_with(r_args))
示例#12
0
    def test_simple(self):
        config = Configuration()
        config.set_auth(FAKE_USER, FAKE_PASSWORD)
        config.write(self.f)

        config = Configuration.from_file(self.f)

        self.assertEqual(config.EPD_auth, FAKE_CREDS)
        self.assertEqual(config.autoupdate, True)
        self.assertEqual(config.proxy, None)
        self.assertEqual(config.use_webservice, True)
        self.assertEqual(config.webservice_entry_point, get_default_url())
示例#13
0
    def test_change_store_url(self):
        config = Configuration()
        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config.write(self.f)

        config = Configuration.from_file(self.f)
        config.update(store_url="https://acme.com")

        self.assertEqual(config.auth._encoded_auth, FAKE_CREDS)
        self.assertEqual(config.autoupdate, True)
        self.assertEqual(config.proxy, None)
        self.assertEqual(config.use_webservice, True)
        self.assertEqual(config.webservice_entry_point,
                         "https://acme.com/eggs/{0}/".format(custom_plat))
        self.assertEqual(config.api_url,
                         "https://acme.com/accounts/user/info/")
示例#14
0
    def test_add_url(self):
        # Given
        path = os.path.join(self.d, "foo.cfg")

        config = Configuration()
        config.write(path)

        url = "http://acme.com/{PLATFORM}/"

        # When
        add_url(path, config, url)

        # Then
        with open(path, "r") as fp:
            data = fp.read()
            self.assertRegex(data, "http://acme.com")
示例#15
0
    def test_change_store_url(self):
        config = Configuration()
        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config.write(self.f)

        config = Configuration.from_file(self.f)
        config.update(store_url="https://acme.com")

        self.assertEqual(config.auth._encoded_auth, FAKE_CREDS)
        self.assertEqual(config.autoupdate, True)
        self.assertEqual(config.proxy, None)
        self.assertEqual(config.use_webservice, True)
        self.assertEqual(config.webservice_entry_point,
                         "https://acme.com/eggs/{0}/".format(custom_plat))
        self.assertEqual(config.api_url,
                         "https://acme.com/accounts/user/info/")
示例#16
0
    def test_add_url(self):
        # Given
        path = os.path.join(self.d, "foo.cfg")

        config = Configuration()
        config.write(path)

        url = "http://acme.com/{PLATFORM}/"

        # When
        add_url(path, config, url)

        # Then
        with open(path, "r") as fp:
            data = fp.read()
            self.assertRegex(data, "http://acme.com")