Skip to content

Commit

Permalink
fix(controllers): fix has permission to validate setting a controller…
Browse files Browse the repository at this point in the history
… with empty controller array
  • Loading branch information
Atticus committed Jun 19, 2024
1 parent d3dacae commit 11103c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/common/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,13 @@ function utils.validateOwner(caller)
end

function utils.assertHasPermission(from)
local isController = false
for _, c in ipairs(Controllers) do
if c == from then
isController = true
break
-- if is controller, return true
return
end
end
local hasPermission = isController == true or Balances[from] or Owner == from or ao.env.Process.Id == from
local hasPermission = Balances[from] == 1 or Owner == from or ao.env.Process.Id == from
assert(hasPermission == true, "Only controllers and owners can set controllers and records.")
end

Expand Down
11 changes: 11 additions & 0 deletions test/controllers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,16 @@ describe('AOS-ANT Controllers', async () => {
});

assert(result.Messages[0].Data === 'Controller removed');

const addControllerResult = await handle(
{
Tags: [
{ name: 'Action', value: 'Set-Controller' },
{ name: 'Controller', value: STUB_ADDRESS },
],
},
result.Memory,
);
assert.equal(addControllerResult.Messages[0].Data, 'Controller added');
});
});
23 changes: 14 additions & 9 deletions tools/spawn-aos-ant.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,21 @@ async function main() {
const tags = args
? Object.entries(args).map(([key, value]) => ({ name: key, value }))
: [];
const result = await ao.dryrun({
process: processId,
tags: [...tags, { name: 'Action', value: method }],
data,
signer,
Owner: address,
From: address,
});
const result = await ao
.message({
process: processId,
tags: [...tags, { name: 'Action', value: method }],
data,
signer,
Owner: address,
From: address,
})
.catch((e) => e);

console.dir({ method, result }, { depth: null });
console.dir(
{ method, result: result.message, type: typeof result },
{ depth: null },
);
}
}

Expand Down

0 comments on commit 11103c6

Please sign in to comment.