-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpatch_test.sh
More file actions
137 lines (113 loc) · 4.84 KB
/
patch_test.sh
File metadata and controls
137 lines (113 loc) · 4.84 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
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
cat << 'INNER_EOF' > src/utils/helper.test.ts
import { afterEach, describe, expect, test } from 'bun:test';
import {
getRecentAppIds,
isExpVersion,
isPasswordValid,
isValidExternalUrl,
RECENT_APP_STORAGE_KEY,
} from './helper';
describe('isPasswordValid', () => {
test('should return true for valid passwords', () => {
expect(isPasswordValid('Passw0rd')).toBe(true);
expect(isPasswordValid('UPPER123')).toBe(true);
expect(isPasswordValid('Valid123')).toBe(true);
});
test('should return false for passwords that are too short', () => {
expect(isPasswordValid('Short')).toBe(false); // 5 chars
expect(isPasswordValid('A1b')).toBe(false); // 3 chars
});
test('should return false for passwords that are too long', () => {
expect(isPasswordValid('ThisPasswordIsWayTooLong123')).toBe(false); // > 16 chars
});
test('should return false for passwords with only digits', () => {
expect(isPasswordValid('12345678')).toBe(false);
});
test('should return false for passwords with only lowercase letters', () => {
expect(isPasswordValid('lowercase')).toBe(false);
});
test('should return false for passwords with no uppercase letters', () => {
expect(isPasswordValid('lower123')).toBe(false);
expect(isPasswordValid('noupper!')).toBe(false);
});
});
describe('isExpVersion', () => {
test('should return false when config is null', () => {
expect(isExpVersion(null, '1.0.0')).toBe(false);
});
test('should return false when config is undefined', () => {
expect(isExpVersion(undefined, '1.0.0')).toBe(false);
});
test('should return false when config.rollout is missing', () => {
expect(isExpVersion({}, '1.0.0')).toBe(false);
});
test('should return false when rollout config for version is missing', () => {
expect(isExpVersion({ rollout: {} }, '1.0.0')).toBe(false);
});
test('should return false when rollout config for version is null', () => {
expect(isExpVersion({ rollout: { '1.0.0': null } }, '1.0.0')).toBe(false);
});
test('should return true when rollout is less than 100', () => {
expect(isExpVersion({ rollout: { '1.0.0': 50 } }, '1.0.0')).toBe(true);
expect(isExpVersion({ rollout: { '1.0.0': 0 } }, '1.0.0')).toBe(true);
});
test('should return false when rollout is 100', () => {
expect(isExpVersion({ rollout: { '1.0.0': 100 } }, '1.0.0')).toBe(false);
});
test('should return false when rollout is greater than 100', () => {
expect(isExpVersion({ rollout: { '1.0.0': 110 } }, '1.0.0')).toBe(false);
});
});
describe('getRecentAppIds', () => {
afterEach(() => {
window.localStorage.clear();
});
test('should return empty array when localStorage contains invalid JSON', () => {
window.localStorage.setItem(RECENT_APP_STORAGE_KEY, 'invalid json');
expect(getRecentAppIds()).toEqual([]);
});
test('should return empty array when localStorage contains non-array JSON', () => {
window.localStorage.setItem(RECENT_APP_STORAGE_KEY, '{"a": 1}');
expect(getRecentAppIds()).toEqual([]);
});
test('should return filtered array of integers when localStorage contains valid array', () => {
window.localStorage.setItem(RECENT_APP_STORAGE_KEY, '[1, "2", 3.5, 4]');
expect(getRecentAppIds()).toEqual([1, 4]);
});
test('should return empty array when window is undefined', () => {
const originalWindow = global.window;
// @ts-expect-error
delete global.window;
expect(getRecentAppIds()).toEqual([]);
global.window = originalWindow;
});
});
describe('isValidExternalUrl', () => {
test('should return true for valid https URLs with trusted domains', () => {
expect(isValidExternalUrl('https://react-native.cn/path')).toBe(true);
expect(isValidExternalUrl('https://sub.react-native.cn/path')).toBe(true);
expect(isValidExternalUrl('https://reactnative.cn/')).toBe(true);
expect(isValidExternalUrl('https://rnupdate.online/foo')).toBe(true);
expect(isValidExternalUrl('https://alipay.com/pay')).toBe(true);
expect(isValidExternalUrl('https://openapi.alipay.com/gateway.do')).toBe(
true,
);
});
test('should return false for http protocol', () => {
expect(isValidExternalUrl('http://react-native.cn/path')).toBe(false);
expect(isValidExternalUrl('http://alipay.com')).toBe(false);
});
test('should return false for untrusted domains', () => {
expect(isValidExternalUrl('https://evil.com/path')).toBe(false);
expect(isValidExternalUrl('https://google.com')).toBe(false);
expect(isValidExternalUrl('https://react-native.cnevil.com')).toBe(false);
});
test('should return false for malformed URLs', () => {
expect(isValidExternalUrl('not a url')).toBe(false);
expect(isValidExternalUrl('://bad-url')).toBe(false);
});
test('should return false for javascript uris', () => {
expect(isValidExternalUrl('javascript:alert(1)')).toBe(false);
});
});
INNER_EOF