Version 1.0.1-SNAPSHOT - fixed issue with requesting pubkey, and problem where your keys are overwritten if you try to import a contact again or worse, your identity as a contact

This commit is contained in:
2016-01-31 18:11:20 +01:00
parent 3103ae6edd
commit 5f4dbfc985
6 changed files with 40 additions and 14 deletions

View File

@ -152,13 +152,25 @@ public class JdbcAddressRepository extends JdbcHelper implements AddressReposito
private void update(BitmessageAddress address) throws IOException, SQLException {
try (Connection connection = config.getConnection()) {
PreparedStatement ps = connection.prepareStatement(
"UPDATE Address SET alias=?, public_key=?, private_key=?, subscribed=? WHERE address=?");
ps.setString(1, address.getAlias());
writePubkey(ps, 2, address.getPubkey());
writeBlob(ps, 3, address.getPrivateKey());
ps.setBoolean(4, address.isSubscribed());
ps.setString(5, address.getAddress());
StringBuilder statement = new StringBuilder("UPDATE Address SET alias=?");
if (address.getPubkey() != null) {
statement.append(", public_key=?");
}
if (address.getPrivateKey() != null) {
statement.append(", private_key=?");
}
statement.append(", subscribed=? WHERE address=?");
PreparedStatement ps = connection.prepareStatement(statement.toString());
int i = 0;
ps.setString(++i, address.getAlias());
if (address.getPubkey() != null) {
writePubkey(ps, ++i, address.getPubkey());
}
if (address.getPrivateKey() != null) {
writeBlob(ps, ++i, address.getPrivateKey());
}
ps.setBoolean(++i, address.isSubscribed());
ps.setString(++i, address.getAddress());
ps.executeUpdate();
}
}

View File

@ -128,6 +128,17 @@ public class JdbcAddressRepositoryTest extends TestBase {
assertEquals("Test-Alias", address.getAlias());
}
@Test
public void ensureExistingKeysAreNotDeleted() {
BitmessageAddress address = new BitmessageAddress(IDENTITY_A);
address.setAlias("Test");
repo.save(address);
BitmessageAddress identityA = repo.getAddress(IDENTITY_A);
assertNotNull(identityA.getPubkey());
assertNotNull(identityA.getPrivateKey());
assertEquals("Test", identityA.getAlias());
}
@Test
public void testRemove() throws Exception {
BitmessageAddress address = repo.getAddress(IDENTITY_A);