Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/lib/rotur/project-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const PROJECT_METHODS = Object.freeze({
'me.requests': {scopes: ['friends:view']},
'me.claimTime': {scopes: ['credits:view']},
'me.transactions': {scopes: ['credits:view']},
'me.transfer': {
scopes: ['credits:transfer'],
confirm: args => ({
label: `send ${amount(args[1])} credits to @${text(args[0])}`,
confirmation: {type: 'payment', amount: amount(args[1]), recipient: text(args[0])}
})
},

'profiles.get': {scopes: []},
'profiles.exists': {scopes: []},
Expand Down
23 changes: 14 additions & 9 deletions test/unit/community-project-rotur-bridge.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const mockClient = {
setToken: jest.fn(),
tokens: {create: jest.fn(() => Promise.resolve({token: 'rotur_new-token'}))},
me: {
transfer: jest.fn(() => Promise.resolve({ok: true})),
get: jest.fn(() => Promise.resolve({username: 'Viewer'}))
},
profiles: {get: jest.fn(() => Promise.resolve({username: 'someone'}))},
gifts: {create: jest.fn(() => Promise.resolve({ok: true}))},
storage: {get: jest.fn(() => Promise.resolve({data: {}}))}
};

Expand Down Expand Up @@ -125,20 +125,25 @@ describe('community project page Rotur bridge', () => {
wrapper.unmount();
});

test('a payment always shows the real amount and recipient, whatever the frame claims', async () => {
test('projects can no longer send credits', async () => {
const {wrapper, send} = await mountProject();
const reply = await send({kind: 'call', id: 5, method: 'me.transfer', args: ['thief', 5000, '']});
expect(reply.ok).toBe(false);
wrapper.unmount();
});

test('spending always shows the real amount, whatever the frame claims', async () => {
const {wrapper, send} = await mountProject();
const pending = send({
kind: 'call',
id: 5,
method: 'me.transfer',
args: ['thief', 5000, ''],
id: 6,
method: 'gifts.create',
args: [5000],
opts: {sensitive: false, label: 'claim a free hat'}
});
await pending;
expect(mockClient.me.transfer).not.toHaveBeenCalled();
expect(wrapper.text()).toContain('Confirm payment');
expect(wrapper.text()).toContain('5000');
expect(wrapper.text()).toContain('@thief');
expect(mockClient.gifts.create).not.toHaveBeenCalled();
expect(wrapper.text()).toContain('create a gift of 5000 credits');
expect(wrapper.text()).not.toContain('free hat');
wrapper.unmount();
});
Expand Down
14 changes: 7 additions & 7 deletions test/unit/packager-account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ test('extensions in an export cannot reach the token or unlisted SDK methods', a

test('a payment is confirmed with the real amount even when the caller says it is not sensitive', async () => {
const sdk = client();
sdk.me.transfer = jest.fn();
sdk.gifts = {create: jest.fn()};
const runtime = runtimeFor('roturEconomy_pay');
const host = createAccountHost(runtime, {title: 'Game'}, function () { return sdk; });
const ready = host.prepare();
await document.querySelector('button').onclick();
await ready;
const confirm = jest.spyOn(window, 'confirm').mockReturnValue(false);
await expect(runtime.roturHost.call('me.transfer', ['thief', 500], {sensitive: false}))
await expect(runtime.roturHost.call('gifts.create', [500], {sensitive: false}))
.rejects.toThrow('cancelled');
expect(confirm).toHaveBeenCalledWith('Allow Game to send 500 credits to @thief?');
expect(sdk.me.transfer).not.toHaveBeenCalled();
expect(confirm).toHaveBeenCalledWith('Allow Game to create a gift of 500 credits?');
expect(sdk.gifts.create).not.toHaveBeenCalled();
});

test('failed authentication keeps project gated and permits retry', async () => {
Expand Down Expand Up @@ -114,16 +114,16 @@ test('published game data uses a player capability and the authenticated session

test('sensitive Rotur actions retain a separate confirmation after login', async () => {
const sdk = client();
sdk.me.transfer = jest.fn();
sdk.gifts = {create: jest.fn()};
const runtime = runtimeFor('roturEconomy_transfer');
const host = createAccountHost(runtime, {}, function () { return sdk; });
const ready = host.prepare();
await document.querySelector('button').onclick();
await ready;
jest.spyOn(window, 'confirm').mockReturnValue(false);
await expect(runtime.roturHost.call('me.transfer', ['someone', 5], {sensitive: true}))
await expect(runtime.roturHost.call('gifts.create', [5], {sensitive: true}))
.rejects.toThrow('cancelled');
expect(sdk.me.transfer).not.toHaveBeenCalled();
expect(sdk.gifts.create).not.toHaveBeenCalled();
});

test('preview storage supports browser storage methods and property access without sharing data', () => {
Expand Down
12 changes: 6 additions & 6 deletions test/unit/rotur-extension-host.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ test('trusted projects still confirm sensitive Rotur actions', async () => {
const showModal = jest.fn(() => Promise.resolve(true));
host.acquireModalLock = jest.fn(() => Promise.resolve({showModal}));

await host.call('me.transfer', ['other-user', 10, ''], {
await host.call('gifts.create', [10], {
sensitive: false,
label: 'claim a free hat',
confirmation: {type: 'payment', amount: 1, recipient: 'friend'}
});

expect(showModal).toHaveBeenCalledWith('confirm', {
label: 'send 10 credits to @other-user',
confirmation: {type: 'payment', amount: 10, recipient: 'other-user'},
label: 'create a gift of 10 credits',
confirmation: null,
username: 'user'
});
expect(callRotur).toHaveBeenCalledWith('me.transfer', ['other-user', 10, '']);
expect(callRotur).toHaveBeenCalledWith('gifts.create', [10]);
});

test('authenticated reads expand scopes without prompting', async () => {
Expand Down Expand Up @@ -120,9 +120,9 @@ test('blocked projects cannot reopen Rotur prompts', async () => {

await expect(host.ensureConsent(['posts:create'], {name: 'Blocked project'})).resolves.toBe(false);
await expect(host.ensureActivitySharing()).resolves.toBe(false);
await expect(host.call('me.transfer', ['other-user', 10], {
await expect(host.call('gifts.create', [10], {
sensitive: true,
label: 'me.transfer'
label: 'gifts.create'
})).rejects.toThrow('cancelled');

expect(host.state.type).toBe(null);
Expand Down
14 changes: 7 additions & 7 deletions test/unit/rotur-project-methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ test('every method the built-in Rotur extensions call is allowlisted with its sc
const calls = await recordExtensionCalls();
expect(calls.length).toBeGreaterThan(80);
for (const {method, opts, scopes} of calls) {
// The "send credits" block: projects can't send credits any more.
if (method === 'me.transfer') continue;
const spec = projectMethod(method);
expect({method, allowed: Boolean(spec)}).toEqual({method, allowed: true});
for (const scope of scopes) {
Expand Down Expand Up @@ -79,6 +81,7 @@ test.each([
'me.deleteAccount',
'me.update',
'admin.transferCredits',
'me.transfer',
'me.transfer.call',
'socket.token',
'socket.send',
Expand Down Expand Up @@ -110,15 +113,12 @@ test('a scoped method needs a grant for one of its scopes', () => {
});

test('spending methods are confirmed with text the host builds from the arguments', () => {
const call = authorizeProjectCall('me.transfer', ['thief', 999, 'note'], [], 'p');
expect(call.confirm).toEqual({
label: 'send 999 credits to @thief',
confirmation: {type: 'payment', amount: 999, recipient: 'thief'}
});
expect(authorizeProjectCall('gifts.create', ['999'], [], 'p').confirm.label)
.toBe('create a gift of 999 credits');
expect(authorizeProjectCall('groups.sendTip', ['tag', '5'], [], 'p').confirm.label)
.toBe('tip 5 credits to group tag');
for (const method of [
'me.transfer', 'gifts.create', 'gifts.claim', 'keys.buy', 'keys.cancel', 'keys.delete',
'gifts.create', 'gifts.claim', 'keys.buy', 'keys.cancel', 'keys.delete',
'posts.delete', 'items.buy', 'items.transfer', 'cosmetics.purchase',
'groups.sendTip', 'groups.purchaseProduct'
]) {
Expand Down Expand Up @@ -147,7 +147,7 @@ test('projects may only ask for scopes their blocks can use', () => {

test('only read scopes and per-call-confirmed scopes are granted without asking', () => {
expect(grantsSilently(['credits:view', 'account:view'])).toBe(true);
expect(grantsSilently(['credits:transfer'])).toBe(true);
expect(grantsSilently(['gifts:create'])).toBe(true);
expect(grantsSilently(['posts:delete'])).toBe(true);
expect(grantsSilently(['posts:create'])).toBe(false);
expect(grantsSilently(['keys:manage'])).toBe(false);
Expand Down
Loading