From 1ca1ba00052ba5566647e8946b065bea11843d92 Mon Sep 17 00:00:00 2001 From: Marnix Dessing Date: Fri, 31 Mar 2023 16:11:49 +0200 Subject: [PATCH] fix: digidLevel should be a string --- src/app/code/DigiDLoa.ts | 26 ++++++++++++++++++++++++++ src/app/code/YiviApi.ts | 4 ++-- test/other/YiviApi.test.ts | 6 +++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/app/code/DigiDLoa.ts b/src/app/code/DigiDLoa.ts index 731c3737..e05659db 100644 --- a/src/app/code/DigiDLoa.ts +++ b/src/app/code/DigiDLoa.ts @@ -31,4 +31,30 @@ export function loaToNumber(loa: DigidLoa) { default: return 0; } +} + + +/** + * Given a DigiD LOA, proved a value that can be used to issue + * the Yivi DigiDLevel attribute. + * From the old issue app (https://github.com/GemeenteNijmegen/irma-brp-opladen) we know that + * there are 4 valid values: + * - 10 = Basis + * - 20 = Midden + * - 25 = Substantieel + * - 30 = Hoog + */ +export function loaToString(loa: DigidLoa) { + switch (loa) { + case DigidLoa.Hoog: + return 'Hoog'; + case DigidLoa.Substantieel: + return 'Substantieel'; + case DigidLoa.Midden: + return 'Midden'; + case DigidLoa.Basis: + return 'Basis'; + default: + return ''; + } } \ No newline at end of file diff --git a/src/app/code/YiviApi.ts b/src/app/code/YiviApi.ts index 3c8fc58b..42a3f58f 100644 --- a/src/app/code/YiviApi.ts +++ b/src/app/code/YiviApi.ts @@ -1,7 +1,7 @@ import { AWS } from '@gemeentenijmegen/utils'; import { aws4Interceptor } from 'aws4-axios'; import axios, { Axios } from 'axios'; -import { DigidLoa, loaToNumber } from './DigiDLoa'; +import { DigidLoa, loaToString } from './DigiDLoa'; export class YiviApi { @@ -154,7 +154,7 @@ export class YiviApi { cityofbirth: gegevens.Geboorteplaats, countryofbirth: gegevens.Geboorteland, bsn: brpData.Persoon.BSN.BSN, - digidlevel: `${loaToNumber(loa)}`, + digidlevel: `${loaToString(loa)}`, ...brpData.Persoon.ageLimits, }, }, diff --git a/test/other/YiviApi.test.ts b/test/other/YiviApi.test.ts index 850f2a00..b8a59767 100644 --- a/test/other/YiviApi.test.ts +++ b/test/other/YiviApi.test.ts @@ -2,7 +2,7 @@ import { YiviApi } from '../../src/app/code/YiviApi'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { AWS } from '@gemeentenijmegen/utils'; -import { DigidLoa, loaToNumber } from '../../src/app/code/DigiDLoa'; +import { DigidLoa, loaToString } from '../../src/app/code/DigiDLoa'; import { TestUtils } from './TestUtils'; const axiosMock = new MockAdapter(axios); @@ -89,7 +89,7 @@ test('Check if yivi api adds aws4-singature and irma-authorization header and ri } const data = JSON.parse(request.data); - const loa = `${loaToNumber(DigidLoa.Substantieel)}`; + const loa = `${loaToString(DigidLoa.Substantieel)}`; expect(data?.credentials[1]?.attributes?.digidlevel).toBe(loa); }); @@ -118,7 +118,7 @@ test('Mapping BRP data', () => { // Check request buildup and LOA expect(yiviRequest.type).toBe('issuing'); - expect(yiviRequest.credentials[1].attributes.digidlevel).toBe(`${loaToNumber(DigidLoa.Midden)}`); + expect(yiviRequest.credentials[1].attributes.digidlevel).toBe(loaToString(DigidLoa.Midden)); expect(yiviRequest.credentials[0].credential).toBe('irma-demo.gemeente.address'); expect(yiviRequest.credentials[1].credential).toBe('irma-demo.gemeente.personalData');