Skip to content

Commit f9ee836

Browse files
authored
Merge pull request #51 from KagemniKarimu/add-auth-tests
🔐 Add auth tests & harden API security
2 parents f3b7bbc + 7be1aea commit f9ee836

File tree

3 files changed

+410
-22
lines changed

3 files changed

+410
-22
lines changed

src/routes.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121
import { Router } from 'express'
2222
import type { RouteMount } from './types/routes.js'
2323
import {
24-
saveBundle,
2524
getBundle,
2625
getAllBundles,
27-
saveCID,
2826
getCIDsByNonce,
29-
updateBalanceForOneToken,
3027
getBalanceForOneToken,
3128
getBalanceForAllTokens,
3229
getVaultNonce,
33-
setVaultNonce,
3430
healthCheck,
3531
detailedHealthCheck,
3632
getInfo,
@@ -40,10 +36,6 @@ import {
4036
getVaultIdsByController,
4137
getControllersByVaultId,
4238
getRulesByVaultId,
43-
addControllerToVault,
44-
removeControllerFromVault,
45-
setRulesForVault,
46-
createVault,
4739
} from './controllers.js'
4840

4941
/**
@@ -78,27 +70,21 @@ export const routeMounts: RouteMount[] = [
7870
},
7971
{
8072
basePath: '/bundle',
81-
router: Router()
82-
.post('/', saveBundle)
83-
.get('/:nonce', getBundle)
84-
.get('/', getAllBundles),
73+
router: Router().get('/:nonce', getBundle).get('/', getAllBundles),
8574
},
8675
{
8776
basePath: '/cid',
88-
router: Router().post('/', saveCID).get('/:nonce', getCIDsByNonce),
77+
router: Router().get('/:nonce', getCIDsByNonce),
8978
},
9079
{
9180
basePath: '/balance',
9281
router: Router()
93-
.post('/', updateBalanceForOneToken)
9482
.get('/:vault/:token', getBalanceForOneToken)
9583
.get('/:vault', getBalanceForAllTokens),
9684
},
9785
{
9886
basePath: '/nonce',
99-
router: Router()
100-
.get('/:vault', getVaultNonce)
101-
.post('/:vault', setVaultNonce),
87+
router: Router().get('/:vault', getVaultNonce),
10288
},
10389
{
10490
basePath: '/filecoin',
@@ -107,12 +93,8 @@ export const routeMounts: RouteMount[] = [
10793
{
10894
basePath: '/vault',
10995
router: Router()
110-
.post('/:vaultId', createVault)
11196
.get('/by-controller/:address', getVaultIdsByController)
11297
.get('/:vaultId/controllers', getControllersByVaultId)
113-
.get('/:vaultId/rules', getRulesByVaultId)
114-
.post('/:vaultId/controllers/add', addControllerToVault)
115-
.post('/:vaultId/controllers/remove', removeControllerFromVault)
116-
.post('/:vaultId/rules', setRulesForVault),
98+
.get('/:vaultId/rules', getRulesByVaultId),
11799
},
118100
]

test/helpers/testFixtures.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* ╔═══════════════════════════════════════════════════════════════════════════╗
3+
* ║ 🌪️ OYA PROTOCOL NODE 🌪️ ║
4+
* ║ Test Fixtures & Constants ║
5+
* ╚═══════════════════════════════════════════════════════════════════════════╝
6+
*
7+
* Shared test data and constants used across test suites.
8+
*/
9+
10+
/**
11+
* Sample vault ID for testing (valid 32-byte hex string with 0x prefix).
12+
*/
13+
export const TEST_VAULT_ID =
14+
'0x1234567890123456789012345678901234567890123456789012345678901234'
15+
16+
/**
17+
* Sample Ethereum address for testing (lowercase to avoid checksum validation).
18+
*/
19+
export const TEST_ADDRESS = '0x742d35cc6634c0532925a3b844bc9e7595f0beb'
20+
21+
/**
22+
* Additional test addresses for multi-party scenarios.
23+
*/
24+
export const TEST_ADDRESS_2 = '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
25+
export const TEST_ADDRESS_3 = '0xcccccccccccccccccccccccccccccccccccccccc'
26+
27+
/**
28+
* Real mainnet token addresses for testing (lowercase, always valid).
29+
*/
30+
export const USDC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
31+
export const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
32+
33+
/**
34+
* Sample CID for testing.
35+
*/
36+
export const TEST_CID =
37+
'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi'
38+
39+
/**
40+
* All POST endpoints that require authentication.
41+
* Only /intention is publicly accessible via POST.
42+
* Other write operations are internal-only (not exposed via HTTP).
43+
*/
44+
export const POST_ENDPOINTS = ['/intention']
45+
46+
/**
47+
* All GET endpoints that should NOT require authentication.
48+
* Used for testing that public endpoints remain accessible.
49+
*/
50+
export const GET_ENDPOINTS = [
51+
'/health',
52+
'/info',
53+
'/metrics',
54+
'/bundle',
55+
'/bundle/0',
56+
'/cid/0',
57+
`/balance/${TEST_VAULT_ID}`,
58+
`/nonce/${TEST_VAULT_ID}`,
59+
`/vault/${TEST_VAULT_ID}/controllers`,
60+
`/vault/${TEST_VAULT_ID}/rules`,
61+
'/vault/by-controller/0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
62+
`/filecoin/status/${TEST_CID}`,
63+
]
64+
65+
/**
66+
* Sample valid intention payload for testing.
67+
*/
68+
export const SAMPLE_INTENTION = {
69+
from: TEST_ADDRESS,
70+
to: TEST_ADDRESS,
71+
intention: 'test intention',
72+
vaultId: TEST_VAULT_ID,
73+
signature: '0x' + '0'.repeat(130), // Dummy signature
74+
}

0 commit comments

Comments
 (0)