File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -54,9 +54,14 @@ export function getClientPrincipalFromHeaders(headers) {
5454 return undefined ;
5555 }
5656
57- const encoded = Buffer . from ( header , 'base64' ) ;
58- const decoded = encoded . toString ( 'ascii' ) ;
59- const clientPrincipal = JSON . parse ( decoded ) ;
57+ try {
58+ const encoded = Buffer . from ( header , 'base64' ) ;
59+ const decoded = encoded . toString ( 'ascii' ) ;
60+ const clientPrincipal = JSON . parse ( decoded ) ;
6061
61- return clientPrincipal ;
62+ return clientPrincipal ;
63+ } catch ( e ) {
64+ console . log ( 'Unable to parse client principal:' , e ) ;
65+ return undefined ;
66+ }
6267}
Original file line number Diff line number Diff line change @@ -118,4 +118,12 @@ describe('client principal parsing', () => {
118118 test ( 'returns undefined when there is no client principal' , ( ) => {
119119 expect ( getClientPrincipalFromHeaders ( new Headers ( ) ) ) . toBeUndefined ( ) ;
120120 } ) ;
121+
122+ test ( 'returns undefined if unable to parse' , ( ) => {
123+ const headers = new Headers ( {
124+ 'x-ms-client-principal' : 'boom'
125+ } ) ;
126+
127+ expect ( getClientPrincipalFromHeaders ( headers ) ) . toBeUndefined ( ) ;
128+ } ) ;
121129} ) ;
You can’t perform that action at this time.
0 commit comments