-
Notifications
You must be signed in to change notification settings - Fork 808
Expand file tree
/
Copy pathTests.spec.js
More file actions
86 lines (76 loc) 路 2.74 KB
/
Copy pathTests.spec.js
File metadata and controls
86 lines (76 loc) 路 2.74 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
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
import axios from 'axios';
import {
getSignedLocalUrl,
normalizeLocalFileUrl,
presignedlocalUrl,
} from '../cloud/parsefunction/getSignedUrl.js';
describe('Parse Server example', () => {
Parse.User.enableUnsafeCurrentUser();
it('call function', async () => {
const result = await Parse.Cloud.run('hello');
expect(result).toBe('Hi');
});
it('call async function', async () => {
const result = await Parse.Cloud.run('asyncFunction');
expect(result).toBe('Hi async');
});
it('failing test', async () => {
const obj = new Parse.Object('Test');
try {
await obj.save();
fail('should not have been able to save test object.');
} catch (e) {
expect(e).toBeDefined();
expect(e.code).toBe(9001);
expect(e.message).toBe('Saving test objects is not available.');
}
});
it('coverage for /', async () => {
const { data, headers } = await axios.get('http://localhost:30001/');
expect(headers['content-type']).toContain('text/html');
expect(data).toBe('I dream of being a website. Please star the parse-server repo on GitHub!');
});
it('coverage for /test', async () => {
const { data, headers } = await axios.get('http://localhost:30001/test');
expect(headers['content-type']).toContain('text/html');
expect(data).toContain('<title>Parse Server Example</title>');
});
});
describe('local file URL signing', () => {
const originalServerUrl = process.env.SERVER_URL;
const originalMasterKey = process.env.MASTER_KEY;
beforeEach(() => {
process.env.SERVER_URL = 'https://opensign.example.com:8443/api/app';
process.env.MASTER_KEY = 'test-master-key';
});
afterAll(() => {
process.env.SERVER_URL = originalServerUrl;
process.env.MASTER_KEY = originalMasterKey;
});
it('normalizes local file URLs to the configured server origin', () => {
const normalizedUrl = normalizeLocalFileUrl(
'https://opensign.example.com/api/app/files/opensign/sample.pdf'
);
expect(normalizedUrl).toBe(
'https://opensign.example.com:8443/api/app/files/opensign/sample.pdf'
);
});
it('preserves the configured port when signing local file URLs', () => {
const signedUrl = getSignedLocalUrl(
'https://opensign.example.com/api/app/files/opensign/sample.pdf',
200
);
expect(signedUrl).toContain(
'https://opensign.example.com:8443/api/app/files/opensign/sample.pdf?token='
);
});
it('re-signs existing local URLs with the configured port', () => {
const signedUrl = presignedlocalUrl(
'https://opensign.example.com/api/app/files/opensign/sample.pdf?token=old-token',
200
);
expect(signedUrl).toContain(
'https://opensign.example.com:8443/api/app/files/opensign/sample.pdf?token='
);
});
});