Esempio n. 1
0
def test_clear_entire_provider():
    cm = CredentialManager()
    cm.load()
    cm.set_user_credentials(DropboxProvider, "foo", 0)
    cm.set_user_credentials(DropboxProvider, "bar", 1)
    cm.clear_user_credentials(DropboxProvider)

    cm.load()
    assert cm.get_user_credentials(DropboxProvider) == {}
Esempio n. 2
0
def test_roundtrip_user():
    cm = CredentialManager()
    cm.load()
    foo_creds = {"a": 1}
    bar_creds = "a_string"
    cm.set_user_credentials(DropboxProvider, "foo", foo_creds)
    cm.set_user_credentials(DropboxProvider, "bar", bar_creds)

    cm.load()
    assert cm.get_user_credentials(DropboxProvider) == {"foo": foo_creds, "bar": bar_creds}

    cm.clear_user_credentials(DropboxProvider, "foo")
    cm.load()
    assert cm.get_user_credentials(DropboxProvider) == {"bar": bar_creds}

    cm.clear_user_credentials(DropboxProvider, "bar")

    cm.load()
    assert cm.get_user_credentials(DropboxProvider) == {}
Esempio n. 3
0
def main(args):
    provider_manager = ProviderManager()
    cm = CredentialManager()
    cm.load()

    providers, errors = provider_manager.load_all_providers_from_credentials()

    def wipe(provider):
        try:
            provider.wipe()
        except Exception:
            print "failed to wipe provider: " + provider.provider_name()

    run_parallel(wipe, map(lambda provider: [provider], providers))

    behavior = args[0]
    cm.clear_user_credentials(provider_class=None,
                              account_identifier=None)  # clear the file

    if behavior == "setup":
        # copy in default credentials (Dropbox, GoogleDrive, OneDrive)
        default_credentials = os.path.join(cm.config_dir,
                                           "default_credentials.json")
        current_credentials = os.path.join(cm.config_dir,
                                           "user_credentials.json")
        try:
            copyfile(default_credentials, current_credentials)
        except IOError:
            print "credential reset to setup state failed, see default_credentials.json"

        if len(args) == 2:  # write credentials for the demo server
            cm.load()  # reload the credential manager with updated store

            ip_block = args[1]
            url = ''.join("http://158.130.108." + ip_block + ":5000")
            demo_server = TestServerProvider(cm)

            try:
                demo_server.connect(url)
            except exceptions.ConnectionFailure:
                print "please start a demo server at: " + url
Esempio n. 4
0
def test_get_not_exists():
    cm = CredentialManager()
    cm.load()
    cm.clear_user_credentials(DropboxProvider)
    assert cm.get_app_credentials(TestProvider) is None
    assert cm.get_user_credentials(DropboxProvider) == {}