mirror of
https://codeberg.org/PGPainless/cert-d-java.git
synced 2024-11-25 00:42:06 +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 {
|
public class DatabaseSubkeyLookupFactory implements SubkeyLookupFactory {
|
||||||
|
|
||||||
|
private String databaseName;
|
||||||
|
|
||||||
|
public DatabaseSubkeyLookupFactory() {
|
||||||
|
this("_pgpainless_subkey_map.db");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseSubkeyLookupFactory(String databaseName) {
|
||||||
|
this.databaseName = databaseName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
public SubkeyLookup createFileBasedInstance(File baseDirectory) {
|
||||||
File databaseFile = new File(baseDirectory, "_pgpainless_subkey_map.db");
|
File databaseFile = new File(baseDirectory, databaseName);
|
||||||
SubkeyLookupDao dao;
|
SubkeyLookupDao dao;
|
||||||
try {
|
try {
|
||||||
if (!databaseFile.exists()) {
|
if (!databaseFile.exists()) {
|
||||||
|
|
|
@ -22,15 +22,15 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class SqliteSubkeyLookupTest {
|
public class SqliteSubkeyLookupTest {
|
||||||
|
|
||||||
private File databaseFile;
|
private File tempDir;
|
||||||
private DatabaseSubkeyLookup lookup;
|
private DatabaseSubkeyLookup lookup;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setupLookup() throws IOException, SQLException {
|
public void setupLookup() throws IOException {
|
||||||
databaseFile = Files.createTempFile("pgp.cert.d-", "lookup.db").toFile();
|
tempDir = Files.createTempDirectory("pgp.cert.d").toFile();
|
||||||
databaseFile.createNewFile();
|
tempDir.deleteOnExit();
|
||||||
databaseFile.deleteOnExit();
|
lookup = (DatabaseSubkeyLookup) new DatabaseSubkeyLookupFactory()
|
||||||
lookup = new DatabaseSubkeyLookup(SqliteSubkeyLookupDaoImpl.forDatabaseFile(databaseFile));
|
.createFileBasedInstance(tempDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,7 +55,7 @@ public class SqliteSubkeyLookupTest {
|
||||||
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificateFingerprintsForSubkeyId(1337));
|
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), lookup.getCertificateFingerprintsForSubkeyId(1337));
|
||||||
|
|
||||||
// do the lookup using a second db instance on the same file
|
// 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));
|
assertEquals(Collections.singleton("eb85bb5fa33a75e15e944e63f231550c4f47e38e"), secondInstance.getCertificateFingerprintsForSubkeyId(1337));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue