com.github.mike10004.seleniumhelp.FirefoxCookieDb Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-capture Show documentation
Show all versions of selenium-capture Show documentation
Capture HTTP traffic generated by Selenium WebDriver in Java
package com.github.mike10004.seleniumhelp;
import io.github.mike10004.subprocess.ProcessResult;
import io.github.mike10004.subprocess.Subprocess;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Converter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@SuppressWarnings({"Convert2Lambda"})
public class FirefoxCookieDb {
private FirefoxCookieDb() {}
static final ImmutableList SQLITE_COLUMN_NAMES = ImmutableList.of(
"id",
"baseDomain",
"originAttributes",
"name",
"value",
"host",
"path",
"expiry",
"lastAccessed",
"creationTime",
"isSecure",
"isHttpOnly",
"appId",
"inBrowserElement");
@VisibleForTesting
static final String TABLE_NAME = "moz_cookies";
public static class CookieTransferConfig extends ExecutableConfig.BasicExecutableConfig {
private static final String SQLITE3_EXECUTABLE_NAME = "sqlite3";
public CookieTransferConfig(@Nullable File executablePathname, String executableFilename) {
super(executablePathname, executableFilename);
}
@SuppressWarnings("unused")
public static CookieTransferConfig forSqlite3Executable(File executable) {
return new CookieTransferConfig(executable, SQLITE3_EXECUTABLE_NAME);
}
public static CookieTransferConfig createDefault() {
return new CookieTransferConfig(null, SQLITE3_EXECUTABLE_NAME);
}
}
public static Importer getImporter() {
return getImporter(CookieTransferConfig.createDefault());
}
public static Exporter getExporter() {
return getExporter(CookieTransferConfig.createDefault());
}
public static Importer getImporter(CookieTransferConfig config) {
return new Sqlite3ProgramImporter(config);
}
public static Exporter getExporter(CookieTransferConfig config) {
return new Sqlite3ProgramExporter(config);
}
public interface Exporter {
List exportCookies(File sqliteDbFile) throws SQLException, IOException;
}
public interface Importer {
void importCookies(Iterable cookies, File sqliteDbFile, Path scratchDir) throws SQLException, IOException;
}
@VisibleForTesting
static class Sqlite3ProgramExporter extends Sqlite3Runner.Sqlite3GenericExporter implements Exporter {
private static final Logger log = LoggerFactory.getLogger(Sqlite3ProgramExporter.class);
public Sqlite3ProgramExporter(CookieTransferConfig config) {
super(config);
}
public List exportCookies(File sqliteDbFile) throws SQLException, IOException {
log.debug("cookies going to {}", sqliteDbFile);
List