mirror of
https://codeberg.org/PGPainless/cert-d-java.git
synced 2024-11-24 00:12:05 +01:00
DatabaseSubkeyLookupFactory: Make database name configurable
This commit is contained in:
parent
27f4598437
commit
f382189638
2 changed files with 18 additions and 8 deletions
|
@ -16,9 +16,19 @@ import java.sql.SQLException;
|
|||
*/
|
||||
public class DatabaseSubkeyLookupFactory implements SubkeyLookupFactory {
|
||||
|
||||
private String databaseName;
|
||||
|
||||
public DatabaseSubkeyLookupFactory() {
|
||||
this("_pgpainless_subkey_map.db");
|
||||
}
|
||||
|
||||
public DatabaseSubkeyLookupFactory(String databaseName) {
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
||||
File databaseFile = new File(baseDirectory, "_pgpainless_subkey_map.db");
|
||||
File databaseFile = new File(baseDirectory, databaseName);
|
||||
SubkeyLookupDao dao;
|
||||
try {
|
||||
if (!databaseFile.exists()) {
|
||||
|
|
|
@ -22,15 +22,15 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
public class SqliteSubkeyLookupTest {
|
||||
|
||||
private File databaseFile;
|
||||
private File tempDir;
|
||||
private DatabaseSubkeyLookup lookup;
|
||||
|
||||
@BeforeEach
|
||||
public void setupLookup() throws IOException, SQLException {
|
||||
databaseFile = Files.createTempFile("pgp.cert.d-", "lookup.db").toFile();
|
||||
databaseFile.createNewFile();
|
||||
databaseFile.deleteOnExit();
|
||||
lookup = new DatabaseSubkeyLookup(SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile));
|
||||
public void setupLookup() throws IOException {
|
||||
tempDir = Files.createTempDirectory("pgp.cert.d").toFile();
|
||||
tempDir.deleteOnExit();
|
||||
lookup = (DatabaseSubkeyLookup) new DatabaseSubkeyLookupFactory()
|
||||
.createFileBasedInstance(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -55,7 +55,7 @@ public class SqliteSubkeyLookupTest {
|
|||
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificateFingerprintsForSubkeyId(1337));
|
||||
|
||||
// do the lookup using a second db instance on the same file
|
||||
DatabaseSubkeyLookup secondInstance = new DatabaseSubkeyLookup(SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile));
|
||||
DatabaseSubkeyLookup secondInstance = (DatabaseSubkeyLookup) new DatabaseSubkeyLookupFactory().createFileBasedInstance(tempDir);
|
||||
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), secondInstance.getCertificateFingerprintsForSubkeyId(1337));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue