Skip to content

Commit

Permalink
Add tests for tiktok
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Mar 8, 2022
1 parent ef39b81 commit 4e873f1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
34 changes: 34 additions & 0 deletions test/flow/oauth2.js
Expand Up @@ -206,6 +206,23 @@ describe('oauth2', () => {
})
})

it('authorize - client_key/client_id - tiktok', async () => {
provider.on.authorize = ({query}) => {
t.equal(query.client_id, undefined)
t.equal(query.client_key, 'key')
}
var {body: {response}} = await request({
url: client.url('/connect/tiktok'),
qs: {key: 'key'},
cookie: {},
})
t.deepEqual(response, {
access_token: 'token',
refresh_token: 'refresh',
raw: {access_token: 'token', refresh_token: 'refresh', expires_in: '3600', open_id: 'id'}
})
})

it('authorize - response_type - visualstudio', async () => {
provider.on.authorize = ({url, headers, query}) => {
t.equal(query.response_type, 'Assertion')
Expand Down Expand Up @@ -374,6 +391,23 @@ describe('oauth2', () => {
})
})

it('access - client_key/client_id - tiktok', async () => {
provider.on.access = ({form}) => {
t.equal(form.client_id, undefined)
t.equal(form.client_key, 'key')
}
var {body: {response}} = await request({
url: client.url('/connect/tiktok'),
qs: {key: 'key'},
cookie: {},
})
t.deepEqual(response, {
access_token: 'token',
refresh_token: 'refresh',
raw: {access_token: 'token', refresh_token: 'refresh', expires_in: '3600', open_id: 'id'}
})
})

it('access - basic auth', async () => {
provider.on.access = ({provider, url, headers, query, form}) => {
t.deepEqual(
Expand Down
4 changes: 3 additions & 1 deletion test/handler/profile.js
Expand Up @@ -138,6 +138,7 @@ describe('profile', () => {
'soundcloud',
'stackexchange',
'stocktwits',
'tiktok',
'tumblr',
'vk',
'wechat',
Expand All @@ -146,7 +147,7 @@ describe('profile', () => {
]
for (var name of providers) {
var version = oauth[name].oauth
provider[`oauth${version}`].on.profile = ({method, query, headers}) => {
provider[`oauth${version}`].on.profile = ({method, query, headers, form}) => {
'arcgis' === name ? t.equal(query.f, 'json') :
'constantcontact' === name ? t.equal(query.api_key, 'key') :
'baidu' === name ? t.equal(query.access_token, 'token') :
Expand All @@ -166,6 +167,7 @@ describe('profile', () => {
'soundcloud' === name ? t.equal(query.oauth_token, 'token') :
'stackexchange' === name ? t.equal(query.key, 'token') :
'stocktwits' === name ? t.equal(query.access_token, 'token') :
'tiktok' === name ? (t.equal(method, 'POST'), t.deepEqual(form, {access_token: 'token', open_id: 'id', fields: ['open_id', 'union_id', 'avatar_url', 'display_name']})) :
'tumblr' === name ? t.equal(query.api_key, 'token') :
'vk' === name ? t.deepEqual(query, {access_token: 'token', v: '5.103'}) :
'wechat' === name ? t.deepEqual(query, {access_token: 'token', openid: 'openid', lang: 'zh_CN'}) :
Expand Down
16 changes: 13 additions & 3 deletions test/util/provider.js
Expand Up @@ -180,6 +180,7 @@ var oauth2 = (port) => new Promise((resolve) => {
: res.end(JSON.stringify({
access_token: 'token', refresh_token: 'refresh', expires_in: 3600,
id_token: openid ? sign({typ: 'JWT'}, {nonce: 'whatever'}, 'signature') : undefined,
open_id: provider === 'tiktok' ? 'id' : undefined,
uid: provider === 'weibo' ? 'id' : undefined,
openid: provider === 'wechat' ? 'openid' : undefined,
}))
Expand Down Expand Up @@ -242,9 +243,18 @@ var oauth2 = (port) => new Promise((resolve) => {
})
}
else if (/profile_url/.test(req.url)) {
on.profile({method, url, query, headers})
res.writeHead(200, {'content-type': 'application/json'})
res.end(JSON.stringify({user: 'simov'}))
if (method === 'POST') {
buffer(req, (form) => {
on.profile({method, url, query, headers, form})
res.writeHead(200, {'content-type': 'application/json'})
res.end(JSON.stringify({user: 'simov'}))
})
}
else {
on.profile({method, url, query, headers})
res.writeHead(200, {'content-type': 'application/json'})
res.end(JSON.stringify({user: 'simov'}))
}
}
else if (/profile_error/.test(req.url)) {
on.profile({method, url, query, headers})
Expand Down

0 comments on commit 4e873f1

Please sign in to comment.