Exemplo n.º 1
0
    def test_enstaller_userpass_upgrade(self):
        """ Username and password should be taken out of .enstaller4rc
        and stored in a keyring.
        """
        config.get_auth()
        config_contents = open(config.home_config_path).read()
        return # XXX
        self.assertTrue('EPD_auth' not in config_contents)
        username, password = config.get_auth()
        self.assertEqual(username, 'foo')
        self.assertEqual(password, 'bar')

        config.clear_auth()
        config_contents = open(config.home_config_path).read()
        self.assertTrue('EPD_username' not in config_contents)
        self.assertEqual(config.get_auth(), (None, None))
Exemplo n.º 2
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))
Exemplo n.º 3
0
    def test_enstaller_userpass_new_config(self):
        """ Username and password should be stored in a keyring for
        brand-new config files, too
        """
        config.home_config_path = self.base_cfg + '.new'
        if isfile(config.home_config_path):
            os.unlink(config.home_config_path)
        config.clear_cache()

        config.change_auth('foo', 'bar')
        config_contents = open(config.home_config_path).read()
        return # XXX
        self.assertTrue('EPD_auth' not in config_contents)
        self.assertEqual(config.get_auth(), ('foo', 'bar'))

        config.clear_auth()
        self.assertEqual(config.get_auth(), (None, None))
        config.change_auth('foo', 'bar')
        self.assertEqual(config.get_auth(), ('foo', 'bar'))
Exemplo n.º 4
0
    def test_enstaller_userpass_no_keyring(self):
        """ When the keyring module isn't available, username and
        password should be stored in the old method
        """
        keyring = config.keyring
        config.keyring = None
        try:
            config.get_auth()
            config_contents = open(config.home_config_path).read()
            self.assertTrue("EPD_auth = 'Zm9vOmJhcg=='" in config_contents)

            config.change_auth('bar', 'foo')
            config_contents = open(config.home_config_path).read()
            self.assertTrue("EPD_auth = 'YmFyOmZvbw=='" in config_contents)

            config.clear_auth()
            config_contents = open(config.home_config_path).read()
            self.assertTrue("EPD_auth" not in config_contents)
            self.assertEqual(config.get_auth(), (None, None))

            config.change_auth('foo', 'bar')
            self.assertEqual(config.get_auth(), ('foo', 'bar'))
        finally:
            config.keyring = keyring
Exemplo n.º 5
0
 def _check_auth():
     """
     Check the user's credentials against the web API.
     """
     user = {}
     try:
         user = config.authenticate(config.get_auth())
         assert(user['is_authenticated'])
         # An EPD Free user who is trying to install a package not in
         # EPD free.  Print out subscription level and fail.
         print config.subscription_message(user)
         _done(FAILURE)
     except Exception as e:
         print e.message
         # No credentials.
         print ""
         _prompt_for_auth()
Exemplo n.º 6
0
def search(enpkg, pat=None):
    """
    Print the packages that are available in the (remote) KVS.
    """
    # Flag indicating if the user received any 'not subscribed to'
    # messages
    SUBSCRIBED = True

    print FMT4 % ('Name', '  Versions', 'Product', 'Note')
    print 80 * '='

    names = {}
    for key, info in enpkg.query_remote():
        names[info['name']] = name_egg(key)

    installed = {}
    for key, info in enpkg.query_installed():
        installed[info['name']] = VB_FMT % info

    for name in sorted(names, key=string.lower):
        if pat and not pat.search(name):
            continue
        disp_name = names[name]
        installed_version = installed.get(name)
        for info in enpkg.info_list_name(name):
            version = VB_FMT % info
            disp_ver = (('* ' if installed_version == version else '  ') +
                        version)
            available = info.get('available', True)
            product = info.get('product', '')
            if not(available):
                SUBSCRIBED = False
            print FMT4 % (disp_name, disp_ver, product,
                   '' if available else 'not subscribed to')
            disp_name = ''

    # if the user's search returns any packages that are not available
    # to them, attempt to authenticate and print out their subscriber
    # level
    if config.get('use_webservice') and not(SUBSCRIBED):
        user = {}
        try:
            user = config.authenticate(config.get_auth())
        except Exception as e:
            print e.message
        print config.subscription_message(user)
Exemplo n.º 7
0
    def test_enstaller_userpass_no_keyring_new_config(self):
        """ Username and password should be stored properly in a new
        config file, even with no keyring module
        """
        config.home_config_path = self.base_cfg + '.new'
        if isfile(config.home_config_path):
            os.unlink(config.home_config_path)
        config.clear_cache()

        keyring = config.keyring
        config.keyring = None
        try:
            config.change_auth('foo', 'bar')
            config_contents = open(config.home_config_path).read()
            self.assertTrue("EPD_auth = 'Zm9vOmJhcg=='" in config_contents)
            self.assertEqual(config.get_auth(), ('foo', 'bar'))
        finally:
            config.keyring = keyring
Exemplo n.º 8
0
 def test_without_existing_configuration(self):
     with mock.patch("enstaller.config.get_path", lambda: None):
         with self.assertRaises(InvalidConfiguration):
             get_auth()