Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/src/schemas/validation.schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod';
import { MarketCategory } from '@prisma/client';
import { stellarService } from '../services/stellar.service.js';

// --- Sanitization helper ---

Expand Down Expand Up @@ -33,7 +34,9 @@ export function sanitizedString(min: number, max: number) {

export const stellarAddress = z
.string()
.regex(/^G[A-Z0-9]{55}$/, 'Invalid Stellar public key');
.refine((val) => stellarService.isValidPublicKey(val), {
message: 'Invalid Stellar public key format or checksum',
});

export const uuidParam = z.object({
id: z.string().uuid(),
Expand Down
34 changes: 17 additions & 17 deletions backend/tests/auth.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Auth Integration Tests', () => {
it('should decode valid access token', () => {
const payload = {
userId: 'user-123',
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
tier: 'EXPERT' as const,
};

Expand All @@ -154,7 +154,7 @@ describe('Auth Integration Tests', () => {
it('should reject tampered token', () => {
const token = signAccessToken({
userId: 'user-123',
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
tier: 'BEGINNER',
});

Expand All @@ -170,7 +170,7 @@ describe('Auth Integration Tests', () => {
const sessionData = {
userId: 'user-123',
tokenId: 'token-456',
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand All @@ -187,15 +187,15 @@ describe('Auth Integration Tests', () => {
const oldSession = {
userId: 'user-123',
tokenId: 'old-token',
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};

const newSession = {
userId: 'user-123',
tokenId: 'new-token',
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand Down Expand Up @@ -418,7 +418,7 @@ describe('Auth Integration Tests', () => {
const oldSession = {
userId,
tokenId: oldTokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand All @@ -428,7 +428,7 @@ describe('Auth Integration Tests', () => {
const newSession = {
userId,
tokenId: newTokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand Down Expand Up @@ -470,7 +470,7 @@ describe('Auth Integration Tests', () => {
const oldSession = {
userId,
tokenId: oldTokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand All @@ -481,7 +481,7 @@ describe('Auth Integration Tests', () => {
const newSession = {
userId,
tokenId: newTokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand All @@ -502,7 +502,7 @@ describe('Auth Integration Tests', () => {
const session = {
userId,
tokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
};
Expand All @@ -522,7 +522,7 @@ describe('Auth Integration Tests', () => {
await sessionService.createSession({
userId,
tokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
});
Expand Down Expand Up @@ -568,7 +568,7 @@ describe('Auth Integration Tests', () => {
await sessionService.createSession({
userId,
tokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
});
Expand All @@ -589,7 +589,7 @@ describe('Auth Integration Tests', () => {
await sessionService.createSession({
userId,
tokenId: `concurrent-token-${i}`,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
});
Expand All @@ -607,7 +607,7 @@ describe('Auth Integration Tests', () => {
await sessionService.createSession({
userId,
tokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
});
Expand All @@ -627,7 +627,7 @@ describe('Auth Integration Tests', () => {
await sessionService.createSession({
userId,
tokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
});
Expand All @@ -652,7 +652,7 @@ describe('Auth Integration Tests', () => {
sessionService.createSession({
userId,
tokenId: `race-token-${i}`,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
})
Expand All @@ -672,7 +672,7 @@ describe('Auth Integration Tests', () => {
await sessionService.createSession({
userId,
tokenId,
publicKey: 'GBTEST',
publicKey: 'GDNX7YG5NRHBKIZITO3FIFYXWLDDAL27IPXLQZSNJBZIIVPDTXJS3YNM',
createdAt: Date.now(),
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000,
});
Expand Down
16 changes: 8 additions & 8 deletions backend/tests/integration/market-lifecycle.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Market Lifecycle E2E', () => {
email: '[email protected]',
username: 'lifecycle_user',
passwordHash: 'hash',
walletAddress: 'GTEST' + 'X'.repeat(51),
walletAddress: 'GAW2MORAONSQ2XHCUYFIUPHXQ2G6PCQ5K37JTS6A4RANJ4LDVEUFUCXG',
usdcBalance: 10000,
xlmBalance: 1000,
},
Expand All @@ -53,27 +53,27 @@ describe('Market Lifecycle E2E', () => {
if (testUser) {
await prisma.trade
.deleteMany({ where: { userId: testUser.id } })
.catch(() => {});
.catch(() => { });
await prisma.prediction
.deleteMany({ where: { userId: testUser.id } })
.catch(() => {});
.catch(() => { });
await prisma.share
.deleteMany({ where: { userId: testUser.id } })
.catch(() => {});
.catch(() => { });
await prisma.leaderboard
.deleteMany({ where: { userId: testUser.id } })
.catch(() => {});
.catch(() => { });
await prisma.categoryLeaderboard
.deleteMany({ where: { userId: testUser.id } })
.catch(() => {});
.catch(() => { });
}
if (testMarket) {
await prisma.market
.delete({ where: { id: testMarket.id } })
.catch(() => {});
.catch(() => { });
}
if (testUser) {
await prisma.user.delete({ where: { id: testUser.id } }).catch(() => {});
await prisma.user.delete({ where: { id: testUser.id } }).catch(() => { });
}
await prisma.$disconnect();
});
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/middleware/validation.schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

// Valid Stellar public key for tests
const VALID_STELLAR_KEY =
'GA5XIGA5C7QTPTWXQHY6MCJRMTRZDOSHR6EFIBNDQTCQHG262N4GGKXQ';
'GAMCVGJFOWWCF6N7YSS66DEZQSCGWZU2SCOWIA2NTMCKTODDTPUOOYDY';
const VALID_UUID = '123e4567-e89b-12d3-a456-426614174000';

// Helper to create a future datetime string
Expand Down
Loading
Loading