-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: constrain external ID attestation author in recipes (#117)
- Loading branch information
Showing
7 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/tryorama/src/recipe/cannot_use_untrusted_external_id_attestor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect, test } from "vitest"; | ||
import { runScenario } from "@holochain/tryorama"; | ||
|
||
import { setupPlayer } from "../utils/setup-happ.js"; | ||
import { encodeHashToBase64, fakeAgentPubKey } from "@holochain/client"; | ||
|
||
test("Cannot use untrusted external id attestor", async () => { | ||
await runScenario(async (scenario) => { | ||
const [alice, aliceCoordinators] = await setupPlayer(scenario); | ||
|
||
// Recipe that simply returns an ExternalIdAttestation via | ||
// `GetLatestCallerExternalId` | ||
const externalIdRecipeRecord = | ||
await aliceCoordinators.usernameRegistry.createRecipe({ | ||
trusted_authors: [await fakeAgentPubKey(0)], | ||
arguments: [], | ||
instructions: [ | ||
[ | ||
"$return", | ||
{ | ||
type: "GetLatestCallerExternalId", | ||
trusted_author: await fakeAgentPubKey(0), | ||
}, | ||
], | ||
], | ||
}); | ||
|
||
// An ExternalIdAttestation that wasn't created by the trusted author | ||
const externalIdAttestationRecord = | ||
await aliceCoordinators.usernameRegistry.createExternalIdAttestation({ | ||
internal_pubkey: alice.agentPubKey, | ||
external_id: "whatever", | ||
display_name: "whatever", | ||
request_id: "1234", | ||
}); | ||
|
||
// Cannot specify untrusted attestation in execution | ||
await expect( | ||
aliceCoordinators.usernameRegistry.createRecipeExecution({ | ||
recipe_ah: externalIdRecipeRecord.signed_action.hashed.hash, | ||
arguments: [], | ||
instruction_executions: [ | ||
{ | ||
GetLatestCallerExternalId: { | ||
attestation_ah: | ||
externalIdAttestationRecord.signed_action.hashed.hash, | ||
}, | ||
}, | ||
], | ||
output: JSON.stringify({ | ||
agent_pubkey: encodeHashToBase64(alice.agentPubKey), | ||
external_id: "whatever", | ||
display_name: "whatever", | ||
}), | ||
}) | ||
).rejects.toSatisfy((err: Error) => | ||
err.message.includes("ExternalIdAttestation is by untrusted author") | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters