Skip to content

Commit

Permalink
close connection after use
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Nov 13, 2023
1 parent 279f66f commit 3716ab6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Map<String, String> getConfigOverrides() {
@Test
@DisplayName("GET /billing returns 401 with empty license managed instance")
public void testGetEmptyManagedInstance() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
UPDATE "settings"
SET "hub_id" = '42', "license_key" = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testGetNonExistingDeviceToken() {
@Order(2)
@DisplayName("PUT /devices/device999 returns 201 (creating new device)")
public void testCreate999() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
INSERT INTO "device_legacy" ("id", "owner_id", "name", "type", "publickey", "creation_time")
VALUES
Expand All @@ -112,7 +112,7 @@ public void testCreate999() throws SQLException {
.when().put("/devices/{deviceId}", "device999")
.then().statusCode(201);

try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
var rs = s.executeQuery("""
SELECT * FROM "device_legacy" WHERE "id" = 'device999';
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public class GrantAccess {
@Test
@DisplayName("POST /vaults/7E57C0DE-0000-4000-8000-000100001111/access-tokens returns 404 for [user998, user999, user666]")
public void testGrantAccess0() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
INSERT INTO "authority" ("id", "type", "name") VALUES ('user998', 'USER', 'User 998');
INSERT INTO "authority" ("id", "type", "name") VALUES ('user999', 'USER', 'User 999');
Expand All @@ -329,7 +329,7 @@ public void testGrantAccess0() throws SQLException {
.when().post("/vaults/{vaultId}/access-tokens/", "7E57C0DE-0000-4000-8000-000100001111")
.then().statusCode(404);

try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
DELETE FROM "authority" WHERE "id" = 'user998';
DELETE FROM "authority" WHERE "id" = 'user999';
Expand All @@ -340,7 +340,7 @@ public void testGrantAccess0() throws SQLException {
@Test
@DisplayName("POST /vaults/7E57C0DE-0000-4000-8000-000100001111/access-tokens returns 200 for [user998, user999]")
public void testGrantAccess1() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
INSERT INTO "authority" ("id", "type", "name") VALUES ('user998', 'USER', 'User 998');
INSERT INTO "authority" ("id", "type", "name") VALUES ('user999', 'USER', 'User 999');
Expand All @@ -355,7 +355,7 @@ public void testGrantAccess1() throws SQLException {
.when().post("/vaults/{vaultId}/access-tokens/", "7E57C0DE-0000-4000-8000-000100001111")
.then().statusCode(200);

try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
DELETE FROM "authority" WHERE "id" = 'user998';
DELETE FROM "authority" WHERE "id" = 'user999';
Expand Down Expand Up @@ -451,7 +451,7 @@ public void getMembersOfVault1() {
@Order(5)
@DisplayName("GET /vaults/7E57C0DE-0000-4000-8000-000100002222/users-requiring-access-grant does contains user2 via group membership")
public void testGetUsersRequiringAccess1() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
UPDATE
"user_details" SET publickey='public2', privatekey='private2', setupcode='setup2'
Expand All @@ -463,7 +463,7 @@ public void testGetUsersRequiringAccess1() throws SQLException {
.then().statusCode(200)
.body("id", hasItems("user2"));

try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
UPDATE
"user_details" SET publickey=NULL, privatekey=NULL, setupcode=NULL
Expand Down Expand Up @@ -493,7 +493,7 @@ public void getMembersOfVault2b() {
@Order(10)
@DisplayName("GET /vaults/7E57C0DE-0000-4000-8000-000100002222/users-requiring-access-grant contains user2")
public void testGetUsersRequiringAccess2() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
UPDATE
"user_details" SET publickey='public2', privatekey='private2', setupcode='setup2'
Expand All @@ -505,7 +505,7 @@ public void testGetUsersRequiringAccess2() throws SQLException {
.then().statusCode(200)
.body("id", hasItems("user2"));

try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
UPDATE
"user_details" SET publickey=NULL, privatekey=NULL, setupcode=NULL
Expand Down Expand Up @@ -562,7 +562,7 @@ public class ManageAccessAsUser1 {

@BeforeAll
public void setup() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
// user999 will be deleted in #cleanup()
s.execute("""
INSERT INTO "authority" ("id", "type", "name") VALUES ('user999', 'USER', 'User 999');
Expand Down Expand Up @@ -651,7 +651,7 @@ public void getMembersOfVault1b() {

@AfterAll
public void cleanup() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
DELETE FROM "authority" WHERE ID = 'user999';
""");
Expand All @@ -673,7 +673,7 @@ public class ExceedingLicenseLimits {
@BeforeAll
public void setup() throws SQLException {
//Assumptions.assumeTrue(EffectiveVaultAccess.countEffectiveVaultUsers() == 2);
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
INSERT INTO "authority" ("id", "type", "name")
VALUES
Expand Down Expand Up @@ -797,7 +797,7 @@ public void testUpdateVaultDespiteLicenseExceeded() {
@Order(7)
@DisplayName("Unlock is blocked if exceeding license seats")
public void testUnlockBlockedIfLicenseExceeded() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
INSERT INTO "vault_access" ("vault_id", "authority_id")
VALUES ('7E57C0DE-0000-4000-8000-000100001111', 'group91');
Expand All @@ -811,7 +811,7 @@ public void testUnlockBlockedIfLicenseExceeded() throws SQLException {

@AfterAll
public void reset() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
DELETE FROM "authority"
WHERE "id" IN ('user91', 'user92', 'user93', 'user94', 'user95_A', 'group91');
Expand Down Expand Up @@ -1014,7 +1014,7 @@ public void testClaimOwnershipAlreadyClaimed() {

@AfterAll
public void reset() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
s.execute("""
DELETE FROM "vault" WHERE "id" = '7E57C0DE-0000-4000-8000-000100009999';
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public class EntityIntegrationTest {
@TestTransaction
@DisplayName("Removing a User cascades to Access")
public void removingUserCascadesToAccess() throws SQLException {
try (var s = dataSource.getConnection().createStatement()) {
try (var c = dataSource.getConnection(); var s = c.createStatement()) {
// test data will be removed via @TestTransaction
s.execute("""
INSERT INTO "authority" ("id", "type", "name") VALUES ('user999', 'USER', 'User 999');
INSERT INTO "user_details" ("id") VALUES ('user999');
INSERT INTO "access_token" ("user_id", "vault_id", "vault_masterkey") VALUES ('user999', '7E57C0DE-0000-4000-8000-000100001111', 'jwe4');
INSERT INTO "access_token" ("user_id", "vault_id", "vault_masterkey") VALUES ('user999', '7E57C0DE-0000-4000-8000-000100001111', 'jwe.jwe.jwe.vault1.user999');
""");
}

Expand Down

0 comments on commit 3716ab6

Please sign in to comment.