-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathyggdrasil.js
53 lines (41 loc) · 1.24 KB
/
yggdrasil.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
/* eslint-disable ava/no-ignored-test-files */
import test from 'ava'
import mojang from '..'
const {
MOJANG_USERNAME,
MOJANG_PASSWORD,
MOJANG_CLIENT_TOKEN
} = process.env
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
test('yggdrasil integration', async t => {
// create unprofiled session
const credentials = {
username: MOJANG_USERNAME,
password: MOJANG_PASSWORD,
clientToken: MOJANG_CLIENT_TOKEN
}
const session = await mojang.authenticate(credentials)
t.is(session.clientToken, MOJANG_CLIENT_TOKEN)
// access token is good
await delay(1000)
t.true(await mojang.isValid(session))
// refresh session
await delay(1000)
const nextSession = await mojang.refresh(session)
t.not(nextSession.accessToken, session.accessToken)
// old access token is bad
await delay(1000)
t.false(await mojang.isValid(session))
// new access token is good
await delay(1000)
t.true(await mojang.isValid(nextSession))
// invalidate newest access token
await delay(1000)
await mojang.invalidate(nextSession)
// newest access token is also bad
await delay(1000)
t.false(await mojang.isValid(nextSession))
// signout for good measure
await delay(1000)
await mojang.signout(credentials)
})