-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwechat.test.js
More file actions
66 lines (61 loc) · 1.93 KB
/
wechat.test.js
File metadata and controls
66 lines (61 loc) · 1.93 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
const assert = require('assert').strict
const { genRedirectUrl, genOAuthUrl, decodeOAuthUrl } = require('../dist/cjs/')
const options = {
appId: '12345678',
merNo: '112345678',
deviceId: 'test',
indexDoc: 'test',
domain: 'www.baidu.com',
basic: 'api.baidu.com',
basicImgUrl: 'img.baidu.com',
https: true
}
const wechatOptions = {
wx_appid: '123456',
wx_component_appid: '1123456',
wx_scope: 'snsapi_base',
redirect_url: genRedirectUrl(options),
state: '0'
}
// decodeOAuthUrl
// normal links with normal propertyeis
assert.deepEqual(decodeOAuthUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx520c15f417810387&redirect_uri=https%3A%2F%2Fchong.qq.com%2Fphp%2Findex.php%3Fd%3D%26c%3DwxAdapter%26m%3DmobileDeal%26showwxpaytitle%3D1%26vb2ctag%3D4_2030_5_1194_60&response_type=code&scope=snsapi_base&state=123#wechat_redirect"), {
valid: true,
data: {
wx_appid: 'wx520c15f417810387',
redirect_url: 'https://chong.qq.com/php/index.php?d=&c=wxAdapter&m=mobileDeal&showwxpaytitle=1&vb2ctag=4_2030_5_1194_60',
response_type: 'code',
wx_scope: 'snsapi_base',
state: '123',
hash: '#wechat_redirect'
}
})
assert.deepEqual(decodeOAuthUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx807d86fb6b3d4fd2&redirect_uri=http%3A%2F%2Fdevelopers.weixin.qq.com&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"), {
valid: true,
data: {
wx_appid: 'wx807d86fb6b3d4fd2',
redirect_url: 'http://developers.weixin.qq.com',
response_type: 'code',
wx_scope: 'snsapi_userinfo',
state: 'STATE',
hash: '#wechat_redirect'
}
})
// invalid url links
let invalidUrls = [
123,
'aagagda',
{},
null,
undefined,
true,
'https://www.baidu.com/',
'http://www.baidu.com/',
'https://open.weixin.qq.com/connect/oauth2/authorize/adadada/adada'
]
invalidUrls.forEach((url) => {
assert.deepEqual(decodeOAuthUrl(url), {
valid: false,
data: null
})
})