generated from WalletConnect/rust-http-starter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
integration.test.ts
167 lines (133 loc) · 5.39 KB
/
integration.test.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import axios from 'axios'
const http = axios.create({
validateStatus: (_status) => true,
})
declare let process: {
env: {
JEST_ENV: string,
TEST_TENANT_ID_APNS: string,
TEST_PROJECT_ID: string,
}
}
const BASE_URLS = new Map<string, string>([
['prod', 'https://verify.walletconnect.com'],
['staging', 'https://staging.verify.walletconnect.com'],
['dev', 'https://dev.verify.walletconnect.com'],
['local', 'http://localhost:3000'],
])
const ENV = process.env.JEST_ENV;
const TEST_PROJECT_ID = process.env.TEST_PROJECT_ID || 'e4eae1aad4503db9966a04fd045a7e4d'
const BASE_URL = BASE_URLS.get(process.env.JEST_ENV)
describe('verify', () => {
describe('Health', () => {
const url = `${BASE_URL}/health`
it('is healthy', async () => {
const { status } = await http.get(`${url}`)
expect(status).toBe(200)
})
})
describe('Attestation', () => {
const url = `${BASE_URL}/attestation`
it('non-scam origin', async () => {
let resp: any = await http.get(`${BASE_URL}/${TEST_PROJECT_ID}`)
let csrfToken = resp.headers["x-csrf-token"]
resp = await http.post(`${url}`, {'origin': 'http://localhost', 'attestationId': 'some'}, {
headers: { "x-csrf-token": csrfToken },
})
expect(resp.status).toBe(200)
expect(resp.headers["access-control-allow-origin"]).toBe(undefined)
resp = await http.options(`${url}/some`);
expect(resp.headers["access-control-allow-origin"]).toBe("*")
resp = await http.get(`${url}/some`)
expect(resp.status).toBe(200)
expect(resp.data.origin).toBe('http://localhost')
expect(resp.data.isScam).toBe(false)
expect(resp.headers["access-control-allow-origin"]).toBe("*")
})
it('scam origin', async () => {
let resp: any = await http.get(`${BASE_URL}/${TEST_PROJECT_ID}`)
let csrfToken = resp.headers["x-csrf-token"]
resp = await http.post(`${url}`, {'origin': 'https://evilpepecoin.com', 'attestationId': 'evil'}, {
headers: { "x-csrf-token": csrfToken },
})
resp = await http.options(`${url}/evil`);
resp = await http.get(`${url}/evil`)
expect(resp.data.isScam).toBe(true)
})
it('scam: unknown', async () => {
let resp: any = await http.get(`${BASE_URL}/${TEST_PROJECT_ID}`)
let csrfToken = resp.headers["x-csrf-token"]
resp = await http.post(`${url}`, {'origin': 'https://my-dapp.io', 'attestationId': 'tbd'}, {
headers: { "x-csrf-token": csrfToken },
})
resp = await http.options(`${url}/tbd`);
resp = await http.get(`${url}/tbd`)
expect(resp.data.isScam).toBe(null)
})
it('invalid CSRF token', async () => {
let csrfToken = 'aaaaaaaaaaaa'
let resp: any = await http.post(`${url}`, {'origin': 'localhost', 'attestationId': 'some'}, {
headers: { "x-csrf-token": csrfToken },
})
expect(resp.status).toBe(403)
})
it('expired CSRF token', async () => {
let csrfToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2ODk2NjE2MTl9.PE9QkYso_axaWvwnAUDxth2nBQLNAA0pCDxc8WnfPR8'
let resp: any = await http.post(`${url}`, {'origin': 'localhost', 'attestationId': 'some'}, {
headers: { "x-csrf-token": csrfToken },
})
expect(resp.status).toBe(403)
})
})
describe('Enclave', () => {
const url = `${BASE_URL}`
it('get the enclave', async () => {
let resp: any = await http.get(`${url}/${TEST_PROJECT_ID}`)
expect(resp.status).toBe(200)
let policy = resp.headers["content-security-policy"]
expect(policy).toBe(`frame-ancestors http://*.localhost http://localhost`)
})
describe('invalid project ID', () => {
let errMsg = "Invalid URL: ProjectId should be a hex string 32 chars long"
it('too short', async () => {
let resp = await http.get(`${url}/aaaaaaaaaa`)
expect(resp.status).toBe(400)
expect(resp.data).toBe(errMsg)
})
it('too long', async () => {
let resp = await http.get(`${url}/3bc51577baa09be45c84b85f13419ae8a`)
expect(resp.status).toBe(400)
expect(resp.data).toBe(errMsg)
})
it('non-hex chars', async () => {
let resp = await http.get(`${url}/3bc51577baa09be45c84b85f13419aez`)
expect(resp.status).toBe(400)
expect(resp.data).toBe(errMsg)
})
})
it('non-existent project', async () => {
let resp = await http.get(`${url}/3bc51577baa09be45c84b85f13419ae8`)
expect(resp.status).toBe(404)
expect(resp.data).toContain("Project with the provided ID doesn't exist")
})
it('project with Verify disabled', async () => {
let resp = await http.get(`${url}/0eae574067d750bb4a5e84bb99b5845f`)
expect(resp.status).toBe(200)
let policy = resp.headers["content-security-policy"]
expect(policy).toBe(undefined)
})
})
describe('index.js', () => {
const url = `${BASE_URL}`
it('get index.js', async () => {
let resp: any = await http.get(`${BASE_URL}/${TEST_PROJECT_ID}`)
let csrfToken = resp.headers["x-csrf-token"]
resp = await http.get(`${url}/index.js?token=${csrfToken}`)
expect(resp.status).toBe(200)
})
it('doesn\'t allow invalid `token` parameters', async () => {
let resp = await http.get(`${url}/index.js?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.<img src onerror=alert(document.domain)>`)
expect(resp.status).toBe(400)
})
})
})