-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add VC support for alternative origins #2211
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
111 changes: 111 additions & 0 deletions
111
src/frontend/src/test-e2e/verifiableCredentials/alternativeOrigins.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,111 @@ | ||
import { runInBrowser } from "$src/test-e2e/util"; | ||
import { DemoAppView } from "$src/test-e2e/views"; | ||
|
||
import { | ||
II_URL, | ||
ISSUER_APP_URL, | ||
TEST_APP_CANONICAL_URL, | ||
TEST_APP_NICE_URL, | ||
} from "$src/test-e2e/constants"; | ||
|
||
import { | ||
authenticateToRelyingParty, | ||
getVCPresentation, | ||
getVCPresentation_, | ||
register, | ||
registerWithIssuer, | ||
} from "./utils"; | ||
|
||
test("Can issue credential with alternative RP derivation origin", async () => { | ||
await runInBrowser(async (browser: WebdriverIO.Browser) => { | ||
await browser.url(II_URL); | ||
|
||
const authConfig = await register["webauthn"](browser); | ||
|
||
// 1. Add employee | ||
|
||
const { msg: _msg, principal: _principal } = await registerWithIssuer({ | ||
browser, | ||
issuer: ISSUER_APP_URL, | ||
authConfig, | ||
}); | ||
|
||
// 2. Do the flow without alt origins | ||
|
||
const vcTestApp = await authenticateToRelyingParty({ | ||
browser, | ||
issuer: ISSUER_APP_URL, | ||
authConfig, | ||
relyingParty: TEST_APP_CANONICAL_URL, | ||
}); | ||
const principalRP = await vcTestApp.getPrincipal(); | ||
const { alias: alias_ } = await getVCPresentation({ | ||
vcTestApp, | ||
browser, | ||
authConfig, | ||
}); | ||
const alias = JSON.parse(alias_); | ||
|
||
// 3. Do the flow WITH alt origins | ||
const vcTestAppAlt = await authenticateToRelyingParty({ | ||
browser, | ||
issuer: ISSUER_APP_URL, | ||
authConfig, | ||
relyingParty: TEST_APP_NICE_URL, | ||
derivationOrigin: TEST_APP_CANONICAL_URL, | ||
}); | ||
const principalRPAlt = await vcTestAppAlt.getPrincipal(); | ||
expect(principalRPAlt).toBe(principalRP); | ||
|
||
const { alias: aliasAlt_ } = await getVCPresentation({ | ||
vcTestApp: vcTestAppAlt, | ||
browser, | ||
authConfig, | ||
}); | ||
|
||
const aliasAlt = JSON.parse(aliasAlt_); | ||
expect(aliasAlt.sub).toBe(alias.sub); | ||
}); | ||
}, 300_000); | ||
|
||
test("Cannot issue credential with bad alternative RP derivation origin", async () => { | ||
await runInBrowser(async (browser: WebdriverIO.Browser) => { | ||
await browser.url(II_URL); | ||
|
||
const authConfig = await register["webauthn"](browser); | ||
|
||
// 1. Add employee | ||
|
||
const { msg: _msg, principal: _principal } = await registerWithIssuer({ | ||
browser, | ||
issuer: ISSUER_APP_URL, | ||
authConfig, | ||
}); | ||
|
||
// 2. Do the flow WITH alt origins RESET | ||
|
||
const vcTestAppAlt = await authenticateToRelyingParty({ | ||
browser, | ||
issuer: ISSUER_APP_URL, | ||
authConfig, | ||
relyingParty: TEST_APP_NICE_URL, | ||
derivationOrigin: TEST_APP_CANONICAL_URL, | ||
}); | ||
|
||
await new DemoAppView(browser).resetAlternativeOrigins(); | ||
|
||
const result = await getVCPresentation_({ | ||
vcTestApp: vcTestAppAlt, | ||
browser, | ||
authConfig, | ||
}); | ||
|
||
expect(result.result).toBe("aborted"); | ||
if (!("reason" in result)) { | ||
throw new Error( | ||
"Expected VC result to be aborted, got: " + JSON.stringify(result) | ||
); | ||
} | ||
expect(result.reason).toBe("bad_derivation_origin_rp"); | ||
}); | ||
}, 300_000); |
111 changes: 111 additions & 0 deletions
111
src/frontend/src/test-e2e/verifiableCredentials/index.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,111 @@ | ||
import { runInBrowser } from "$src/test-e2e/util"; | ||
|
||
import { | ||
APPLE_USER_AGENT, | ||
II_URL, | ||
ISSUER_APP_URL, | ||
ISSUER_APP_URL_LEGACY, | ||
TEST_APP_CANONICAL_URL, | ||
TEST_APP_CANONICAL_URL_LEGACY, | ||
} from "$src/test-e2e/constants"; | ||
|
||
import { | ||
authenticateToRelyingParty, | ||
getVCPresentation, | ||
register, | ||
registerWithIssuer, | ||
} from "./utils"; | ||
|
||
test("Can add employee on issuer app", async () => { | ||
await runInBrowser(async (browser: WebdriverIO.Browser) => { | ||
const authConfig = await register["webauthn"](browser); | ||
|
||
const { msg, principal } = await registerWithIssuer({ | ||
browser, | ||
authConfig, | ||
issuer: ISSUER_APP_URL, | ||
}); | ||
|
||
expect(msg).toContain("Added"); | ||
expect(msg).toContain(principal); | ||
}); | ||
}, 300_000); | ||
|
||
const getDomain = (url: string) => url.split(".").slice(1).join("."); | ||
|
||
// The different test configs (different URLs, differnet auth methods) | ||
const testConfigs: Array<{ | ||
relyingParty: string; | ||
issuer: string; | ||
authType: "pin" | "webauthn"; | ||
}> = [ | ||
{ | ||
relyingParty: TEST_APP_CANONICAL_URL_LEGACY, | ||
issuer: ISSUER_APP_URL, | ||
authType: "webauthn", | ||
}, | ||
{ | ||
relyingParty: TEST_APP_CANONICAL_URL, | ||
issuer: ISSUER_APP_URL_LEGACY, | ||
authType: "webauthn", | ||
}, | ||
{ | ||
relyingParty: TEST_APP_CANONICAL_URL, | ||
issuer: ISSUER_APP_URL, | ||
authType: "pin", | ||
}, | ||
]; | ||
|
||
testConfigs.forEach(({ relyingParty, issuer, authType }) => { | ||
const testSuffix = `RP: ${getDomain(relyingParty)}, ISS: ${getDomain( | ||
issuer | ||
)}, auth: ${authType}`; | ||
|
||
test( | ||
"Can issue credentials " + testSuffix, | ||
async () => { | ||
await runInBrowser( | ||
async (browser: WebdriverIO.Browser) => { | ||
await browser.url(II_URL); | ||
|
||
const authConfig = await register[authType](browser); | ||
|
||
// 1. Add employee | ||
|
||
const { msg: _msg, principal: _principal } = await registerWithIssuer( | ||
{ | ||
browser, | ||
issuer, | ||
authConfig, | ||
} | ||
); | ||
|
||
// 2. Auth to RP | ||
|
||
const vcTestApp = await authenticateToRelyingParty({ | ||
browser, | ||
issuer, | ||
authConfig, | ||
relyingParty, | ||
}); | ||
|
||
const principalRP = await vcTestApp.getPrincipal(); | ||
|
||
// 3. Get VC presentation | ||
|
||
const { alias } = await getVCPresentation({ | ||
vcTestApp, | ||
browser, | ||
authConfig, | ||
}); | ||
|
||
// Perform a basic check on the alias | ||
const aliasObj = JSON.parse(alias); | ||
expect(aliasObj.sub).toBe(`did:icp:${principalRP}`); | ||
}, | ||
authType === "pin" ? APPLE_USER_AGENT : undefined | ||
); | ||
}, | ||
300_000 | ||
); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a later PR: Given it is now used in multiple flows, this could be moved to some flow independent infrastructure place? Also the documentation in this file does not convey that it is used in multiple flows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep definitely! I also want to change the interface:
it's somewhere on my TODO list, but since we already pull some code from the
authorize
flow elsewhere I thought this wouldn't hurt