forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublicAPI.spec.js
184 lines (164 loc) · 5.43 KB
/
PublicAPI.spec.js
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const req = require('../lib/request');
const request = function (url, callback) {
return req({
url,
}).then(
response => callback(null, response),
err => callback(err, err)
);
};
describe('public API', () => {
it('should return missing username error on ajax request without username provided', async () => {
await reconfigureServer({
publicServerURL: 'http://localhost:8378/1',
});
try {
await req({
method: 'POST',
url: 'http://localhost:8378/1/apps/test/request_password_reset',
body: `new_password=user1&token=43634643&username=`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest',
},
followRedirects: false,
});
} catch (error) {
expect(error.status).not.toBe(302);
expect(error.text).toEqual('{"code":200,"error":"Missing username"}');
}
});
it('should return missing token error on ajax request without token provided', async () => {
await reconfigureServer({
publicServerURL: 'http://localhost:8378/1',
});
try {
await req({
method: 'POST',
url: 'http://localhost:8378/1/apps/test/request_password_reset',
body: `new_password=user1&token=&username=Johnny`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest',
},
followRedirects: false,
});
} catch (error) {
expect(error.status).not.toBe(302);
expect(error.text).toEqual('{"code":-1,"error":"Missing token"}');
}
});
it('should return missing password error on ajax request without password provided', async () => {
await reconfigureServer({
publicServerURL: 'http://localhost:8378/1',
});
try {
await req({
method: 'POST',
url: 'http://localhost:8378/1/apps/test/request_password_reset',
body: `new_password=&token=132414&username=Johnny`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest',
},
followRedirects: false,
});
} catch (error) {
expect(error.status).not.toBe(302);
expect(error.text).toEqual('{"code":201,"error":"Missing password"}');
}
});
it('should get invalid_link.html', done => {
request('http://localhost:8378/1/apps/invalid_link.html', (err, httpResponse) => {
expect(httpResponse.status).toBe(200);
done();
});
});
it('should get choose_password', done => {
reconfigureServer({
appName: 'unused',
publicServerURL: 'http://localhost:8378/1',
}).then(() => {
request('http://localhost:8378/1/apps/choose_password?id=test', (err, httpResponse) => {
expect(httpResponse.status).toBe(200);
done();
});
});
});
it('should get verify_email_success.html', done => {
request('http://localhost:8378/1/apps/verify_email_success.html', (err, httpResponse) => {
expect(httpResponse.status).toBe(200);
done();
});
});
it('should get password_reset_success.html', done => {
request('http://localhost:8378/1/apps/password_reset_success.html', (err, httpResponse) => {
expect(httpResponse.status).toBe(200);
done();
});
});
});
describe('public API without publicServerURL', () => {
beforeEach(done => {
reconfigureServer({ appName: 'unused' }).then(done, fail);
});
it('should get 404 on verify_email', done => {
request('http://localhost:8378/1/apps/test/verify_email', (err, httpResponse) => {
expect(httpResponse.status).toBe(404);
done();
});
});
it('should get 404 choose_password', done => {
request('http://localhost:8378/1/apps/choose_password?id=test', (err, httpResponse) => {
expect(httpResponse.status).toBe(404);
done();
});
});
it('should get 404 on request_password_reset', done => {
request('http://localhost:8378/1/apps/test/request_password_reset', (err, httpResponse) => {
expect(httpResponse.status).toBe(404);
done();
});
});
});
describe('public API supplied with invalid application id', () => {
beforeEach(done => {
reconfigureServer({ appName: 'unused' }).then(done, fail);
});
it('should get 403 on verify_email', done => {
request('http://localhost:8378/1/apps/invalid/verify_email', (err, httpResponse) => {
expect(httpResponse.status).toBe(403);
done();
});
});
it('should get 403 choose_password', done => {
request('http://localhost:8378/1/apps/choose_password?id=invalid', (err, httpResponse) => {
expect(httpResponse.status).toBe(403);
done();
});
});
it('should get 403 on get of request_password_reset', done => {
request('http://localhost:8378/1/apps/invalid/request_password_reset', (err, httpResponse) => {
expect(httpResponse.status).toBe(403);
done();
});
});
it('should get 403 on post of request_password_reset', done => {
req({
url: 'http://localhost:8378/1/apps/invalid/request_password_reset',
method: 'POST',
}).then(done.fail, httpResponse => {
expect(httpResponse.status).toBe(403);
done();
});
});
it('should get 403 on resendVerificationEmail', done => {
request(
'http://localhost:8378/1/apps/invalid/resend_verification_email',
(err, httpResponse) => {
expect(httpResponse.status).toBe(403);
done();
}
);
});
});