34 lines
2.3 KiB
JavaScript
34 lines
2.3 KiB
JavaScript
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {openAccountConnection,sealAccountConnection} from '../../src/foundry/account-connection.mjs';
|
|
import {MAReadClient} from '../../src/providers/ma/client.mjs';
|
|
import {hmac} from '../../src/providers/ma/webcrypto.mjs';
|
|
|
|
test('saved account connection is portable ciphertext bound to the same token, world and user',async()=>{
|
|
const config={maUrl:'https://ma.example.test',targetName:'Development receiver',token:'fixture-token',identityStorage:{secret:'excluded'}};
|
|
const scope='["https://foundry.example.test","world","gm"]';
|
|
const saved=await sealAccountConnection(config,config.token,scope);
|
|
assert.ok(!JSON.stringify(saved).includes(config.maUrl));
|
|
assert.ok(!JSON.stringify(saved).includes(config.token));
|
|
assert.deepEqual(await openAccountConnection(JSON.parse(JSON.stringify(saved)),config.token,scope),{maUrl:config.maUrl,targetName:config.targetName});
|
|
await assert.rejects(openAccountConnection(saved,'different-token',scope),{code:'saved-connection-unavailable'});
|
|
await assert.rejects(openAccountConnection(saved,config.token,scope.replace('gm','player')),{code:'saved-connection-unavailable'});
|
|
});
|
|
|
|
test('new playlist references are shared across browsers and the original can still resolve its old reference',async()=>{
|
|
const fetchImpl=async(_url,options)=>Response.json(JSON.parse(options.body).command.includes('/playlists/')?[
|
|
{name:'Ambient',media_type:'playlist',is_playable:true,provider_mappings:[{provider_instance:'music',item_id:'ambient',available:true}]},
|
|
]:[]);
|
|
const common={baseUrl:'https://ma.example.test',token:'fixture-token',target:'dedicated',approvedProviders:['music'],campaign:'test',fetchImpl};
|
|
const catalogKey=await hmac(new TextEncoder().encode(common.token),'test portable catalog');
|
|
const originalKey=new Uint8Array(32).fill(1),otherKey=new Uint8Array(32).fill(2);
|
|
const [old]=await new MAReadClient({...common,catalogKey:originalKey}).catalog();
|
|
const first=new MAReadClient({...common,catalogKey,legacyCatalogKey:originalKey});
|
|
const other=new MAReadClient({...common,catalogKey,legacyCatalogKey:otherKey});
|
|
const [a]=await first.catalog(),[b]=await other.catalog();
|
|
assert.equal(a.id,b.id);
|
|
assert.equal(a.legacyId,old.id);
|
|
assert.notEqual(a.legacyId,b.legacyId);
|
|
assert.equal(first.resolveCatalog(old),other.resolveCatalog(a));
|
|
});
|