34 lines
895 B
JavaScript
34 lines
895 B
JavaScript
'use strict'
|
|
|
|
const test = require('brittle')
|
|
const { encodeInvite, decodeInvite, PREFIX } = require('../lib/invite')
|
|
|
|
test('round-trip invite', (t) => {
|
|
const inv = encodeInvite({
|
|
worldKey: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
cap: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
|
name: 'Demo',
|
|
mcVersion: '1.21.1',
|
|
portHint: 25565
|
|
})
|
|
t.ok(inv.startsWith(PREFIX))
|
|
const body = decodeInvite(inv)
|
|
t.is(body.name, 'Demo')
|
|
t.is(body.mcVersion, '1.21.1')
|
|
t.is(body.type, 'private-world')
|
|
t.is(body.v, 1)
|
|
})
|
|
|
|
test('rejects bad prefix', (t) => {
|
|
t.exception(() => decodeInvite('pd1.nope'))
|
|
})
|
|
|
|
test('rejects expired', (t) => {
|
|
const inv = encodeInvite({
|
|
worldKey: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
|
cap: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
|
expires: Date.now() - 1000
|
|
})
|
|
t.exception(() => decodeInvite(inv))
|
|
})
|