forked from ritik4ever/stellar-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-auth-flow.ts
More file actions
33 lines (29 loc) · 1.12 KB
/
Copy pathtest-auth-flow.ts
File metadata and controls
33 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { describe, it, expect, beforeAll, vi } from 'vitest';
import request from 'supertest';
import { app } from './backend/src/index';
import { Keypair, Transaction, Networks } from '@stellar/stellar-sdk';
describe('Integration: Auth Flow', () => {
let clientKeypair: Keypair;
let challengeTx: string;
let validToken: string;
beforeAll(() => {
vi.stubEnv('JWT_SECRET', 'test_secret');
clientKeypair = Keypair.random();
});
it('should generate a challenge', async () => {
const response = await request(app)
.get('/api/auth/challenge')
.query({ accountId: clientKeypair.publicKey() });
expect(response.status).toBe(200);
challengeTx = response.body.transaction;
});
it('should verify with correct sig', async () => {
const tx = new Transaction(challengeTx, Networks.TESTNET);
tx.sign(clientKeypair);
const response = await request(app)
.post('/api/auth/token')
.send({ transaction: tx.toXDR() });
expect(response.status).toBe(200);
validToken = response.body.token;
});
});