package Ġno . nav . pg i . sk att . inn te kt . sk att Ċ Ċ import Ġcom . nim bus ds . jwt . Signed JWT Ċ import Ġno . nav . pg i . sk att . inn te kt . mock . Mask in port en Mock Ċ import Ġno . nav . pg i . sk att . inn te kt . mock . Mask in port en Mock . Companion . MASK IN PORT EN _ CLIENT _ ENV _ VARIABLE S Ċ import Ġno . nav . pg i . sk att . inn te kt . mock . P ens jon sg iven de In n te kt Mock Ċ import Ġno . nav . pg i . sk att . inn te kt . mock . P ens jon sg iven de In n te kt Mock . Companion . PG I _ CLIENT _ ENV _ VARIABLE S Ċ import Ġorg . junit . jupiter . api .* Ċ import Ġorg . junit . jupiter . api . Assertions . assertEquals Ċ import Ġorg . junit . jupiter . api . Assertions . assertTrue Ċ import Ġjava . net . http . HttpResponse Ċ Ċ private Ġconst Ġval ĠIN N TE KT SA AR Ġ= Ġ" 2 0 1 8 " Ċ private Ġconst Ġval ĠN ORS K _ PERSON IDENT IFI K ATOR Ġ= Ġ" 1 2 3 4 5 6 7 8 9 0 1 " Ċ Ċ @ Test Instance ( Test Instance . Lifecycle . PER _ CLASS ) Ċ class ĠP gi Client Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġp gi Client : ĠP gi Client Ġ= ĠP gi Client ( PG I _ CLIENT _ ENV _ VARIABLE S Ġ+ ĠMASK IN PORT EN _ CLIENT _ ENV _ VARIABLE S ) ĊĊĠĠĠ Ġprivate Ġval Ġp ens jon sg iven de In n te kt Mock Ġ= ĠP ens jon sg iven de In n te kt Mock () ĊĠĠĠ Ġprivate Ġval Ġmask in port en Mock Ġ= ĠMask in port en Mock () ĊĊĠĠĠ Ġ@ Before All ĊĠĠĠ Ġinternal Ġfun Ġinit () Ġ{ ĊĠĠĠĠĠĠĠ Ġmask in port en Mock .` stub Ġmask in port en Ġtoken Ġendpoint `() ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġinternal Ġfun ĠbeforeEach () Ġ{ ĊĠĠĠĠĠĠĠ Ġp ens jon sg iven de In n te kt Mock . reset () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After All ĊĠĠĠ Ġinternal Ġfun Ġteardown () Ġ{ ĊĠĠĠĠĠĠĠ Ġp ens jon sg iven de In n te kt Mock . stop () ĊĠĠĠĠĠĠĠ Ġmask in port en Mock . stop () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create GetRequest Ġshould Ġadd Ġinn tek ts aar Ġand Ġn ors k Person ident ifik ator Ġto Ġpath `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġp gi Client . create P gi Request ( IN N TE KT SA AR , ĠN ORS K _ PERSON IDENT IFI K ATOR ) ĊĠĠĠĠĠĠĠ ĠassertEquals (""" $ P ENS J ON SG IV EN DE _ IN N TE KT _ PATH /$ IN N TE KT SA AR /$ N ORS K _ PERSON IDENT IFI K ATOR """, Ġrequest . uri (). path ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` create GetRequest Ġshould Ġadd Ġauthorization Ġheader Ġwith Ġbe arer Ġtoken `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġp gi Client . create P gi Request ( IN N TE KT SA AR , ĠN ORS K _ PERSON IDENT IFI K ATOR ) ĊĠĠĠĠĠĠĠ Ġval Ġauthorization Header Ġ= Ġrequest . headers (). first Value (" Authorization "). get () ĊĊĠĠĠĠĠĠĠ ĠassertTrue ( authorization Header Ġcontains Regex Ġ""" Bearer \ s .* """) ĊĠĠĠĠĠĠĠ Ġassert DoesNot Throw Ġ{ Ġparse Jwt ( authorization Header ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġresponse Ġfor Ġp ens jon sg iven de Ġinn te kt Ġendpoint Ġwhen Ġstatus Ġ 2 0 0 `() Ġ{ ĊĠĠĠĠĠĠĠ Ġp ens jon sg iven de In n te kt Mock .` stub Ġp ens j ong iven de Ġinn te kt `( IN N TE KT SA AR , ĠN ORS K _ PERSON IDENT IFI K ATOR ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġp gi Client . getP gi ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġp gi Client . create P gi Request ( IN N TE KT SA AR , ĠN ORS K _ PERSON IDENT IFI K ATOR ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpResponse . Body Handlers . discard ing () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 0 0 , Ġresponse . statusCode ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` should Ġreturn Ġresponse Ġfor Ġp ens jon sg iven de Ġinn te kt Ġendpoint Ġwhen Ġstatus Ġis Ġnot Ġ 2 0 0 `() Ġ{ ĊĠĠĠĠĠĠĠ Ġp ens jon sg iven de In n te kt Mock .` stub Ġ 4 0 1 Ġfrom Ġsk att `( IN N TE KT SA AR , ĠN ORS K _ PERSON IDENT IFI K ATOR ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġp gi Client . getP gi ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġp gi Client . create P gi Request ( IN N TE KT SA AR , ĠN ORS K _ PERSON IDENT IFI K ATOR ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠHttpResponse . Body Handlers . discard ing () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 4 0 1 , Ġresponse . statusCode ()) ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ private Ġfun Ġparse Jwt ( bearer Token : ĠString ) Ġ= ĠSigned JWT . parse ( bearer Token . split (""" Bearer Ġ"" ")[ 1 ]) Ċ private Ġin fix Ġfun ĠString . contains Regex ( regex : ĠString ): ĠBoolean Ġ= Ġregex . to Regex (). matches ( this )