|
1 | 1 | import { describe, expect, test } from 'vitest' |
| 2 | +import { Openid4vpAuthorizationResponseError } from '../Openid4vpAuthorizationResponseError' |
2 | 3 | import { parseOpenid4VpAuthorizationResponsePayload } from '../parse-authorization-response-payload' |
3 | 4 |
|
4 | 5 | describe('parseOpenid4VpAuthorizationResponsePayload', () => { |
@@ -26,4 +27,41 @@ describe('parseOpenid4VpAuthorizationResponsePayload', () => { |
26 | 27 | }, |
27 | 28 | }) |
28 | 29 | }) |
| 30 | + |
| 31 | + test('should throw an Openid4vpAuthorizationResponseError when the wallet returns an authorization error response', () => { |
| 32 | + // Non-normative example of an Authorization Error Response from the OpenID4VP spec. |
| 33 | + const parsedPayload = Object.fromEntries( |
| 34 | + new URLSearchParams( |
| 35 | + 'error=invalid_request&error_description=unsupported%20client_id_prefix&state=eyJhb...6-sVA' |
| 36 | + ).entries() |
| 37 | + ) |
| 38 | + |
| 39 | + let error: unknown |
| 40 | + try { |
| 41 | + parseOpenid4VpAuthorizationResponsePayload(parsedPayload) |
| 42 | + } catch (e) { |
| 43 | + error = e |
| 44 | + } |
| 45 | + |
| 46 | + expect(error).toBeInstanceOf(Openid4vpAuthorizationResponseError) |
| 47 | + expect((error as Openid4vpAuthorizationResponseError).errorResponse).toEqual({ |
| 48 | + error: 'invalid_request', |
| 49 | + error_description: 'unsupported client_id_prefix', |
| 50 | + state: 'eyJhb...6-sVA', |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + test('should throw an Openid4vpAuthorizationResponseError for an error response without additional parameters', () => { |
| 55 | + let error: unknown |
| 56 | + try { |
| 57 | + parseOpenid4VpAuthorizationResponsePayload({ error: 'wallet_unavailable' }) |
| 58 | + } catch (e) { |
| 59 | + error = e |
| 60 | + } |
| 61 | + |
| 62 | + expect(error).toBeInstanceOf(Openid4vpAuthorizationResponseError) |
| 63 | + expect((error as Openid4vpAuthorizationResponseError).errorResponse).toEqual({ |
| 64 | + error: 'wallet_unavailable', |
| 65 | + }) |
| 66 | + }) |
29 | 67 | }) |
0 commit comments