async def test_change_specify_folder_setting_with_manual_creds(
        reader: ReaderHelper, server: SimulationServer, session,
        coord: Coordinator, folder_finder: FolderFinder, drive: DriveSource,
        config):
    server.resetDriveAuth()
    # Generate manual credentials
    req_path = "manualauth?client_id={}&client_secret={}".format(
        server.custom_drive_client_id, server.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 = URL(resp.headers["location"]).query["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'
    }
    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'
    }
    assert folder_finder.getCachedFolder() == "12345"
async def test_cred_refresh_with_secret(drive: DriveSource, server: SimulationServer, time: FakeTime, config: Config):
    server.resetDriveAuth()
    with open(config.get(Setting.CREDENTIALS_FILE_PATH), "w") as f:
        creds = server.getCurrentCreds()
        creds._secret = config.get(Setting.DEFAULT_DRIVE_CLIENT_SECRET)
        json.dump(creds.serialize(), f)
    drive.drivebackend.tryLoadCredentials()
    await drive.get()
    old_creds = drive.drivebackend.creds

    # valid creds should be reused
    await drive.get()
    assert old_creds.access_token == drive.drivebackend.creds.access_token

    # then refreshed when they expire
    time.advanceDay()
    await drive.get()
    assert old_creds.access_token != drive.drivebackend.creds.access_token

    # verify the client_secret is kept
    with open(config.get(Setting.CREDENTIALS_FILE_PATH)) as f:
        assert "client_secret" in json.load(f)