示例#1
0
    def test_same_app_different_servers(self):
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        keyring = InMemoryKeyring()
        # Be paranoid about the keyring starting out empty.
        assert not keyring.data, 'oops, a fresh keyring has data in it'
        with fake_keyring(keyring):
            # Create stored credentials for the same application but against
            # two different sites (service roots).
            NoNetworkLaunchpad.login_with(
                'application name', service_root='http://alpha.example.com/',
                launchpadlib_dir=launchpadlib_dir)
            NoNetworkLaunchpad.login_with(
                'application name', service_root='http://beta.example.com/',
                launchpadlib_dir=launchpadlib_dir)

        # There should only be two sets of stored credentials (this assertion
        # is of the test mechanism, not a test assertion).
        assert len(keyring.data.keys()) == 2

        application_key_1 = keyring.data.keys()[0][1]
        application_key_2 = keyring.data.keys()[1][1]
        self.assertNotEqual(application_key_1, application_key_2)
示例#2
0
    def test_components_of_application_key(self):
        launchpadlib_dir = os.path.join(self.temp_dir, 'launchpadlib')
        keyring = InMemoryKeyring()
        service_root = 'http://api.example.com/'
        application_name = 'Super App 3000'
        with fake_keyring(keyring):
            launchpad = NoNetworkLaunchpad.login_with(
                application_name, service_root=service_root,
                launchpadlib_dir=launchpadlib_dir)
            consumer_name = launchpad.credentials.consumer.key

        application_key = keyring.data.keys()[0][1]

        # Both the consumer name (normally the name of the application) and
        # the service root (the URL of the service being accessed) are
        # included in the key when storing credentials.
        self.assert_(service_root in application_key)
        self.assert_(consumer_name in application_key)

        # The key used to store the credentials is of this structure (and
        # shouldn't change between releases or stored credentials will be
        # "forgotten").
        self.assertEquals(application_key, consumer_name + '@' + service_root)
示例#3
0
 def setUp(self):
     self.keyring = InMemoryKeyring()
     self.store = KeyringCredentialStore()
示例#4
0
 def setUp(self):
     # The real keyring package should never be imported during tests.
     assert_keyring_not_imported()
     # For these tests we want to use a dummy keyring implementation
     # that only stores data in memory.
     launchpadlib.credentials.keyring = InMemoryKeyring()