diff --git a/src/identity/ownership/TokenOwnershipValidator.ts b/src/identity/ownership/TokenOwnershipValidator.ts index d025e698a..6ee1aca3c 100644 --- a/src/identity/ownership/TokenOwnershipValidator.ts +++ b/src/identity/ownership/TokenOwnershipValidator.ts @@ -82,11 +82,15 @@ export class TokenOwnershipValidator extends OwnershipValidator { * Throws an error containing the description of which triple is needed for verification. */ private throwError(webId: string, token: string): never { - this.logger.debug(`Missing verification token at ${webId}`); + this.logger.debug(`No verification token found for ${webId}`); const errorMessage = [ - `<${webId}> <${SOLID.terms.oidcIssuerRegistrationToken.value}> "${token}" .`, - 'Must be added to the WebId. This can be removed after registration.', - ].join('\n'); + 'Verification token not found.', + 'Please add the RDF triple', + `<${webId}> <${SOLID.oidcIssuerRegistrationToken}> "${token}".`, + `to the WebID document at ${webId.replace(/#.*/u, '')}`, + 'to prove it belongs to you.', + 'You can remove this triple again after validation.', + ].join(' '); throw new BadRequestHttpError(errorMessage); } } diff --git a/test/integration/Identity.test.ts b/test/integration/Identity.test.ts index 1e8903211..9d758f532 100644 --- a/test/integration/Identity.test.ts +++ b/test/integration/Identity.test.ts @@ -34,16 +34,13 @@ async function postForm(url: string, formBody: string): Promise { * Extracts the registration triple from the registration form body. */ function extractRegistrationTriple(body: string, webId: string): string { - const error = load(body)('p.error').first().text().trim() - .split('\n')[0]; + const error = load(body)('p.error').first().text(); const regex = new RegExp( - `(<${webId}> "[^"]+"\\s*\\.\\s*)$`, 'u', + `<${webId}>\\s+\\s+"[^"]+"\\s*\\.`, 'u', ); const match = regex.exec(error); - expect(match).toHaveLength(2); - const registrationTriple = match![1]; - expect(registrationTriple).not.toHaveLength(0); - return registrationTriple; + expect(match).toHaveLength(1); + return match![0]; } // No way around the cookies https://github.com/panva/node-oidc-provider/issues/552 . diff --git a/test/unit/identity/ownership/TokenOwnershipValidator.test.ts b/test/unit/identity/ownership/TokenOwnershipValidator.test.ts index 34bcfd3e1..498ec30f0 100644 --- a/test/unit/identity/ownership/TokenOwnershipValidator.test.ts +++ b/test/unit/identity/ownership/TokenOwnershipValidator.test.ts @@ -24,7 +24,7 @@ describe('A TokenOwnershipValidator', (): void => { const webId = 'http://alice.test.com/#me'; const token = 'randomlyGeneratedToken'; const tokenTriple = quad(namedNode(webId), SOLID.terms.oidcIssuerRegistrationToken, literal(token)); - const tokenString = `${quadToString(tokenTriple)} .`; + const tokenString = `${quadToString(tokenTriple)}.`; const converter = new RdfToQuadConverter(); let storage: ExpiringStorage; let validator: TokenOwnershipValidator;