Ejemplo n.º 1
0
async def test_manual_creds(reader: ReaderHelper, ui_server: UiServer, config: Config, server, session, drive: DriveSource):
    # get the auth url
    req_path = "manualauth?client_id={}&client_secret={}".format(config.get(
        Setting.DEFAULT_DRIVE_CLIENT_ID), config.get(Setting.DEFAULT_DRIVE_CLIENT_SECRET))
    data = await reader.getjson(req_path)
    assert "auth_url" in data

    # request the auth code from "google"
    async with session.get(data["auth_url"], allow_redirects=False) as resp:
        code = (await resp.json())["code"]

    drive.saveCreds(None)
    assert not drive.enabled()
    # Pass the auth code to generate creds
    req_path = "manualauth?code={}".format(code)
    assert await reader.getjson(req_path) == {
        'auth_url': "index?fresh=true"
    }

    # verify creds are saved and drive is enabled
    assert drive.enabled()

    # Now verify that bad creds fail predictably
    req_path = "manualauth?code=bad_code"
    assert await reader.getjson(req_path) == {
        'error': 'Your Google Drive credentials have expired.  Please reauthorize with Google Drive through the Web UI.'
    }
async def test_cred_refresh_no_secret(drive: DriveSource, server: SimulationServer, time: FakeTime, config: Config):
    drive.saveCreds(server.getCurrentCreds())
    await drive.get()
    old_creds = drive.drivebackend.creds
    await drive.get()
    assert old_creds.access_token == drive.drivebackend.creds.access_token
    time.advanceDay()
    await drive.get()
    assert old_creds.access_token != drive.drivebackend.creds.access_token
    with open(config.get(Setting.CREDENTIALS_FILE_PATH)) as f:
        assert "client_secret" not in json.load(f)
async def test_change_specify_folder_setting_with_manual_creds(
        reader: ReaderHelper, google, session, coord: Coordinator,
        folder_finder: FolderFinder, drive: DriveSource, config):
    google.resetDriveAuth()
    # Generate manual credentials
    req_path = "manualauth?client_id={}&client_secret={}".format(
        google._custom_drive_client_id, google._custom_drive_client_secret)
    data = await reader.getjson(req_path)
    assert "auth_url" in data
    async with session.get(data["auth_url"], allow_redirects=False) as resp:
        code = (await resp.json())["code"]
    drive.saveCreds(None)
    assert not drive.enabled()
    req_path = "manualauth?code={}".format(code)
    await reader.getjson(req_path)
    assert drive.isCustomCreds()

    await coord.sync()
    assert folder_finder.getCachedFolder() is not None

    # Specify the snapshot folder, which should cache the new one
    update = {
        "config": {
            Setting.SPECIFY_SNAPSHOT_FOLDER.value: True
        },
        "snapshot_folder": "12345"
    }
    assert await reader.postjson("saveconfig", json=update) == {
        'message': 'Settings saved',
        "reload_page": False
    }
    assert folder_finder.getCachedFolder() == "12345"

    # Un change the folder, which should keep the existing folder
    update = {
        "config": {
            Setting.SPECIFY_SNAPSHOT_FOLDER.value: False
        },
        "snapshot_folder": ""
    }
    assert await reader.postjson("saveconfig", json=update) == {
        'message': 'Settings saved',
        "reload_page": False
    }
    assert folder_finder.getCachedFolder() == "12345"
Ejemplo n.º 4
0
async def test_check_time(drive: DriveSource, drive_creds: Creds):
    assert not drive.check()
    drive.saveCreds(drive_creds)
    assert drive.check()