Compare commits

..

No commits in common. "d5f8f8448027411e1089e36028970ec2716b3300" and "1d65984323e5da02c8aa1dcb5bd385868e54cb33" have entirely different histories.

4 changed files with 8 additions and 31 deletions

View file

@ -27,11 +27,3 @@ pipeline:
- apk add sqlite sqlite-dev libpq libpq-dev - apk add sqlite sqlite-dev libpq libpq-dev
- echo "Running unit tests..." - echo "Running unit tests..."
- ./zig-linux-x86_64-0.10.0/zig build unit - ./zig-linux-x86_64-0.10.0/zig build unit
integration-tests:
image: alpine
commands:
- echo "Downloading dependencies..."
- apk add sqlite sqlite-dev libpq libpq-dev
- echo "Running integration tests..."
- ./zig-linux-x86_64-0.10.0/zig build integration-tests

View file

@ -322,7 +322,6 @@ fn ApiConn(comptime DbConn: type) type {
pub fn close(self: *Self) void { pub fn close(self: *Self) void {
util.deepFree(self.allocator, self.community); util.deepFree(self.allocator, self.community);
if (self.token_info) |info| util.deepFree(self.allocator, info);
self.db.releaseConnection(); self.db.releaseConnection();
} }
@ -354,14 +353,11 @@ fn ApiConn(comptime DbConn: type) type {
const user = try services.actors.get(self.db, info.user_id, self.allocator); const user = try services.actors.get(self.db, info.user_id, self.allocator);
defer util.deepFree(self.allocator, user); defer util.deepFree(self.allocator, user);
const username = try util.deepClone(self.allocator, user.username);
errdefer util.deepFree(self.allocator, username);
return AuthorizationInfo{ return AuthorizationInfo{
.id = user.id, .id = user.id,
.username = username, .username = try util.deepClone(self.allocator, user.username),
.community_id = self.community.id, .community_id = self.community.id,
.host = try util.deepClone(self.allocator, self.community.host), .host = self.community.host,
.issued_at = info.issued_at, .issued_at = info.issued_at,
}; };

View file

@ -104,7 +104,7 @@ pub fn login(
error.NoRows => error.InvalidLogin, error.NoRows => error.InvalidLogin,
else => error.DatabaseFailure, else => error.DatabaseFailure,
}; };
defer alloc.free(info.hash); errdefer util.deepFree(alloc, info);
try verifyPassword(info.hash, password, alloc); try verifyPassword(info.hash, password, alloc);
@ -162,7 +162,6 @@ pub fn verifyToken(
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
) VerifyTokenError!TokenInfo { ) VerifyTokenError!TokenInfo {
const hash = try hashToken(token, alloc); const hash = try hashToken(token, alloc);
defer alloc.free(hash);
return db.queryRow( return db.queryRow(
TokenInfo, TokenInfo,

View file

@ -39,9 +39,7 @@ fn connectAndLogin(
var conn = try api_source.connectUnauthorized(host, alloc); var conn = try api_source.connectUnauthorized(host, alloc);
defer conn.close(); defer conn.close();
const result = try conn.login(username, password); return try util.deepClone(alloc, try conn.login(username, password));
defer util.deepFree(conn.allocator, result);
return try util.deepClone(alloc, result);
} }
test "login as root" { test "login as root" {
@ -56,7 +54,6 @@ test "login as root" {
var conn = try src.connectToken(admin_host, login.token, alloc); var conn = try src.connectToken(admin_host, login.token, alloc);
defer conn.close(); defer conn.close();
const auth = try conn.verifyAuthorization(); const auth = try conn.verifyAuthorization();
defer util.deepFree(conn.allocator, auth);
try std.testing.expectEqual(login.user_id, auth.id); try std.testing.expectEqual(login.user_id, auth.id);
try std.testing.expectEqualStrings(root_user, auth.username); try std.testing.expectEqualStrings(root_user, auth.username);
@ -76,8 +73,7 @@ test "create community" {
defer conn.close(); defer conn.close();
const host = "fedi.example.com"; const host = "fedi.example.com";
const community = try conn.createCommunity("https://" ++ host, null); const community = try conn.createCommunity("https://" ++ host);
defer util.deepFree(alloc, community);
try std.testing.expectEqual(api.Community.Scheme.https, community.scheme); try std.testing.expectEqual(api.Community.Scheme.https, community.scheme);
try std.testing.expectEqual(api.Community.Kind.local, community.kind); try std.testing.expectEqual(api.Community.Kind.local, community.kind);
@ -87,10 +83,7 @@ test "create community" {
} }
test "create community and transfer to new owner" { test "create community and transfer to new owner" {
//const alloc = std.testing.allocator; const alloc = std.testing.allocator;
var gpa = std.heap.GeneralPurposeAllocator(.{ .stack_trace_frames = 16 }){};
defer _ = gpa.deinit();
const alloc = gpa.allocator();
var db = try makeDb(alloc); var db = try makeDb(alloc);
defer db.deinit(); defer db.deinit();
var src = try ApiSource.init(&db); var src = try ApiSource.init(&db);
@ -103,10 +96,8 @@ test "create community and transfer to new owner" {
var conn = try src.connectToken(admin_host, root_login.token, alloc); var conn = try src.connectToken(admin_host, root_login.token, alloc);
defer conn.close(); defer conn.close();
const community = try conn.createCommunity("https://" ++ host, null); const community = try conn.createCommunity("https://" ++ host);
defer util.deepFree(conn.allocator, community);
const invite = try conn.createInvite(.{ .to_community = community.id, .kind = .community_owner }); const invite = try conn.createInvite(.{ .to_community = community.id, .kind = .community_owner });
defer util.deepFree(conn.allocator, invite);
break :blk try util.deepClone(alloc, invite); break :blk try util.deepClone(alloc, invite);
}; };
defer util.deepFree(alloc, invite); defer util.deepFree(alloc, invite);
@ -117,7 +108,7 @@ test "create community and transfer to new owner" {
var conn = try src.connectUnauthorized(host, alloc); var conn = try src.connectUnauthorized(host, alloc);
defer conn.close(); defer conn.close();
util.deepFree(conn.allocator, try conn.register(username, password, .{ .invite_code = invite.code })); _ = try conn.register(username, password, .{ .invite_code = invite.code });
} }
const login = try connectAndLogin(&src, host, username, password, alloc); const login = try connectAndLogin(&src, host, username, password, alloc);
@ -127,7 +118,6 @@ test "create community and transfer to new owner" {
defer conn.close(); defer conn.close();
const auth = try conn.verifyAuthorization(); const auth = try conn.verifyAuthorization();
defer util.deepFree(conn.allocator, auth);
try std.testing.expectEqual(login.user_id, auth.id); try std.testing.expectEqual(login.user_id, auth.id);
try std.testing.expectEqualStrings(username, auth.username); try std.testing.expectEqualStrings(username, auth.username);